Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Filename : tvragetest.py
- Author : G.D. Walters
- Purpose : Query TVRage.com for info about tv shows
- """
- #=============================================================
- # IMPORTS
- #=============================================================
- from xml.etree import ElementTree as ET
- import urllib
- import sys
- #=============================================================
- # Main Class
- #=============================================================
- class TvRage:
- def __init__(self):
- self.ApiKey = "Itnl8IyY1hsR9n0IP6zI"
- self.FindSeriesString = "http://services.tvrage.com/myfeeds/search.php?key="
- self.GetShowInfoString = "http://services.tvrage.com/myfeeds/showinfo.php?key="
- self.GetEpisodeListString = "http://services.tvrage.com/myfeeds/episode_list.php?key="
- self.ShowList = []
- self.ShowInfo = []
- self.EpisodeList = []
- self.EpisodeItem = []
- def FindIdByName(self,showname,debug = 0):
- strng = self.FindSeriesString + self.ApiKey + "&show=" + showname
- urllib.socket.setdefaulttimeout(8)
- usock = urllib.urlopen(strng)
- tree = ET.parse(usock).getroot()
- usock.close()
- foundcounter = 0
- self.showlist = []
- for node in tree.findall('show'):
- showinfo = []
- genrestring = None
- dict = {}
- for n in node:
- if n.tag == 'showid':
- showid = n.text
- dict['ID'] = showid
- elif n.tag == 'name':
- showname = n.text
- dict['Name'] = showname
- elif n.tag == 'link':
- showlink = n.text
- dict['Link'] = showlink
- elif n.tag == 'country':
- showcountry = n.text
- dict['Country'] = showcountry
- elif n.tag == 'started':
- showstarted = n.text
- dict['Started'] = showstarted
- elif n.tag == 'ended':
- showended = n.text
- dict['Ended'] = showended
- elif n.tag == 'seasons':
- showseasons = n.text
- dict['Seasons'] = showseasons
- elif n.tag == 'status':
- showstatus = n.text
- dict['Status'] = showstatus
- elif n.tag == 'classification':
- showclassification = n.text
- dict['Classification'] = showclassification
- elif n.tag == 'genres':
- for subelement in n:
- if subelement.tag == 'genre':
- if subelement.text != None:
- if genrestring == None:
- genrestring = subelement.text
- else:
- genrestring += " | " + subelement.text
- dict['Genres'] = genrestring
- foundcounter += 1
- self.showlist.append(dict)
- return self.showlist
- #========================================================
- def DisplayShowResult(self, ShowListDict):
- lcnt = len(ShowListDict)
- print "%d Found" % lcnt
- print "------------------------"
- cntr = 1
- for c in ShowListDict:
- print "%d - %s - %s" % (cntr,c['Name'],c['ID']) #,c['Ended'],c['Link']
- cntr += 1
- sel = raw_input("Enter Selection or 0 to exit -> ")
- return sel
- def main():
- tr = TvRage()
- #--------------------
- # Find Series by name
- #--------------------
- nam = raw_input("Enter Series Name -> ")
- if nam != None:
- sl = tr.FindIdByName(nam)
- which = tr.DisplayShowResult(sl)
- if which == 0:
- sys.exit()
- else:
- option = int(which)-1
- id = sl[option]['ID']
- print "ShowID selected was %s" % id
- #===========================================================
- # Main loop
- #===========================================================
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement