pastebin - collaborative debugging tool
kpaste.net RSS

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

    
11
import json
22
import urllib2
33
import base64
44
import os
55
import datetime
66
import sys
77
88
#config
99
#base64string =
1010
base64string =
11-
apikey= '
11+
apikey=
1212
username =
1313
apipath='/user/calendar/shows.json/'
1414
tmppath=
1515
1616
1717
#for color crap on windows
1818
from colorama import init
1919
init()
2020
from colorama import Style
2121
2222
#funcs
2323
2424
2525
2626
def user_cal_shows():
2727
	request = urllib2.Request("https://api.trakt.tv/user/calendar/shows.json/" + apikey + "/" + username)
2828
	request.add_header("Authorization", "Basic %s" % base64string)
2929
	return json.load(urllib2.urlopen(request))
3030
3131
def outputrun():
3232
    for i in range(len(out)):
3333
        for b in range(len(out[i]['episodes'])):
3434
            in_watch = out[i]['episodes'][b]['show']['in_watchlist'] #True
3535
            #make sure the show is in the watch list
3636
            if in_watch == True:
3737
                showname = out[i]['episodes'][b]['show']['title']  #Fringe
3838
                ep_name = out[i]['episodes'][b]['episode']['title']  #In Absentia
3939
                network = out[i]['episodes'][b]['show']['network']  #FOX
4040
                airtime = out[i]['episodes'][b]['show']['air_time']  #9:00pm
4141
                season = out[i]['episodes'][b]['episode']['season']  #5
4242
                ep_num = out[i]['episodes'][b]['episode']['number']  #2
4343
                airday = out[i]['episodes'][b]['show']['air_day']  #Friday
4444
                runtime = out[i]['episodes'][b]['show']['runtime']  #60v
4545
                print showname + " airs at " + Style.BRIGHT + airtime + Style.NORMAL +" on "+ Style.BRIGHT + airday + Style.NORMAL
4646
                print "\t " + str(season) + "." + str(ep_num) + " - " + ep_name + Style.BRIGHT +" " + network + Style.NORMAL
4747
                print "\t watchlist: " + str(in_watch) + " - runtime: " + str(runtime) + "min"
4848
4949
def update_json():
5050
    out = user_cal_shows()
5151
    #overwrites any data there
5252
    with open(tmppath+"data","wb") as fp:
5353
        json.dump(out,fp)
5454
    return out
5555
5656
5757
#caching, sees if cache folder is there, if not make it
5858
#if it is, it gets the date from the cache
5959
if not os.path.exists(tmppath+"data"):
6060
    if not os.path.exists(tmppath):
6161
        os.makedirs(tmppath)
6262
    out = update_json()
6363
else:
6464
    #load from the file
6565
    with open(tmppath+"data", "rb") as fp:
6666
        out = json.load(fp)
6767
   #compare the date
6868
    if str(out[0]['date']) != str(datetime.date.today()):
6969
       #not the same, update list
7070
       out = update_json()
7171
    if len(sys.argv) > 1:
7272
        if str(sys.argv[1]) == "reset":
7373
           out = update_json()
7474
outputrun()
7575
7676
7777
7878

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