def get(self): # pull the github token out of the social user db and grab gists from github if self.request.get('job_token') != config.job_token: logging.info("Hacker attack on jobs!") return else: user_info = models.User.get_by_id(long(self.request.get('user'))) social_user = models.SocialUser.get_by_user_and_provider( user_info.key, 'github') gists = github.get_user_gists(social_user.uid, social_user.access_token) # update with the gists for gist in gists: article = models.Article.get_by_user_and_gist_id( user_info.key, gist['gist_id']) if article: # update existing article with new data article.title = gist['title'] article.summary = gist['summary'] article.gist_id = gist['gist_id'] article.article_type = gist['article_type'] article.updated = datetime.datetime.fromtimestamp( gist['published']) else: # we have a new article on our hands - insert # prep the slug slug = utils.slugify(gist['title']) article = models.Article( title=gist['title'], summary=gist['summary'], created=datetime.datetime.fromtimestamp( gist['published']), gist_id=gist['gist_id'], owner=user_info.key, slug=slug, article_type=gist['article_type'], ) # update article.put() # flush memcache copy just in case we had it github.flush_gist_content(article.gist_id) # use the channel to tell the browser we are done channel_token = self.request.get('channel_token') channel.send_message(channel_token, 'reload') return
def get(self): # pull the github token out of the social user db and grab gists from github if self.request.get('job_token') != config.job_token: logging.info("Hacker attack on jobs!") return else: user_info = models.User.get_by_id(long(self.request.get('user'))) social_user = models.SocialUser.get_by_user_and_provider(user_info.key, 'github') gists = github.get_user_gists(social_user.uid, social_user.access_token) # update with the gists for gist in gists: article = models.Article.get_by_user_and_gist_id(user_info.key, gist['gist_id']) if article: # update existing article with new data article.title = gist['title'] article.summary = gist['summary'] article.gist_id = gist['gist_id'] article.article_type = gist['article_type'] article.updated = datetime.datetime.fromtimestamp(gist['published']) else: # we have a new article on our hands - insert # prep the slug slug = utils.slugify(gist['title']) article = models.Article( title = gist['title'], summary = gist['summary'], created = datetime.datetime.fromtimestamp(gist['published']), gist_id = gist['gist_id'], owner = user_info.key, slug = slug, article_type = gist['article_type'], ) # update article.put() # flush memcache copy just in case we had it github.flush_gist_content(article.gist_id) # use the channel to tell the browser we are done channel_token = self.request.get('channel_token') channel.send_message(channel_token, 'reload') return
def get(self, article_id=None, username=None): user_info = models.User.get_by_id(long(self.user_id)) article = models.Article.get_by_id(long(article_id)) if article.owner == user_info.key and github.flush_gist_content(article.gist_id): message = 'Article was flushed from cache.' else: message = 'Something went wrong flushing from cache!' return message
def get(self, article_id=None, username=None): user_info = models.User.get_by_id(long(self.user_id)) article = models.Article.get_by_id(long(article_id)) if article.owner == user_info.key and github.flush_gist_content( article.gist_id): message = 'Article was flushed from cache.' else: message = 'Something went wrong flushing from cache!' return message