askcompu

Untitled

Aug 9th, 2015
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.15 KB | None | 0 0
  1. def episode_find(query, phenny):
  2.     query = query.replace('!', '')
  3.     if re.compile('(?i)(season \d+ episode \d+)').match(query):
  4.         regex = re.compile('(?i)(season [\d+] episode [\d+])')
  5.         numbers = regex.findall(query)
  6.         return str(numbers)
  7.         # uri = 'http://api.ponycountdown.com/' + numbers[0] + '/' + numbers[1]
  8.         nl = query
  9.     if re.compile('next').match(query):
  10.         uri = 'http://api.ponycountdown.com/next'
  11.         nl = 'next'
  12.     if re.compile('last').match(query):
  13.         uri = 'http://api.ponycountdown.com/last'
  14.         nl = 'last'
  15.     rec_bytes = web.get(uri)
  16.     try:
  17.         jsonstring = json.loads(rec_bytes)
  18.     except:
  19.         return
  20.     try:
  21.         jsonstring[0]
  22.     except:
  23.         try:
  24.             jsonstring['name']
  25.         except:
  26.             return 'nope$' + nl
  27.     try:
  28.         epname = jsonstring[0]['name']
  29.         eps = str(jsonstring[0]['season'])
  30.         epe = str(jsonstring[0]['episode'])
  31.     except:
  32.         epname = jsonstring['name']
  33.         eps = str(jsonstring['season'])
  34.         epe = str(jsonstring['episode'])
  35.     return epname + ', Season ' + eps + ', Episode ' + epe
Advertisement
Add Comment
Please, Sign In to add comment