Beispiel #1
0
def mockCheckSequel(id):
    if not os.path.isfile("./xml/" + str(id) + ".xml"):
        return
    tree = ET.parse("./xml/" + str(id) + ".xml")
    root = tree.getroot()
    if root.find("relatedanime") is None:
        return
    for anime in root.find("relatedanime"):
        if anime.attrib['type'] == "Prequel":
            prequelId = anime.attrib['id']
            db = DBHelper()
            db.executeQuery("UPDATE shows SET sequel=" + str(id) + " WHERE showId=%s", (prequelId,))
            print "Added sequel: " + str(id)
Beispiel #2
0
 def getXML(self, id):
     db = DBHelper()
     lastXmlUpdate = db.retrieveData("SELECT lastXmlUpdate FROM shows WHERE showId=%s", (id,))
     if len(lastXmlUpdate) < 1:
         return
     lastXmlUpdate = lastXmlUpdate[0][0]
     if lastXmlUpdate is None or time() - lastXmlUpdate > 604800000: # 1 week
         sleep(2)
         url = "http://api.anidb.net:9001/httpapi?request=anime&client=seqwatcher&clientver=0&protover=1&aid=" + str(id)
         r = requests.get(url)
         xml = r.text.encode('utf-8')
         if "anime id" not in xml: # check the response is valid
             return
         db.executeQuery("UPDATE shows SET xml=%s, lastXmlUpdate=%s WHERE showId=%s", (xml, time(), id))
         print "Updated XML for showId: " + str(id)
Beispiel #3
0
 def checkSequel(self, id):
     # self.getXML(id)
     db = DBHelper()
     xml = db.retrieveData("SELECT xml FROM shows WHERE showId=%s AND xml IS NOT NULL", (id,))
     if len(xml) < 1:
         return
     xml = xml[0][0]
     root = ET.fromstring(xml)
     if root.find("relatedanime") is None:
         return
     for anime in root.find("relatedanime"):
         if anime.attrib['type'] == "Prequel":
             prequelId = anime.attrib['id']
             db = DBHelper()
             db.executeQuery("UPDATE shows SET sequel=" + str(id) + " WHERE showId=%s", (prequelId,))
             print "Added sequel: " + str(id)
Beispiel #4
0
 def addNewShows(self):
     db = DBHelper()
     lastId = db.retrieveData("SELECT * FROM shows ORDER BY showId DESC LIMIT 1", ())
     if len(lastId) > 0:
         lastId = lastId[0][0]
     else:
         lastId = 0
     tree = ET.parse('./allshows.xml')
     root = tree.getroot()
     for child in root:
         id =  int(child.attrib['aid'])
         if id > lastId:
             db.executeQuery("INSERT INTO shows (showId) VALUES (" + str(id) + ")", ())
             for title in child:
                 lang = title.attrib['{http://www.w3.org/XML/1998/namespace}lang']
                 if (lang == "en") or (lang == "x-jat"):
                     db.executeQuery("INSERT INTO titles (showId, title) VALUES (" + str(id) + ", %s)", (title.text,))