def __init__(self, options): self.settings = self.load_settings() self.db = mongodb.connect('tweets') tweets = self.load_tweets(int(options.num), sort=options.sort, mark_read=options.mark_read) d = display.Display() d.display_tweets(tweets)
def __init__(self, options, args): self.debug = options.debug self.db = mongodb.connect('tweets') d = display.Display() if options.user_search: twitterers = self.user_search(options.user_search, int(options.num)) d.display_users(twitterers) else: tweets = self.tweet_search(args, int(options.num)) d.display_tweets(tweets)
def __init__(self, debug=False): self.debug = debug self.db = mongodb.connect(self.DB_NAME) auth = tweepy.OAuthHandler(settings.CONSUMER_KEY, settings.CONSUMER_SECRET) auth.set_access_token(settings.ACCESS_KEY, settings.ACCESS_SECRET) self.api = tweepy.API(auth) last_tweet_id = self.get_last_tweet_id() try: self.fetchTweets(last_tweet_id) except tweepy.error.TweepError: # authorization failure print "You need to authorize tc to connect to your twitter account. I'm going to open a browser. Once you authorize, I'll ask for your PIN." auth = self.setup_auth() self.api = tweepy.API(auth) self.fetchTweets(last_tweet_id) self.classify_tweets()
import sys, os import pymongo sys.path.append('..') from lib import mongodb from classify_tweets import * DB_NAME = 'tweets' if __name__ == '__main__': classifiers = [] for active_classifier in active_classifiers: c = globals()[active_classifier]() classifiers.append(c) db = mongodb.connect(DB_NAME) for r in db[DB_NAME].find(spec={'topics': { '$exists': False }}, fields={ 'text': True, 'user': True }): # for all unclassified tweets print r topics = {} for c in classifiers: (topic, score) = c.classify(r['text']) topics[topic] = score print topics db[DB_NAME].update({'_id': r['_id']}, {'$set': {'topics': topics}})
import sys, os import pymongo sys.path.append('..') from lib import mongodb from classify_tweets import * DB_NAME = 'tweets' if __name__ == '__main__': classifiers = [] for active_classifier in active_classifiers: c = globals()[active_classifier]() classifiers.append(c) db = mongodb.connect(DB_NAME) for r in db[DB_NAME].find(spec={'topics': {'$exists': False } },fields={'text': True, 'user': True}): # for all unclassified tweets print r topics = {} for c in classifiers: (topic, score) = c.classify(r['text']) topics[topic] = score print topics db[DB_NAME].update({'_id': r['_id']}, {'$set': {'topics': topics }})
#!/usr/bin/env python import os, sys import cgi import simplejson as json sys.path.append("..") from lib import mongodb db = mongodb.connect() print "Content-Type: application/json" print form = cgi.FieldStorage() if "lat" not in form or "lng" not in form: print "{'error': 'invalid request'}" os._exit(0) lat = float(form.getvalue("lat")) lng = float(form.getvalue("lng")) points = [] for point in db["points"].find({"loc": {"$near": [lat, lng]}}).limit(100): points.append(point) print json.dumps({"error": False, "results": points})