def main(): with open('sampleTweets.csv') as f: lunghezzaFile = sum(1 for _ in f) api = connectApi.loginApi() list_ret = [] thefile = open('retweet2.txt', 'a') try: getRetweet(api, 'sampleTweets.csv', thefile, lunghezzaFile, 0, list_ret) except RuntimeError: print('Eccezione Ricorsione') with open('retweet2.txt') as f: lunghezzaRetweet = sum(1 for _ in f) thefile.close() print("Lunghezza Fil Retweet" + str(lunghezzaRetweet)) if (lunghezzaRetweet < lunghezzaFile): print('Eseguo di nuovo la get Retweet, ultima tupla analizzata:' + str(lunghezzaRetweet)) thefile = open('retweet2.txt', 'a') getRetweet(api, 'sampleTweets.csv', thefile, lunghezzaFile, lunghezzaRetweet, list_ret) else: print('Terminato')
def retriveRetweetId(t): api = connectApi.loginApi() results = api.retweets(t.id) list = [] for tweet in results: # retweets = t.GetRetweets(tweet.GetId()) # users = [retweet.GetUser().GetScreenName() for retweet in retweets] list.append(tweet.user.id) print('exception raised, waiting 15 minutes') print('(until:', dt.datetime.now() + dt.timedelta(minutes=15), ')') time.sleep(15 * 60) return list
def retweetmain(readList, query, start, stop, dizionario_tweet, char): api = connectApi.loginApi() list_ret = [] dizionario_retweet = {} # with open('./pickle/retweet_data.pkl', 'wb') as output: result = getRetweet(api, readList, len(readList), list_ret, dizionario_tweet, dizionario_retweet, query, start, stop, char) with open('./pickle/' + query + 'TestAWS/Dicembre/retweet' + char + query + '_' + start + '_' + stop + '_data.pkl', 'wb') as output: pickle.dump(result, output, pickle.HIGHEST_PROTOCOL) # getRetweet(api,readList,len(readList),list_ret,query,start,stop); print('finito getRetweet') with open('./pickle/' + query + 'TestAWS/Dicembre/retweet' + char + query + '_' + start + '_' + stop + '_data.pkl', 'rb') as input: retweetList = pickle.load(input) for i in range(0, len(retweetList)): print (retweetList[i].user)
def main(): with open('sampleTweets.csv') as f: lunghezzaFile = sum(1 for _ in f) print("lunghezzaFile" + str(lunghezzaFile)) print(sys.getrecursionlimit()) sys.setrecursionlimit(10000) api = connectApi.loginApi() list_ret = [] result = getRetweet(api, 'sampleTweets.csv', lunghezzaFile, 0, list_ret) thefile = open('retweet.txt', 'w') #for item in result: # thefile.write("%s\n" % item) for item in result: thefile.write(str(item.posizione) + "," + str(item.retweet) + '\n') print('finito', str(result))
def load_api(): ''' Function that loads the twitter API after authorizing the user. ''' return connectApi.loginApi()