def get(self): extra_values = {} try: loser = Moustache.get_by_id(int(self.request.get('l'))) winner = Moustache.get_by_id(int(self.request.get('w'))) extra_values['last_winner'] = winner extra_values['last_loser'] = loser except: pass template_values = self.auth_and_taches() template_values.update(extra_values) self.render_template(template_values)
def get(self): if os.environ['HTTP_HOST'].endswith('.appspot.com'): self.redirect('http://moustachewars.com') extra_values = {} try: loser = Moustache.get_by_id(int(self.request.get('l'))) winner = Moustache.get_by_id(int(self.request.get('w'))) extra_values['last_winner'] = winner extra_values['last_loser'] = loser except: pass template_values = self.auth_and_taches() template_values.update(extra_values) self.render_template(template_values)
def post(self): client = OAuthClient("twitter", self) logged_in = client.get_cookie() if not logged_in: self.redirect("/") twitter_info = client.get("/account/verify_credentials") tache = Moustache() if self.request.get('add-tache'): tache.name = twitter_info["screen_name"] tache_image = images.resize(self.request.get('image'), 340, 340) tache.image = db.Blob(tache_image) tache.put() self.redirect('/profile/'+tache.name) else: self.render_form()
def get(self): today = date.today() #Get the spider, or create it if we lost it spider = get_spider() if not spider: spider = Spider() spider.put() #Find the list of pictures the spider has already found twitpic_spider_list = spider.twitpics #Api to call twitter twitter_search = twapi.Twitter(domain="search.twitter.com") twitter_search.encoded_args = 'q=&ands=&phrase=twitpic&ors=%23movember+%23mowars&since=' + str(spider.last_since) + '&rpp=100&until=' + str(spider.last_until) tw_search_results = twitter_search.search() #Find twitpic links reg = re.compile(r'http://(www)?twitpic.com/([^\s]*)\s*', re.I) results = [] for twt in tw_search_results['results']: #Crudely try to find original tweeter message = twt['text'] if 'RT' not in message[0:8]: #Find all twitpics res = reg.findall(twt['text']) for url_groups in res: #This is just the twitpic link slug twitpic_url = url_groups[1] #Make a tache tache = Moustache(name=twt['from_user'], tweet=twt['text'], twitpic = twitpic_url) #Don't regrab if an older one has if twitpic_url not in twitpic_spider_list: try: tache_image = images.resize(get_twitpic_image(twitpic_url), 340, 340) tache.image = db.Blob(tache_image) tache.put() twitpic_spider_list.append(twitpic_url) results.append(dict) except: pass #Increase limits by a day a time, or just keep it as today and yesterday one_day = timedelta(days=1) spider.last_since = spider.last_until new_until = spider.last_until + one_day if new_until<=today: spider.last_until = new_until else: spider.last_until = today spider.last_since = today - one_day spider.twitpics = twitpic_spider_list spider.put() self.response.out.write(spider.last_until) self.response.out.write(spider.last_since) self.response.out.write('\n\n<br><br>') self.response.out.write(results) self.response.out.write('\n\n<br><br>') self.response.out.write(tw_search_results)