def yes(self): field_list = self.field_list # print(field_list) # gui.mainWindow(self.master).delete_contact(name) ab.edit_contact(self.entry_id, field_list) db.db_commit() self.top.destroy()
def handle_user_change_name(BOT, update): print(update.message) if update.message.chat_id != BOUNTY_GROUP_ID: return telegram_user = telegram_user = update.message.from_user username = telegram_user.username name = telegram_user.full_name user_id = telegram_user.id group_chat_id = update.message.chat_id user = Bounter.get_bounter(telegram_id=user_id) if user: if 'dalecoin.org' in name and user.is_active_bounter: return elif 'dalecoin.org' in name and not user.is_active_bounter: user.is_active_bounter = True Bounter.break_point(user_id) elif user.is_active_bounter and not ('dalecoin.org' in name): Bounter.break_point(user_id, update_week=True) user.is_active_bounter = False elif 'dalecoin.org' in name: new_user = Bounter.add_bounter(user_id, name, username) new_user.is_active_bounter = True else: Bounter.add_bounter(user_id, name, username) db_commit()
def private_message_handler(BOT, update): telegram_user = update.message.from_user username = telegram_user.username name = telegram_user.full_name user_id = telegram_user.id group_chat_id = update.message.chat_id user = Bounter.get_bounter(telegram_id=user_id) ''' if len(name) >= 39: update.message.reply_text("Your name is too long. You may not be able to participate in this dalecoin bounty program") return ''' if user: if 'dalecoin.org' in name and user.is_active_bounter: pass elif 'dalecoin.org' in name and not user.is_active_bounter: user.is_active_bounter = True Bounter.break_point(user_id) elif user.is_active_bounter and not ('dalecoin.org' in name): Bounter.break_point(user_id, update_week=True) user.is_active_bounter = False elif 'dalecoin.org' in name: new_user = Bounter.add_bounter(user_id, name, username) new_user.is_active_bounter = True else: user = Bounter.add_bounter(user_id, name, username) address = update.message.text if address: if len(address.split(' ')) == 1 and address.startswith('0x'): user.eth_address = address update.message.reply_text( 'ETH address has been updated successfully') db_commit()
def yes(self): """Confirm the deletion of a contact.""" name = self.name gui.mainWindow(self.master).delete_contact(name) db.db_commit() self.top.destroy()
def handle_new_chat_member(BOT, update): if update.message.chat_id != BOUNTY_GROUP_ID: return telegram_user = telegram_user = update.message.from_user username = telegram_user.username name = telegram_user.full_name user_id = telegram_user.id group_chat_id = update.message.chat_id if len(name) >= 39: update.message.reply_text( "Your name is too long. You may not be able to participate in this dalecoin bounty program" ) return user = Bounter.get_bounter(telegram_id=user_id) if user: if 'dalecoin.org' in name: Bounter.set_is_active_bounter(user_id, True) #Bounter.break_point(user_id, update_week=False) Bounter.break_point(user_id, update_week=False) #BOT.send_message(group_chat_id, "welcome") db_commit() return Bounter.add_bounter(user_id, name, username) db_commit()
def short_to_long_over_db(cursor): max_days = 365 users = db_get_all_users(cursor) tweets = [] done = 0 v = [] for i in range(0, len(users)): u = users[i] print(u) if db_is_col(cursor, u, "url") == False: db_add_col(cursor, u, "url", length="1000") print("adding url") cur_time = time.time() tweets = db_get_cols_from_table(cursor, u, ["date", "tweet", "url", "tweet_id"]) http = 0 urls = [] for ii in range(0, len(tweets)): date = int(tweets[ii][0]) t = tweets[ii][1] url = tweets[ii][2] id = tweets[ii][3] if url == "None": if ((cur_time - date) / 60 / 60 / 24) < max_days: ret = re.search("(?P<url>https?://[^\s]+)", t) if ret != None: ret = ret.group("url") if ret.count("\\u2026") == 0: urls.append([ret, id]) #print(urls) if len(urls) > 40 or (len(urls) > 0 and ii == len(tweets) - 1): #print("fetch",urls) urls_out = fetch_parallel(urls) #print("fetch..") for iii in range(0, len(urls_out)): if urls_out[iii][0] != "error": if urls_out[iii][0].startswith('https://'): urls_out[iii][0] = urls_out[iii][0][8:] if urls_out[iii][0].startswith('http://'): urls_out[iii][0] = urls_out[iii][0][7:] if len(urls_out[iii][0]) > 1000: urls_out[iii][0] = urls_out[iii][0][:1000] #print(urls[iii][0]) #print(urls_out[iii][0]) #print() #print(urls_out[iii]) db_update_record(cursor, u, "tweet_id", urls_out[iii][1], "url", urls_out[iii][0]) db_commit() urls = [] ids = []
def group_message_handler(BOT, update): if update.message.chat_id != BOUNTY_GROUP_ID: return telegram_user = telegram_user = update.message.from_user username = telegram_user.username name = telegram_user.full_name user_id = telegram_user.id group_chat_id = update.message.chat_id user = Bounter.get_bounter(telegram_id=user_id) if len(name) >= 39: update.message.reply_text( "Your name is too long. You may not be able to participate in this dalecoin bounty program" ) return if user: if 'dalecoin.org' in name and user.is_active_bounter: return elif 'dalecoin.org' in name and not user.is_active_bounter: user.is_active_bounter = True Bounter.break_point(user_id) elif user.is_active_bounter and not ('dalecoin.org' in name): Bounter.break_point(user_id, update_week=True) user.is_active_bounter = False elif 'dalecoin.org' in name: new_user = Bounter.add_bounter(user_id, name, username) new_user.is_active_bounter = True else: Bounter.add_bounter(user_id, name, username) db_commit()
def sen_run_over_db(cursor): users=db_get_all_users(cursor) tweets=[] cur_time=time.time() done=0 for i in range(0,len(users)): u=users[i] print(u,i,len(users)) if db_is_col(cursor,u,"sen")==False: db_add_col(cursor,u,"sen") print("adding") tweets=db_get_cols_from_table(cursor,u,["tweet_id","tweet","sen","date"]) for t in tweets: delta=int((cur_time-int(t[3]))/60/60/24) #print(delta) if delta<365*2: if t[2]=="None": st=t[1].replace("\\\\","") s=sentiment(st) print(".", end='', flush=True) #print(t[1],s,"new") db_update_record(cursor,u,"tweet_id",t[0],"sen",str(s)) #db_commit() #else: # print(t[2]) print("") db_commit()
def clean_db(BOT, update): if update.message.chat_id != ADMIN_ID: return all_users = Bounter.query.all() for user in all_users: db.session.delete(user) db_commit() update.message.reply_text('Users deleted')
def handle_user_left_chat(BOT, update): #if update.message.chat_id != -201473564: if update.message.chat_id != BOUNTY_GROUP_ID: return telegram_user = telegram_user = update.message.from_user username = telegram_user.username name = telegram_user.full_name user_id = telegram_user.id group_chat_id = update.message.chat_id user = Bounter.get_bounter(telegram_id=user_id) if user: Bounter.break_point(user_id, update_week=True) user.is_active_bounter = False db_commit()
def clas_stats(cursor): users = db_get_all_users(cursor) for u in users: print(u) words_delete_all() c = db_get_cols_from_table(cursor, u, ["clas"]) for w in c: #print(w) word_add(w[0]) words = words_ret_hist() w = "" for i in range(0, len(words[0])): w = w + words[0][i] + "=" + str(words[1][i]) + ";" w = w[:-1] db_update_record(cursor, "user_names", "user_id", u, "clas", w) db_commit() print(w) adas
def update_google_sheet(BOT, update): if update.message.chat_id != ADMIN_ID: return all_users = Bounter.query.all() data_set = [] n = 1 for user in all_users: if user.is_active_bounter and not user.in_google_sheet: user.in_google_sheet = True db_commit() if not user.in_google_sheet: continue wks = Bounter.get_wks(user) bounty_status = 'active' if user.is_active_bounter else 'Not active' address = user.eth_address if user.eth_address else '-' name = user.telegram_username if user.telegram_username else "No telegram username" user_data = [n, name, wks, bounty_status, address] data_set.append(user_data) n += 1 google_sheet.update_sheet(data_set) url = google_sheet.get_sheet_url() update.message.reply_text('Sheet updated successfully \n{}'.format(url))
def scan_change_name(BOT, job): users = Bounter.query.all() user_ids = [user.telegram_id for user in users] all_users = [BOT.get_chat_member(BOUNTY_GROUP_ID, id) for id in user_ids] for user in all_users: try: name = user.user.full_name print(name) user_id = user.user.id bounter = Bounter.get_bounter(user_id) if len(name) >= 39: return if user.status == 'left': if bounter.is_active_bounter: Bounter.break_point(user_id, update_week=True) bounter.is_active_bounter = False db_commit() print(f"{name} is deactivated") continue if 'dalecoin.org' in name and bounter.is_active_bounter: #print(f"{name} is active") pass elif ('dalecoin.org' not in name) and bounter.is_active_bounter: Bounter.break_point(user_id, update_week=True) bounter.is_active_bounter = False db_commit() print(f"{name} is deactivated") elif 'dalecoin.org' in name and not bounter.is_active_bounter: Bounter.break_point(user_id) bounter.is_active_bounter = True db_commit() print(f"{name} is activated") except AttributeError as identifier: name = user.first_name print('no name')
def save(self): db.db_commit()
def cal_retweets(cursor): users = db_get_all_users(cursor) tweets = [] done = 0 v = [] update = False if update == True: for i in range(0, len(users)): u = users[i] print(u) cur_time = time.time() tweets = db_get_cols_from_table(cursor, u, ["date", "tweet"]) rt = 0 origonal = 0 for ii in range(0, len(tweets)): t = tweets[ii][1] delta = (cur_time - int(tweets[ii][0])) / 60 / 60 / 24 if delta < 100.0: if t.startswith("RT "): rt = rt + 1 else: origonal = origonal + 1 if rt + origonal != 0: frac = 100.0 * rt / (rt + origonal) else: frac = 0.0 db_update_record(cursor, "user_names", "user_id", u, "retweets", str(frac)) db_commit() tweets_per_day = db_get_cols_from_table(cursor, "user_names", ["retweets", "job_type1"]) con = [] lab = [] lib = [] snp = [] for i in range(0, len(tweets_per_day)): party = tweets_per_day[i][1] if party.startswith("con") == True: con.append(int(tweets_per_day[i][0])) if party.startswith("lab") == True: lab.append(int(tweets_per_day[i][0])) if party.startswith("lib") == True: lib.append(int(tweets_per_day[i][0])) if party.startswith("snp") == True: snp.append(int(tweets_per_day[i][0])) if int(tweets_per_day[i][0]) != 0: v.append(int(tweets_per_day[i][0])) m = 100 dx = 1.0 x = 0.0 xbins = [] while (x < m): xbins.append(x) x = x + dx con[0] = 0.0 lab[0] = 0.0 snp[0] = 0.0 #lib[0]=0.0 for_web = False if for_web == True: plt.figure(figsize=(25.0, 6.0), dpi=300) plt.title("Re-tweets from MPs as % over last 100 days", fontsize=30) plt.gcf().subplots_adjust(bottom=0.15) plt.hist(v, bins=xbins, alpha=0.5, color='green') plt.hist(con, bins=xbins, alpha=0.8, color='blue') plt.hist(lab, bins=xbins, alpha=0.8, color='red') plt.hist(snp, bins=xbins, alpha=0.8, color='purple') plt.hist(lib, bins=xbins, alpha=0.8, color='yellow') plt.legend(('All', 'Con', 'Lab', 'SNP', "Lib"), fontsize=25) plt.ylabel('Number of MPs', fontsize=25) plt.xlabel('Percentage of tweets that are retweets', fontsize=25) plt.savefig("/var/www/html/graphs/retweets.png", bbox_inches='tight') else: matplotlib.rcParams['font.family'] = 'Open Sans' plt.figure(figsize=(6.0, 6.0), dpi=300) ax = plt.subplot(111) #plt.title("Re-tweets from MPs as % over last 100 days", fontsize=30) plt.gcf().subplots_adjust(bottom=0.15) ax.spines['right'].set_visible(False) ax.spines['top'].set_visible(False) plt.hist(v, bins=xbins, alpha=1.0, color='#36845b') #plt.hist(con, bins=xbins, alpha=0.8,color="#00539f") #plt.hist(lab, bins=xbins, alpha=0.8,color="#d50000") #plt.hist(snp, bins=xbins, alpha=0.8,color="#fff685") #plt.hist(lib, bins=xbins, alpha=0.8,color='yellow') #plt.legend( ( 'Con', 'Lab','SNP'), fontsize=25) plt.ylabel('Number of MPs', fontsize=25) plt.xlabel('Percentage retweets', fontsize=25) plt.savefig("retweet_dist.png", bbox_inches='tight')
def clas(cursor, delta=172800 / 2): users = db_get_all_users(cursor) tweets = [] #users=["JoJohnsonUK"] done = 0 for i in range(271, 562): u = users[i] print(u, i, len(users)) #ada if db_is_col(cursor, u, "clas") == False: db_add_col(cursor, u, "clas") print("adding") tweets = db_get_cols_from_table(cursor, u, ["tweet_id", "tweet"]) for t in tweets: clas, tot, res = clas_clas_text(t[1]) db_update_record(cursor, u, "tweet_id", t[0], "clas", clas) #print(clas) #print(t) db_commit() #adas types = None if tot != 0: m = len(tweets) if m > 500: m = 500 for i in range(0, m): #print(tweets[i]) out = clas_clas_text(tweets[i]) if types == None: types = res else: #print(types) for ii in range(0, len(res)): types[ii][1] = types[ii][1] + res[ii][1] if out != "unknown": clas = clas + 1 path = "/var/www/html/interests/" + u + ".txt" #print(types) #asadasds if clas != 0: types = sorted(types, key=itemgetter(1), reverse=True) sum_ids = 0 for i in range(0, len(types)): sum_ids = sum_ids + types[i][1] clas_perent = 100.0 * (clas / tot) print(u, types, clas_perent) f = open(path, 'w') for i in range(0, len(types)): f.write(types[i][0] + " " + str(int((types[i][1] / sum_ids) * 100.0)) + "\n") #f.write("clas "+str(int(clas_perent))+"\n") f.close()
def cal_tweets_per_day(cursor): users = db_get_all_users(cursor) tweets = [] done = 0 v = [] update = False if update == True: for i in range(0, len(users)): u = users[i] print(u) cur_time = time.time() tweets = db_get_cols_from_table(cursor, u, ["date"]) count = 0 for ii in range(0, len(tweets)): delta = (cur_time - int(tweets[ii][0])) / 60 / 60 / 24 if delta < 100.0: count = count + 1 db_update_record(cursor, "user_names", "user_id", u, "tweets_per_day", str(count / 100.0)) #v.append(count) db_commit() tweets_per_day = db_get_cols_from_table(cursor, "user_names", ["tweets_per_day", "job_type1"]) con = [] lab = [] lib = [] snp = [] for i in range(0, len(tweets_per_day)): party = tweets_per_day[i][1] if party.startswith("con") == True: con.append(int(tweets_per_day[i][0])) if party.startswith("lab") == True: lab.append(int(tweets_per_day[i][0])) if party.startswith("lib") == True: lib.append(int(tweets_per_day[i][0])) if party.startswith("snp") == True: snp.append(int(tweets_per_day[i][0])) v.append(int(tweets_per_day[i][0])) m = 60 dx = 1.0 x = 0.0 xbins = [] while (x < m): xbins.append(x) x = x + dx for_web = False if for_web == True: plt.figure(figsize=(25.0, 6.0), dpi=300) plt.title("Tweets from MPs per day", fontsize=30) plt.gcf().subplots_adjust(bottom=0.15) plt.hist(v, bins=xbins, alpha=0.5, color='green') plt.hist(con, bins=xbins, alpha=0.8, color='blue') plt.hist(lab, bins=xbins, alpha=0.8, color='red') plt.hist(snp, bins=xbins, alpha=0.8, color='purple') plt.hist(lib, bins=xbins, alpha=0.8, color='yellow') plt.legend(('All', 'Con', 'Lab', 'SNP', "Lib"), fontsize=25) plt.ylabel('Number of MPs', fontsize=25) plt.xlabel('Number of tweets/day', fontsize=25) plt.savefig("/var/www/html/graphs/tweets_per_day.png", bbox_inches='tight') else: matplotlib.rcParams['font.family'] = 'Open Sans' ###############All############# plt.clf() plt.figure(figsize=(6.0, 6.0), dpi=300) ax = plt.subplot(111) #plt.title("Tweets from MPs per day", fontsize=30) plt.gcf().subplots_adjust(bottom=0.15) ax.spines['right'].set_visible(False) ax.spines['top'].set_visible(False) ax.hist(v, bins=xbins, alpha=1.0, color='#36845b') plt.ylabel('Number of MPs', fontsize=20) plt.xlabel('Number of tweets/day', fontsize=20) plt.savefig("./tweets_per_day/tweets_per_day_all.png", bbox_inches='tight') ###############Con############# ax = setup_graph() axes = plt.gca() axes.set_ylim([0, 40]) plt.hist(con, bins=xbins, alpha=0.8, color="#00539f") #plt.legend( ( 'Con', 'Lab','SNP',"Lib"), fontsize=20) #plt.ylabel('Number of MPs', fontsize=20) #plt.xlabel('Number of tweets/day', fontsize=20) plt.savefig("./tweets_per_day/tweets_per_day_all_con.png", bbox_inches='tight') ###############Lab############# ax = setup_graph() axes = plt.gca() axes.set_ylim([0, 40]) plt.hist(lab, bins=xbins, alpha=0.8, color="#d50000") #plt.legend( ( 'Con', 'Lab','SNP',"Lib"), fontsize=20) #plt.ylabel('Number of MPs', fontsize=20) #plt.xlabel('Number of tweets/day', fontsize=20) plt.savefig("./tweets_per_day/tweets_per_day_all_lab.png", bbox_inches='tight') ###############SNP############# ax = setup_graph() axes = plt.gca() axes.set_ylim([0, 40]) plt.hist(snp, bins=xbins, alpha=0.8, color="#fff685") #plt.legend( ( 'Con', 'Lab','SNP',"Lib"), fontsize=20) #plt.ylabel('Number of MPs', fontsize=20) #plt.xlabel('Number of tweets/day', fontsize=20) plt.savefig("./tweets_per_day/tweets_per_day_all_snp.png", bbox_inches='tight') ###############Lib############# ax = setup_graph() plt.hist(lib, bins=xbins, alpha=0.8, color='#faa01a') #plt.legend( ( 'Con', 'Lab','SNP',"Lib"), fontsize=20) #plt.ylabel('Number of MPs', fontsize=20) #plt.xlabel('Number of tweets/day', fontsize=20) plt.savefig("./tweets_per_day/tweets_per_day_all_lib.png", bbox_inches='tight')
def yes(self): field_list = self.field_list ab.edit_contact(self.entry_id, field_list) db.db_commit() self.top.destroy()
def http_retweets(cursor): users = db_get_all_users(cursor) tweets = [] done = 0 v = [] update = False if update == True: for i in range(0, len(users)): u = users[i] print(u) cur_time = time.time() tweets = db_get_cols_from_table(cursor, u, ["date", "tweet"]) http = 0 for ii in range(0, len(tweets)): t = tweets[ii][1] delta = (cur_time - int(tweets[ii][0])) / 60 / 60 / 24 if delta < 100.0: if t.count("http"): http = http + 1 if http != 0: frac = 100.0 * http / (len(tweets)) else: frac = 0.0 db_update_record(cursor, "user_names", "user_id", u, "http_tweets", str(frac)) db_commit() tweets_per_day = db_get_cols_from_table(cursor, "user_names", ["http_tweets", "job_type1"]) print(tweets_per_day) con = [] lab = [] lib = [] snp = [] for i in range(0, len(tweets_per_day)): party = tweets_per_day[i][1] if party.startswith("con") == True: con.append(int(tweets_per_day[i][0])) if party.startswith("lab") == True: lab.append(int(tweets_per_day[i][0])) if party.startswith("lib") == True: lib.append(int(tweets_per_day[i][0])) if party.startswith("snp") == True: snp.append(int(tweets_per_day[i][0])) v.append(int(tweets_per_day[i][0])) m = 100 dx = 1.0 x = 0.0 xbins = [] while (x < m): xbins.append(x) x = x + dx plt.figure(figsize=(25.0, 6.0), dpi=300) plt.title("Percentage of tweets which contain web links", fontsize=30) plt.gcf().subplots_adjust(bottom=0.15) plt.hist(v, bins=xbins, alpha=0.5, color='green') plt.hist(con, bins=xbins, alpha=0.8, color='blue') plt.hist(lab, bins=xbins, alpha=0.8, color='red') plt.hist(snp, bins=xbins, alpha=0.8, color='purple') plt.hist(lib, bins=xbins, alpha=0.8, color='yellow') plt.legend(('All', 'Con', 'Lab', 'SNP', "Lib"), fontsize=25) plt.ylabel('Number of MPs', fontsize=25) plt.xlabel('Percent', fontsize=25) plt.savefig("/var/www/html/graphs/http_tweets.png", bbox_inches='tight')
def yes(self): name = self.name gui.mainWindow(self.master).delete_contact(name) db.db_commit() self.top.destroy()