Difference between
modified post 2106c2d06 by Anonymous on Fri 19th Oct 2012 15:12
original post 56d37f33 by Anonymous on Fri 19th Oct 2012 15:12
Download diff
Show
old version |
new version |
both versions
| 1 | 1 | import json | |
| 2 | 2 | import urllib2 | |
| 3 | 3 | import base64 | |
| 4 | 4 | import os | |
| 5 | 5 | import datetime | |
| 6 | 6 | import sys | |
| 7 | 7 | ||
| 8 | 8 | #config | |
| 9 | 9 | #base64string = | |
| 10 | 10 | base64string = | |
| 11 | - | apikey= ' | |
| 11 | + | apikey= | |
| 12 | 12 | username = | |
| 13 | 13 | apipath='/user/calendar/shows.json/' | |
| 14 | 14 | tmppath= | |
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | 17 | #for color crap on windows | |
| 18 | 18 | from colorama import init | |
| 19 | 19 | init() | |
| 20 | 20 | from colorama import Style | |
| 21 | 21 | ||
| 22 | 22 | #funcs | |
| 23 | 23 | ||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | 26 | def user_cal_shows(): | |
| 27 | 27 | request = urllib2.Request("https://api.trakt.tv/user/calendar/shows.json/" + apikey + "/" + username) | |
| 28 | 28 | request.add_header("Authorization", "Basic %s" % base64string) | |
| 29 | 29 | return json.load(urllib2.urlopen(request)) | |
| 30 | 30 | ||
| 31 | 31 | def outputrun(): | |
| 32 | 32 | for i in range(len(out)): | |
| 33 | 33 | for b in range(len(out[i]['episodes'])): | |
| 34 | 34 | in_watch = out[i]['episodes'][b]['show']['in_watchlist'] #True | |
| 35 | 35 | #make sure the show is in the watch list | |
| 36 | 36 | if in_watch == True: | |
| 37 | 37 | showname = out[i]['episodes'][b]['show']['title'] #Fringe | |
| 38 | 38 | ep_name = out[i]['episodes'][b]['episode']['title'] #In Absentia | |
| 39 | 39 | network = out[i]['episodes'][b]['show']['network'] #FOX | |
| 40 | 40 | airtime = out[i]['episodes'][b]['show']['air_time'] #9:00pm | |
| 41 | 41 | season = out[i]['episodes'][b]['episode']['season'] #5 | |
| 42 | 42 | ep_num = out[i]['episodes'][b]['episode']['number'] #2 | |
| 43 | 43 | airday = out[i]['episodes'][b]['show']['air_day'] #Friday | |
| 44 | 44 | runtime = out[i]['episodes'][b]['show']['runtime'] #60v | |
| 45 | 45 | print showname + " airs at " + Style.BRIGHT + airtime + Style.NORMAL +" on "+ Style.BRIGHT + airday + Style.NORMAL | |
| 46 | 46 | print "\t " + str(season) + "." + str(ep_num) + " - " + ep_name + Style.BRIGHT +" " + network + Style.NORMAL | |
| 47 | 47 | print "\t watchlist: " + str(in_watch) + " - runtime: " + str(runtime) + "min" | |
| 48 | 48 | ||
| 49 | 49 | def update_json(): | |
| 50 | 50 | out = user_cal_shows() | |
| 51 | 51 | #overwrites any data there | |
| 52 | 52 | with open(tmppath+"data","wb") as fp: | |
| 53 | 53 | json.dump(out,fp) | |
| 54 | 54 | return out | |
| 55 | 55 | ||
| 56 | 56 | ||
| 57 | 57 | #caching, sees if cache folder is there, if not make it | |
| 58 | 58 | #if it is, it gets the date from the cache | |
| 59 | 59 | if not os.path.exists(tmppath+"data"): | |
| 60 | 60 | if not os.path.exists(tmppath): | |
| 61 | 61 | os.makedirs(tmppath) | |
| 62 | 62 | out = update_json() | |
| 63 | 63 | else: | |
| 64 | 64 | #load from the file | |
| 65 | 65 | with open(tmppath+"data", "rb") as fp: | |
| 66 | 66 | out = json.load(fp) | |
| 67 | 67 | #compare the date | |
| 68 | 68 | if str(out[0]['date']) != str(datetime.date.today()): | |
| 69 | 69 | #not the same, update list | |
| 70 | 70 | out = update_json() | |
| 71 | 71 | if len(sys.argv) > 1: | |
| 72 | 72 | if str(sys.argv[1]) == "reset": | |
| 73 | 73 | out = update_json() | |
| 74 | 74 | outputrun() | |
| 75 | 75 | ||
| 76 | 76 | ||
| 77 | 77 | ||
| 78 | 78 |
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.
kpaste.net RSS