def store_comics(self, comics_to_store): """ This method accepts a set/list of comic URLs to fetch and store. Loops through the list, creates a new instance for each comic and stores each instance. """ model_instances = [] for comic in comics_to_store: # urlfetch library is unique to Google App Engine logging.info("Fetching %s " % comic) image = urlfetch.fetch(comic) logging.info("Done fetching %s " % comic) # Datastore logging.info("Allocating RabiaStore instance for %s" % comic) rabia = RabiaStore() rabia.encoding = image.headers['content-type'] rabia.comic = image.content rabia.url = comic rabia.json = self.json_schema[comic] model_instances.append(rabia) logging.info("Appending RabiaStore instance to list for %s" % comic) logging.info("Beginning aggregated datastore write.") db.put(model_instances) logging.info("Aggreggated datastore write complete.")
def have_id(self): img_id = self.request.get("img") current_comic = RabiaStore.get(img_id) next_comic = RabiaStore.all().filter("datetime <", current_comic.datetime).order("-datetime") next_comic = next_comic.get() prev_comic = RabiaStore.all().filter("datetime >", current_comic.datetime).order("datetime") prev_comic = prev_comic.get() if next_comic is not None: next_comic = next_comic.key() else: next_comic = False if prev_comic is not None: prev_comic = prev_comic.key() else: prev_comic = False self.template_values = { "prev_comic_id": prev_comic, "next_comic_id": next_comic, "imgur_url": current_comic.url, }
def have_id(self): """ Fetches a specific comic and finds the previous and next comics. """ self.current_comic = RabiaStore.get(self.img_id) self.get_prev_and_next() json = self.current_comic.json self.template_values['imgur_url'] = self.current_comic.url self.template_values['current_comic_id'] = self.img_id self.template_values['reddit_title'] = json['title'] self.template_values['reddit_permalink'] = json['permalink'] self.template_values['nsfw'] = bool(json['over_18']) # Serialize this data so we can store it in memcache self.json_template_values = simplejson.dumps(self.template_values)
def store_comics(self, comics_to_store): """ This method accepts a set/list of comic URLs to fetch and store. Loops through the list, creates a new instance for each comic and stores each instance. """ for comic in comics_to_store: # urlfetch library is unique to Google App Engine image = urlfetch.fetch(comic) # Datastore rabia = RabiaStore() rabia.encoding = image.headers['content-type'] rabia.comic = image.content rabia.url = comic rabia.put() if self.interactive == False: logging.info("Just stored a record for: %s" % comic)