pastebin - collaborative debugging tool
kpaste.net RSS


trakt json python
Posted by Anonymous on Tue 2nd Oct 2012 19:26
raw | new post

  1. import json
  2. import urllib2
  3. import base64
  4. #config
  5. base64string = base64.encodestring('username:password')
  6. apikey= 'apikey'
  7. username ='username'
  8. apipath='/user/calendar/shows.json/'
  9.  
  10. #funcs
  11. def user_cal_shows():
  12.         request = urllib2.Request("https://api.trakt.tv/user/calendar/shows.json/" + apikey + "/" + username)
  13.         request.add_header("Authorization", "Basic %s" % base64string)
  14.         return json.load(urllib2.urlopen(request))
  15.  
  16.  
  17. out = user_cal_shows()
  18. for i in range(len(out)):
  19.         showname = out[i]['episodes'][0]['show']['title']  #Fringe
  20.         ep_name = out[i]['episodes'][0]['episode']['title']  #In Absentia
  21.         network = out[i]['episodes'][0]['show']['network']  #FOX
  22.         airtime = out[i]['episodes'][0]['show']['air_time']  #9:00pm
  23.         season = out[i]['episodes'][0]['episode']['season']  #5
  24.         ep_num = out[i]['episodes'][0]['episode']['number']  #2
  25.         in_watch = out[i]['episodes'][0]['show']['in_watchlist'] #True
  26.         airday = out[i]['episodes'][0]['show']['air_day']  #Friday
  27.         runtime = out[i]['episodes'][0]['show']['runtime']  #60v
  28.  
  29.         print showname + " airs at " +  airtime + " on " + airday
  30.         print "\t " + str(season) + "." + str(ep_num) + " - " + ep_name + " " + network
  31.         print "\t watchlist: " + str(in_watch) + " - runtime: " + str(runtime) + "min"

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at