Skip to content

Instantly share code, notes, and snippets.

@foxlet
Last active July 26, 2022 07:08
Show Gist options
  • Save foxlet/ead80f322d533acbb9b0 to your computer and use it in GitHub Desktop.
Save foxlet/ead80f322d533acbb9b0 to your computer and use it in GitHub Desktop.
Snoovatars
from lxml import html
import requests
from cloudbot import hook
from cloudbot.util import timeformat, formatting
# A nice user agent for use with Reddit
headers = {'User-Agent': 'CloudBot/dev 1.0 - CloudBot Refresh by lukeroge'}
@hook.command
def snoovatar(text):
nickname = text
url = "http://reddit.com/user/{}/snoo/.json".format(nickname)
# The Reddit API will not play nice if it doesn't identify with headers...
r = requests.get(url, headers=headers)
data = r.json()
print(str(data))
if '{}' in str(data):
return "http://reddit.com/user/{}/snoo/".format(nickname)
else:
return "{} has no Snoovatar.".format(nickname)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment