Commits

Bruno Bord committed ec9e827

not really functional yet, but we're going forward

Comments (0)

Files changed (3)

src/home_at_home/config.py

 MONGO_HOST = 'localhost'
 MONGO_DB = 'twitter'
 MONGO_COLLECTION = 'tweets'
+### DO NOT EDIT THESE
+TWITTER_CONSUMER_KEY = 'cHgvJTj3wZcmRS2fHGMLHA'
+TWITTER_CONSUMER_SECRET = 'RcGdM8c3lZBYYoysvbuqmTLtxxtrLz7EVyveksoKxE'
 
 TWITTER_EMAIL = 'email@example.com'
 TWITTER_USERNAME = 'my_twitter_username'

src/home_at_home/hath.py

 from cmd import Cmd
 import argparse
 from config import MONGO_DB, MONGO_HOST, MONGO_COLLECTION
-from config import TWITTER_EMAIL, TWITTER_PASSWORD, TWITTER_USERNAME
 from storage import Storage
 from query import parse_queryargs
+from config import TWITTER_USERNAME
+from config import TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET
+
+try:
+    from config import TWITTER_TOKEN, TWITTER_TOKEN_SECRET
+except ImportError:
+    print "You seem not to have configured Twitter Oauth elements."
+    
+    answer = raw_input('Do you wish to do the Oauth Dance (y/n)? ')
+    if answer.lower() == 'y':
+        from twitter.oauth_dance import oauth_dance
+        oauth_token, oauth_token_secret = oauth_dance('Home Timeline At Home',
+            TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET)
+        print "Now that you've registered, you must add these lines to your local_config.py, and restart the program"
+        print "TWITTER_TOKEN = '%s'" % oauth_token 
+        print "TWITTER_TOKEN_SECRET = '%s'" % oauth_token_secret
+        
+        sys.exit() 
 
 
 class HomeAtHome(Cmd, object):
             host=arguments.host,
             dbname=arguments.db,
             collection=arguments.collection,
-            twitter_email=arguments.twitter_email,
-            twitter_password=arguments.twitter_password,
-            twitter_username=arguments.twitter_username
+            twitter_username=arguments.twitter_username,
+            twitter_config=(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET,
+                TWITTER_TOKEN, TWITTER_TOKEN_SECRET
+            )
         )
 
     def do_quit(self, args):
         help='the MongoDb database name', default=MONGO_DB)
     parser.add_argument('--collection', metavar=str,
         help='the MongoDb collection name', default=MONGO_COLLECTION)
-    parser.add_argument('--twitter-email',
-        help='your twitter email', default=TWITTER_EMAIL)
+#    parser.add_argument('--twitter-email',
+#        help='your twitter email', default=TWITTER_EMAIL)
     parser.add_argument('--twitter-username',
         help='your twitter username', default=TWITTER_USERNAME)
-    parser.add_argument('--twitter-password',
-        help='your twitter password', default=TWITTER_PASSWORD)
+#    parser.add_argument('--twitter-password',
+#        help='your twitter password', default=TWITTER_PASSWORD)
 
     arguments = parser.parse_args()
 

src/home_at_home/storage.py

 from pymongo import ASCENDING, DESCENDING
 
 from twitter import Twitter as Api
+from twitter import OAuth
 from utils import twitter_time_to_dict
 from query import parse_queryargs
 from termcolor import colored
     MongoDb database."""
     
     def __init__(self, host='localhost', dbname='twitter', collection='tweets',
-        twitter_email='', twitter_password='', twitter_username=''):
+        twitter_username='', twitter_config=()):
         try:
             connection = Connection(host)
         except:
             print "Issues with the database connection. Please check"
             sys.exit()
         self.store = connection[dbname][collection]
-        self.twitter_email = twitter_email
-        self.twitter_password = twitter_password
         self.twitter_username = twitter_username
+        self.token, self.token_key, self.con_secret, self.con_secret_key = twitter_config
 
     @property
     def connection(self):
         "Return Twitter API connection."
         if not hasattr(self, "__connection"):
-            self.__connection = Api(
-                email=self.twitter_email,
-                password=self.twitter_password
-            )
+            self.__connection = Api(auth=OAuth(
+                self.token,
+                self.token_key,
+                self.con_secret,
+                self.con_secret_key))
         return self.__connection
 
     def count(self):