Example #1
0
auth = tweepy.OAuthHandler(cred['twitter']['consumer_key'], cred['twitter']['consumer_secret'])
auth.set_access_token(cred['twitter']['access_token'], cred['twitter']['access_token_secret'])

api = tweepy.API(auth)

rl = api.rate_limit_status()
print(rl['resources']['friendships']['/friendships/show'])
if rl['resources']['friendships']['/friendships/show']['reset'] == 0:
    time_to_reset = rl['resources']['friendships']['/friendships/show']['reset']-int(time.time())+11
    print "dormindo por %s segundos esperando o reset" % time_to_reset
    if time_to_reset > 0:
        time.sleep(time_to_reset)
    else:
        time.sleep(10)

persister = TweetsPersister() #connect to database
while True:
    #try to get new user
    new_user = persister.loadUnprocessedUser2() 
        
    if new_user and new_user != SOURCE_ID:        
        print 'building network for user %s' % new_user
                
        
        try:
            #check if user is related to source
            relation = api.show_friendship(source_id=SOURCE_ID, target_id=new_user)
            if relation[1].following == True:
                persister.saveFollower(new_user)
                
            time.sleep(5)
Example #2
0
import networkx as nx
import json
import numpy as np
import pickle
from PersistencyLayer import TweetsPersister
import copy

###############################################################################
#PREPARACAO DOS DADOS
###############################################################################
#1- Seleciona grupo de tweets da base

json_fp = open('credentials.json')
cred = json.load(json_fp)

persister = TweetsPersister()

FOLHA = '14594813'
ESTADAO = '9317502'
UOLNOT = '14594698'
G1 = '8802752'
R7 = '65473559'

ROOTUSERS = [int(FOLHA), int(ESTADAO), int(UOLNOT), int(G1), int(R7)]

#ROOTUSER = 14594813
#root_tweets = persister.loadTweetsOfUser(ROOTUSER) #get all root tweets


root_tweets = []
for root in ROOTUSERS: