def get_results_for_top_list(twitter_app_auth): top_list = [ 'CowboyNewsBot', 'Onlucyme', 'macaspacxx', 'AngeloYnax', 'YnaAngelox', 'lepitens2', 'DXNXXLFXRD', 'Daez17', 'lepitennicell1', 'lepitennicell69', 'kbdpftcristwo2', 'JadineTQ', 'kbdpftcristhre', 'lepitennicell2', 'knsolidified1', 'kbdpftcris9', 'lepitennicell10', 'kbdpftcris8', 'lepitennicell4', 'kbdpftcris10' ] bon = botornot.BotOrNot(**twitter_app_auth) total = len(top_list) print("We are going to classify {} accounts as real or fake".format(total)) result_list = [] for i, username in enumerate(top_list): try: result = bon.check_account('@{}'.format(username)) print( "We have classified {0} account(s), and we have {1} percent to go" .format(i, 1 - round(float(i) / total, 2))) result_list.append(result) tab.insert_one(result) except: print("{} has protected tweets, we will continue".format(username)) result_list.append('failed') continue return result_list
def query_API(self, j): tokens_ar = self.tokens_ar[j] if j == 0: j = 1 else: j = 0 twitter_app_auth = { 'consumer_key': tokens_ar[2], 'consumer_secret': tokens_ar[3], 'access_token': tokens_ar[0], 'access_token_secret': tokens_ar[1], } bon = botornot.BotOrNot(wait_on_ratelimit=True, warn_on_ratelimit=True, **twitter_app_auth) i = 1 for user in self.ids: self.cur.execute( 'SELECT botornot, user_info_json FROM followers WHERE user_id = %s;', (user, )) f = self.cur.fetchone() if f: if f[0]: print "already have botornot score" continue try: user_info = ast.literal_eval(f[1]) timeline = json.load( open('Debot2/stream/' + user + '_stream.json', 'r')) except: print "Error" print user continue else: print "User " + user + " does not exist in db" continue if i % 180 == 0: print "sleep" self.sleep(j) try: score = bon._check_account(user_info, timeline) print score self.cur.execute( 'UPDATE followers SET botornot = %s WHERE user_id = %s', (str(score), user)) self.con.commit() i += 1 except Exception as e: print "Blocked" print e self.sleep(j)
def botornot_search(): token = token_list[key_num] twitter_app_auth = { 'consumer_key': token[0], 'consumer_secret': token[1], 'access_token': token[2], 'access_token_secret': token[3], } bon = botornot.BotOrNot(**twitter_app_auth) start = time() #bon.check_account('@TBTimes_Opinion') bon.check_account('@clayadavis') end = time() print('%s takes' % (end - start))
def bon_analysis( self, twitter_handle ): #bot or not score - more info here: https://truthy.indiana.edu/botornot/ twitter_app_auth = { 'consumer_key': self.consumer_key, 'consumer_secret': self.consumer_secret, 'access_token': self.access_token, 'access_token_secret': self.access_secret, } bon = botornot.BotOrNot(**twitter_app_auth) # Check a single account try: result = bon.check_account(twitter_handle) score = result['score'] except botornot.NoTimelineError as e: score = 'null' return score
def check_username_validity(twitter_app_auth, username_list): client = MongoClient() db = client['country_info'] tab = db['user_check_results'] bon = botornot.BotOrNot(**twitter_app_auth) total = len(username_list) print("We are going to classify {} accounts as real or fake".format(total)) result_list = [] for i, username in enumerate(username_list): try: result = bon.check_account('@{}'.format(username)) print( "We have classified {0} account(s), and we have {1} percent to go" .format(i, 1 - round(float(i) / total, 2))) result_list.append(result) tab.insert_one(result) except: print("{} has protected tweets, we will continue".format(username)) continue return result_list
import matplotlib.pyplot as plt import numpy as np import plotly.plotly as py import tweepy import random import networkx as nx twitter_app_auth = { 'consumer_key': 'C_KEY', 'consumer_secret': 'C_SECRET', 'access_token': 'A_TOK', 'access_token_secret': 'A_TOK_SECRET', 'wait_on_ratelimit':True } bon = botornot.BotOrNot(**twitter_app_auth) #sorts a list of tups by the numerical variable in index i (ascending) def sorttup(thirds,i): l = [] e = [] g = [] if len(thirds) > 1: temp = thirds[0][i] for tup in thirds: if tup[i] > temp: l.append(tup) if tup[i] == temp: e.append(tup) if tup[i] < temp: g.append(tup) return sorttup(g,i)+e+sorttup(l,i)
def query_API(): try: load_dotenv('/home/amanda/bigDisk/Twitter/creds/.env') username = os.getenv('DATABASE_USER') password = os.getenv('DATABASE_PASSWORD') conn_string = "dbname='twitter' user="******" password = "******"3049000188-5uO7lnBazaRcGTDiWzQNP6cYmTX5LeM4TFeIzWd", "i3ZqDFWkr7tkXsdI1PYoQALvE6rtSWaXVPjuHxdFRpTK0", "IrZza7bDaRKGQUc5ZZM2EiCsG", "hYFK0tUtxGBHpwvrsvZ6NLYTTGqCo5rMjBfmAPEtQ3nEm2OmJR" ] """ tokens_ar = ["781174251621494785-vekK5v518ddfH7I0zBOESdWXRgQz63n", "fhVmLgCvVEwzjk28KFLsqPwivs7OlepaEpggtee1WDxqD", "tlUFi9tJGX1NxIA7JWBET2f4K", "4uFHkxjmLyn2mAdLYOCtD1VekrHtg34qYk16kxn0bnSOGnIpxT"] """ twitter_app_auth = { 'consumer_key': tokens_ar[2], 'consumer_secret': tokens_ar[3], 'access_token': tokens_ar[0], 'access_token_secret': tokens_ar[1], } bon = botornot.BotOrNot(wait_on_ratelimit=True, warn_on_ratelimit=True, **twitter_app_auth) f_out = open('clique_expansion/just_LOF/botornot_scores.txt', 'a') users = load_from_file('all_no_dups2.txt') i = 1 for user in users: print user cur.execute('SELECT user_info_json FROM followers WHERE user_id = %s;', (user, )) f = cur.fetchone() if f: try: user_info = ast.literal_eval(f[0]) timeline = json.load( open('Debot2/stream/' + user + '_stream.json', 'r')) except: print "Error" continue else: print "Does not exist in db" continue if i % 180 == 0: print "sleep" time.sleep(900) try: score = bon._check_account(user_info, timeline) print score f_out.write(str(score) + '\n') i += 1 except: print "Blocked" time.sleep(700) try: score = bon._check_account(user_info, timeline) print score f_out.write(str(score) + '\n') i += 1 except: print "Need to sleep more" time.sleep(200) score = bon._check_account(user_info, timeline) print score f_out.write(str(score) + '\n') i += 1
import botornot import json import twauth from dateutil.relativedelta import * from util import * assert len(sys.argv) == 3 bon = botornot.BotOrNot(**twauth.TwitterAuth().auth()) start_time = datetime.now() # Check a sequence of accounts with open(sys.argv[1]) as f: accounts = ['@' + uid for uid in f] acct_sum = len(accounts) printerr_ts("Attempting to identify {:,d} twitter users...".format(acct_sum)) with open(sys.argv[2], 'w') as f: for i, result in enumerate(bon.check_accounts_in(accounts), start=1): # result is a list sres = json.dumps(result, indent=2) print(sres, file=f, end='\n') printerr(sres) printerr_ts("-- {:,d} of {:,d} processed. --".format(i, acct_sum)) printerr_ts('Done. Took {}.'.format( str(relativedelta(datetime.now(), start_time))))
def __init__(self): twitterKey = Auth.getKeyIndex(0) self.bon = botornot.BotOrNot(**twitterKey)
#### # # get followers, classify them as bots, aggregate. # ### from __future__ import print_function import botornot from config.keys import myauth BOTORNOT_API = botornot.BotOrNot(**myauth) def get_bot_or_not(screen_name): """ returns bot or not features, using python package""" try: result = BOTORNOT_API.check_account(screen_name) except Exception as err: print(err) return None return (result)
def authenticate(): key = get_key(KEYFILE) global bon bon = botornot.BotOrNot(**key) return bon