Esempio n. 1
0
 def __init__(self, user, retweetFactor=None, impactFactor=None, mcFactor=None, TFIDFArray = None):
     self._api = APISingleton.getInstance()
     self.id = user.id
     self.screen_name = user.screen_name
     self.userObj = user
     self.retweetFactor = retweetFactor
     self.impactFactor = impactFactor
     self.mcFactor = mcFactor
     self.TFIDFArray = TFIDFArray
     self.similarity = None
     if retweetFactor == None:
         self.retweetFactor = self.__calcRetweetFactor()
         self.impactFactor = self.__calcImpactFactor()
         self.TFIDFArray = self._calcTFIDF()
Esempio n. 2
0
 def __init__(self,
              user,
              retweetFactor=None,
              impactFactor=None,
              mcFactor=None,
              TFIDFArray=None):
     self._api = APISingleton.getInstance()
     self.id = user.id
     self.screen_name = user.screen_name
     self.userObj = user
     self.retweetFactor = retweetFactor
     self.impactFactor = impactFactor
     self.mcFactor = mcFactor
     self.TFIDFArray = TFIDFArray
     self.similarity = None
     if retweetFactor == None:
         self.retweetFactor = self.__calcRetweetFactor()
         self.impactFactor = self.__calcImpactFactor()
         self.TFIDFArray = self._calcTFIDF()
Esempio n. 3
0
def getUsersToFollow(keyword, count=10, currentFriends=[]):
    twitterApi = APISingleton.getInstance()

    users = twitterApi.search_users(q=keyword, per_page=random.randint(20, 200), page=random.randint(1,10))
    results = []
    goodResults = []
    for u in users:
        try:
            eUser = EvalUser.load(u)
            results.append(eUser)
            results += eUser.BFS(100, random_walk=True)
            goodResults = [u for u in results if u.getImpactFactor()*u.getRetweetFactor() > 0.05 and u.getUserObj().id not in currentFriends]
            print "Keyword=",keyword, "GoodResults#=",len(goodResults)
            if len(goodResults) > count:
                return goodResults
        except Exception:
            traceback.print_exc(sys.stdout)
            pass
    return goodResults
Esempio n. 4
0
 def loadFromTwitter(cls, userId, userObj=None):
     if not userObj:
         userObj = APISingleton.getInstance().get_user(user_id=userId)
     ret = cls(userObj)
     ret.save()
     return ret
Esempio n. 5
0
import sys
import traceback
sys.path.append("../lib/")
from tweeapi.IR import getTFIDFArray
from db import DBSingleton
import psycopg2.extras

import simplejson

from tweeapi import APISingleton
from tweeapi.utils import EvalUser

if __name__ == "__main__":

    twitterApi = APISingleton.getInstance()

    tweets = twitterApi.search(q=sys.argv[1].lower(),
                               rpp=100,
                               page=1,
                               force=True)
    tweets = [t.text for t in tweets]
    tfidfArray = getTFIDFArray(tweets)

    db = DBSingleton.getInstance()
    cur = db.cursor(cursor_factory=psycopg2.extras.DictCursor)
    cur.execute(
        "select * from users where  retweet_factor > 0.2 and impact_factor > 0.2 limit 1000;"
    )

    results = []
    for row in cur:
        self.queue = queue
        threading.Thread.__init__(self)
    
    def run(self):
        global results
        while True:
            user = self.queue.get()
            try:
                results.append(EvalUser.load(user))
            except Exception:
                traceback.print_exc(sys.stderr)
            self.queue.task_done()

if __name__ == "__main__":

    twitterApi = APISingleton.getInstance()
    users = twitterApi.search_users(q=sys.argv[1], per_page=200)
    results = []
    queue = Queue.Queue()
    for i in range(20):
        t = EvalThread(queue)
        t.setDaemon(True)
        t.start()
    
    for u in users:
        queue.put(u)
        queue.join()
    
    results.sort()
    results.reverse()
    for i in results:
Esempio n. 7
0
 def loadFromTwitter(cls, userId, userObj = None):
     if not userObj:
         userObj = APISingleton.getInstance().get_user(user_id=userId)
     ret = cls(userObj)
     ret.save()
     return ret