Commits

wooparadog  committed 9098419

twitter watcher

  • Participants
  • Parent commits 11ac66b

Comments (0)

Files changed (6)

File main/checkTwitterClients.py

+#!/usr/bin/python
+#coding:utf-8
+
+from tweepy import API
+from tweepy.auth import OAuthHandler, BasicAuthHandler
+from db_model import tweetCount, tweetClient
+from google.appengine.ext import db
+import logging
+import sys
+
+api = API()
+consumer_key = 'vxBbB1ETPsPwcGz6AZ3TSA'
+consumer_secret = 'teRyrSKRPV7V5VasRDSmJdb5P8W7TmywMT9anCWx2U'
+token = '15296418-o0HcsOeXYWCNC13fWu4nb9UYdSeWI7ISBX8vsIY9n'
+tokenSecret='gBjdLu5KzBzbVfbJ7qssRjinPZLWjSw2XrzuLZGsGmU'
+
+        
+def auth():
+    auth = OAuthHandler(consumer_key, consumer_secret)
+    auth_url = auth.get_authorization_url()
+    print 'Please authorize: ' + auth_url
+    verifier = raw_input('PIN: ').strip()
+    print auth.get_access_token(verifier)
+    api = API(auth)
+    print api.auth.access_token.key
+
+def getLastId():
+    command="SELECT * FROM tweetCount limit 1"
+    q = db.GqlQuery(command)
+    if q.count() == 1:
+        return q[0]
+    else:
+        newCount = tweetCount()
+        newCount.since = -1
+        db.put(newCount)
+        return newCount
+        
+
+def checkTwetter():
+    #auth()
+    auth = OAuthHandler(consumer_key, consumer_secret)
+    auth.set_access_token(token,tokenSecret)
+    api = API(auth)
+    if len(sys.argv)>1:
+        api.update_status(sys.argv[1])
+    else:
+        print sys.argv
+    lastCount = getLastId()
+    result = api.home_timeline(since_id=lastCount.since)
+    for i in result:
+        updateDB(i)
+    if len(result):
+        lastCount.since=result[0].id
+        db.put(lastCount)
+
+def update(entry,ori):
+
+    logging.info(entry.name+" before "+str(entry.many))
+    entry.many += 1
+    logging.info(entry.name+" after "+str(entry.many))
+
+    if ori.user.screen_name not in entry.users:
+        logging.info("adding User:"+ ori.user.screen_name)
+        entry.users.append(ori.user.screen_name)
+
+    db.put(entry)
+
+def updateDB(i):
+    command="SELECT * FROM tweetClient where name = '"+i.source.title()+"'"
+    q = db.GqlQuery(command)
+    if q.count()==0:
+        newClient = tweetClient()
+        newClient.name = i.source.title()
+        newClient.many = 1
+        newClient.users= [i.user.screen_name,]
+        db.put(newClient)
+        logging.info("adding new" + i.source.title())
+    elif q.count() == 1:
+        update(q[0],i)
+    else:
+        logging.error("shit")
+        raise Exception('count:'+str(q.count()))
+
+        
+
+if __name__ == "__main__":
+    checkTwetter()

File main/db_model.py

     txt = db.StringProperty()
     user = db.ReferenceProperty(record)
 
+class tweetClient(db.Model):
+    name = db.StringProperty()
+    many = db.IntegerProperty()
+    users = db.StringListProperty()
+
+class tweetCount(db.Model):
+    since = db.IntegerProperty()

File main/db_model.pyc

Binary file modified.

File main/getTimelines.pyc

Binary file modified.

File main/main.py

 from db_model import record,tweets 
 from getTimelines import Test
 from config import watchName, token
+from checkTwitterClients import checkTwetter
 import logging
 
 
         elif num==0:
             addUser(name)
             checkMsg()
+    checkTwetter()
+
 
 
 class realMain(webapp.RequestHandler):
+/home/wooparadog/Documents/project/tweepy/tweepy