Beispiel #1
0
    def mentions(self):
        db = cherrypy.request.db
        
        graph = []
        root = {'id': 'root', 'name': '', "data": { "$type": "none" }, 'adjacencies': []}
        for user_id in Mention.users(db):
            node = {
                "nodeTo": "%d" % user_id,
                "data": {
                    '$type': 'none'
                    }
                }
            root['adjacencies'].append(node)
        graph.append(root)

        total = len(root['adjacencies'])
        
        for index, (username, user_id, count) in enumerate(Mention.grouped(db)):
            node = {
                "id": "%d" % user_id,
                "name": username,
                "data": {
                    "$color": "#cf5",
                    "$height": 120,
                    "$angularWidth": count * 360 / (total * 1.0)
                    },
                "adjacencies": []
                }
            graph.append(node)
        return graph
Beispiel #2
0
    def fetch_mentions(self):
        url = "http://api.twitter.com/1/statuses/mentions.json?count=50"

        session = cherrypy.engine.publish('bind-session').pop()
        newest = Mention.newest(session)
        if newest:
            url += "&since_id=%d" % newest.tweet_id
        for user in User.all_(session):
            content = self.bus.publish("oauth-request", url, user.oauth_token,
                                       user.oauth_token_secret).pop()
            tweets = json.loads(content)
            if newest:
                cherrypy.log("Retrieved %d tweets since %s" %
                             (len(tweets), newest.date))
            else:
                cherrypy.log("Retrieved %d tweets" % (len(tweets), ))
            for tweet in tweets:
                user = tweet.get('user')
                if user:
                    session.add(
                        Mention(username=user['name'],
                                user_id=user['id'],
                                tweet=tweet['text'],
                                tweet_id=tweet['id'],
                                lang=self.guess_language(tweet['text']),
                                date=parse(tweet['created_at'])))

        cherrypy.engine.publish('commit-session')
Beispiel #3
0
    def mentions(self):
        db = cherrypy.request.db

        graph = []
        root = {
            'id': 'root',
            'name': '',
            "data": {
                "$type": "none"
            },
            'adjacencies': []
        }
        for user_id in Mention.users(db):
            node = {"nodeTo": "%d" % user_id, "data": {'$type': 'none'}}
            root['adjacencies'].append(node)
        graph.append(root)

        total = len(root['adjacencies'])

        for index, (username, user_id,
                    count) in enumerate(Mention.grouped(db)):
            node = {
                "id": "%d" % user_id,
                "name": username,
                "data": {
                    "$color": "#666633",
                    "$height": 65,
                    "$angularWidth": count * 360 / (total * 1.0)
                },
                "adjacencies": []
            }
            graph.append(node)
        return graph
Beispiel #4
0
    def tweets(self, user_id):
        db = cherrypy.request.db
        tweets = []
        for mention in Mention.tweets(db, int(user_id)):
            tweets.append(mention.tweet)

        return tweets
Beispiel #5
0
    def fetch_mentions(self):
        url = "http://api.twitter.com/1/statuses/mentions.json?count=50"
        
        session = cherrypy.engine.publish('bind-session').pop()
        newest = Mention.newest(session)
        if newest:
            url += "&since_id=%d" % newest.tweet_id
        for user in User.all_(session):
            content = self.bus.publish("oauth-request", url,
                                       user.oauth_token,
                                       user.oauth_token_secret).pop()
            tweets = json.loads(content)
            if newest: cherrypy.log("Retrieved %d tweets since %s" % (len(tweets), newest.date))
            else: cherrypy.log("Retrieved %d tweets" % (len(tweets), ))
            for tweet in tweets:
                user = tweet.get('user')
                if user:
                    session.add(Mention(username=user['name'],
                                        user_id=user['id'],
                                        tweet=tweet['text'],
                                        tweet_id=tweet['id'],
                                        lang=self.guess_language(tweet['text']),
                                        date=parse(tweet['created_at'])))

        cherrypy.engine.publish('commit-session')
Beispiel #6
0
    def tweets(self, user_id):
        db = cherrypy.request.db
        tweets = {}
        for mention in Mention.tweets(db, int(user_id)):
            if mention.lang not in tweets:
                tweets[mention.lang] = []

            tweets[mention.lang].append({'text': mention.tweet})

        return tweets
Beispiel #7
0
    def tweets(self, user_id):
        db = cherrypy.request.db
        tweets = {}
        for mention in Mention.tweets(db, int(user_id)):
            if mention.lang not in tweets:
                tweets[mention.lang] = []
                
            tweets[mention.lang].append({
                'text': mention.tweet
                }
            )

        return tweets