summaryrefslogtreecommitdiffstats
path: root/framed.py
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2009-10-19 22:53:07 -0400
committerJason A. Donenfeld <Jason@zx2c4.com>2009-10-19 22:53:07 -0400
commitb1ea0c369e2e1dfeecf4b07b3dfd51b3a7bddaa0 (patch)
treeaf3ef2708859728250ddce302d96e2a8ebdae724 /framed.py
parentGitignore file. (diff)
downloadFramedPrototype-b1ea0c369e2e1dfeecf4b07b3dfd51b3a7bddaa0.tar.xz
FramedPrototype-b1ea0c369e2e1dfeecf4b07b3dfd51b3a7bddaa0.zip
Add ftp logic to zx2c4 host becuase ap engine doesnt allow port 21.
Diffstat (limited to 'framed.py')
-rw-r--r--framed.py94
1 files changed, 56 insertions, 38 deletions
diff --git a/framed.py b/framed.py
index 41447fe..0e8acdf 100644
--- a/framed.py
+++ b/framed.py
@@ -28,46 +28,64 @@ class Title(db.Model):
code = db.StringProperty(required=True)
actors = db.StringListProperty()
characters = db.StringListProperty()
+ lastThumb = db.IntegerProperty()
class LoadNewTitles(webapp.RequestHandler):
- def get(self):
- api = AnyClipAPI("CAD58B9E-F045-492F-81B9-22CFE6B00604")
- index = 0
- imdbPattern = re.compile("<td class=\"nm\"><a href=\"/name/nm[0-9]{7}/\" onclick=\"\\(new Image\\(\\)\\)\\.src='/rg/castlist/position-[0-9]{1,2}/images/b\\.gif\\?link=/name/nm[0-9]{7}/';\">([^><]+)</a></td><td class=\"ddd\"> \\.\\.\\. </td><td class=\"char\">(?:<a href=\"/character/ch[0-9]{7}/\">([^><]+)</a>[^><]*|([^><]*))</td>")
- while True:
- response = api.request("titles", ("recent", index, 20))
- index += 20
- for item in response["Items"]:
- if Title.all().filter('code = ', item["Code"]).count() == 0:
- self.response.out.write("Adding %s<br>" % item["Name"])
- newTitle = Title(title=item["Name"], code=item["Code"])
-
- imdbList = fetch("http://www.imdb.com/title/tt%s/fullcredits" % item["ImdbID"])
- i = 0
- while imdbList.status_code != 200:
- i += 1
- if i == 5:
- break
- sleep(3)
- imdbList = fetch("http://www.imdb.com/title/tt%s/fullcredits" % item["ImdbID"])
- if imdbList.status_code != 200:
- self.response.out.write("Could not add cast of %s<br>" % item["Name"])
- continue
- i = 0
- for match in imdbPattern.finditer(imdbList.content):
- newTitle.actors.append(match.group(1))
- character = match.group(2)
- if character == None:
- character = match.group(3)
- newTitle.characters.append(character)
- i += 1
- if i == 10:
- break
- newTitle.put()
- else:
- index = response["TotalItemCount"]
- break
- if index >= response["TotalItemCount"]:
+ def __init__(self):
+ self.api = AnyClipAPI("CAD58B9E-F045-492F-81B9-22CFE6B00604")
+ self.imdbPattern = re.compile("<td class=\"nm\"><a href=\"/name/nm[0-9]{7}/\" onclick=\"\\(new Image\\(\\)\\)\\.src='/rg/castlist/position-[0-9]{1,2}/images/b\\.gif\\?link=/name/nm[0-9]{7}/';\">([^><]+)</a></td><td class=\"ddd\"> \\.\\.\\. </td><td class=\"char\">(?:<a href=\"/character/ch[0-9]{7}/\">([^><]+)</a>[^><]*|([^><]*))</td>")
+
+ def getCast(self, imdbCode):
+ imdbList = fetch("http://www.imdb.com/title/tt%s/fullcredits" % imdbCode)
+ i = 0
+ while imdbList.status_code != 200:
+ i += 1
+ if i == 5:
+ break
+ sleep(3)
+ imdbList = fetch("http://www.imdb.com/title/tt%s/fullcredits" % imdbCode)
+ if imdbList.status_code != 200:
+ return None
+ i = 0
+ actors = []
+ characters = []
+ for match in self.imdbPattern.finditer(imdbList.content):
+ actors.append(match.group(1))
+ character = match.group(2)
+ if character == None:
+ character = match.group(3)
+ characters.append(character)
+ i += 1
+ if i == 10:
break
+ return (actors, characters)
+
+ def get(self):
+ thumbListing = fetch("http://anyclip.zx2c4.com/thumblisting.py")
+ if thumbListing.status_code != 200:
+ self.response.out.write("error")
+ return
+ movies = thumbListing.content.split("\n")
+ for movie in movies:
+ codeThumb = movie.split(" ")
+ if len(codeThumb) != 2:
+ continue
+ code = codeThumb[0]
+ lastThumb = int(codeThumb[1])
+ if Title.all().filter('code = ', code).count() == 0:
+ item = self.api.request("title", (code,))
+ if len(item) == 2 and item[0] == '1005':
+ self.response.out.write("Could not add invalid code %s<br>" % code)
+ continue
+ self.response.out.write("Adding %s<br>" % item["Name"])
+ newTitle = Title(title=item["Name"], code=item["Code"])
+ newTitle.lastThumb = lastThumb
+ cast = self.getCast(item["ImdbID"])
+ if cast == None:
+ self.response.out.write("Could not add cast of %s<br>" % item["Name"])
+ continue
+ newTitle.actors = cast[0]
+ newTitle.characters = cast[1]
+ newTitle.put()
application = webapp.WSGIApplication(