Ejemplo n.º 1
0
    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')
            apps = github.get_user_gists(social_user.uid,
                                         social_user.access_token)

            # update with the apps we get back from github
            for app in apps:
                app2 = models.App.get_by_user_and_gist_id(
                    user_info.key, app['gist_id'])

                if app2:
                    # update existing app with new data
                    app2.name = app['name']
                    app2.command = app['command']
                    app2.description = app['description']
                    app2.thumb_url = app['thumb_url']
                    app2.gist_id = app['gist_id']
                    app2.public = app['public']
                else:
                    # we have a new app on our hands - insert
                    app2 = models.App(
                        name=app['name'],
                        command=app['command'],
                        description=app['description'],
                        thumb_url=app['thumb_url'],
                        gist_id=app['gist_id'],
                        owner=user_info.key,
                        author=user_info.key,
                        github_author=app['github_author'],
                        public=app['public'],
                    )

                # update
                app2.put()

                # flush memcache copies just in case we had them
                # get our gist's filenames
                files = github.get_gist_filenames(app['gist_id'])

                for afile in files:
                    github.flush_raw_gist_content(app2.gist_id, afile)

            # use the channel to tell the browser we are done
            channel_token = self.request.get('channel_token')
            channel.send_message(channel_token, 'reload')
            return
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
    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')
            apps = github.get_user_gists(social_user.uid, social_user.access_token)

            # update with the apps we get back from github
            for app in apps:
                app2 = models.App.get_by_user_and_gist_id(user_info.key, app['gist_id'])

                if app2:
                    # update existing app with new data
                    app2.name = app['name']
                    app2.command = app['command']
                    app2.description = app['description']
                    app2.thumb_url = app['thumb_url']
                    app2.gist_id = app['gist_id']
                    app2.public = app['public']
                else:
                    # we have a new app on our hands - insert
                    app2 = models.App(
                        name = app['name'],
                        command = app['command'],
                        description = app['description'],
                        thumb_url = app['thumb_url'],
                        gist_id = app['gist_id'],
                        owner = user_info.key,
                        author = user_info.key,
                        github_author = app['github_author'],
                        public = app['public'],
                    )
                
                # update
                app2.put()

                # flush memcache copies just in case we had them
                # get our gist's filenames
                files = github.get_gist_filenames(app['gist_id'])
                
                for afile in files:
                    github.flush_raw_gist_content(app2.gist_id, afile)
               
            # use the channel to tell the browser we are done
            channel_token = self.request.get('channel_token')
            channel.send_message(channel_token, 'reload')
            return
Ejemplo n.º 4
0
    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