def risk_score(): mycursor.execute('SELECT address FROM sws_risk_score') check = mycursor.fetchall() for addr in check: address=addr[0] mycursor.execute('SELECT risk_score_by_tx,riskscore_by_safename,riskscore_by_knownheist FROM sws_risk_score WHERE address="'+str(address)+'"') check = mycursor.fetchall() for record in check: print(record) score = 0 for lst in record: if lst is not None: score = lst+score risk_score = 50+score mycursor.execute('UPDATE sws_address SET address_risk_score="'+str(risk_score)+'" WHERE address = "'+str(address)+'"') print("updated") mydb.commit()
def auto_fetch(): print("runing") response_user_token = requests.get(url=ETH_SCAM_URL) mycursor.execute("""CREATE TABLE IF NOT EXISTS `sws_heist_address` ( id INT,coin varchar(100),tag_name varchar(100),status varchar(100),address varchar(100),source varchar(1000),subcategory varchar(100),description varchar(1500),also_known_as varchar(1000))""") response = response_user_token.json() result = response['result'] if result: for record in result: if "addresses" in record: coin = record['coin'] category = record['category'] status = record['status'] url = record['url'] if "subcategory" in record: subcate = record['subcategory'] else: subcate = "" subcategory = subcate if "description" in record: description = record['description'] else: description = "" addr = record['addresses'] for add in addr: addresses = add mycursor.execute('SELECT * FROM sws_heist_address WHERE address="'+str(addresses)+'"') check = mycursor.fetchall() if not check: print("added") mycursor.execute('''SELECT MAX(id) FROM sws_heist_address''') maxid = mycursor.fetchone() check=maxid[0] if check is None: ids = 1 else: ids=(maxid[0]+1) print(ids) conversion =description.replace('"','') mycursor.execute('INSERT INTO sws_heist_address (id,coin,tag_name,status,address,source,subcategory,description,also_known_as) VALUES ("'+str(ids)+'","'+str(coin)+'","'+str(category)+'","'+str(status)+'","'+str(addresses)+'","https://etherscamdb.info/api/scams","'+str(subcategory)+'","'+str(conversion)+'","'+str(url)+'")') mydb.commit() else: print("already_exist")
def risk_score_by_heist(): print("runnnnnn") mycursor.execute("""CREATE TABLE IF NOT EXISTS `sws_risk_score` ( id INT NOT NULL AUTO_INCREMENT,address varchar(100),risk_score_by_tx float(3) NULL,type_id int(3) NULL,riskscore_by_safename float(3) NULL,riskscore_by_knownheist float(3) NULL,PRIMARY KEY (id))""") mycursor.execute('SELECT address,type_id FROM sws_address') check = mycursor.fetchall() print("line 150") for check in check: address=check[0] type_id=check[1] print("line 153") mycursor.execute('SELECT * FROM sws_risk_score WHERE address="'+str(address)+'"') check = mycursor.fetchall() if not check: mycursor.execute('INSERT INTO `sws_risk_score`(address,type_id) VALUES ("'+str(address)+'","'+str(type_id)+'")') mydb.commit() print("line 155") heist_addresses=[] mycursor.execute('SELECT address FROM sws_heist_address WHERE (tag_name <> "heist_associated")') ret = mycursor.fetchall() for addres in ret: address=addres[0] heist_addresses.append(address) print(len(heist_addresses)) print("170") heist_associated_addresses=[] mycursor.execute('SELECT address FROM sws_heist_address WHERE (tag_name = "heist_associated")') ret = mycursor.fetchall() for add in ret: addres=add[0] heist_associated_addresses.append(addres) print("177") mycursor.execute('SELECT address FROM sws_risk_score') check = mycursor.fetchall() for addr in check: address=addr[0] records = mongo.db.sws_history.find_one({"address":address}) if records is not None: transactions=records['transactions'] addresses=[] for transaction in transactions: fro =transaction['from'] for frmm in fro: fr = frmm['send_amount'] addresses.append(fr) for checkk in addresses: print("checkkkk") if checkk in heist_addresses: tx_knownheist_formula =-((50*50)/100) mycursor.execute('UPDATE sws_risk_score SET riskscore_by_knownheist ="'+str(tx_knownheist_formula)+'" WHERE address = "'+str(address)+'"') print("updated_50%") mydb.commit() if checkk in heist_associated_addresses: tx_heistassosiated_formula = -((50*30)/100) mycursor.execute('UPDATE sws_risk_score SET riskscore_by_knownheist ="'+str(tx_heistassosiated_formula)+'" WHERE address = "'+str(address)+'"') print("updated_30%") mydb.commit() else: pass
def Top_user_percentage(): print("runnnnnn") mycursor.execute('SELECT address,address_risk_score FROM sws_address') check = mycursor.fetchall() all_records_count = len(check) data = [] for record in check: risk_score = record[1] data.append(risk_score) for score in check: r_address = score[0] r_score = score[1] count = 1 for scr in data: if r_score < scr: count = count + 1 calculating = all_records_count * count / all_records_count print(r_address) print(calculating) mycursor.execute('UPDATE sws_address SET address_top_rate ="' + str(calculating) + '" WHERE address = "' + str(r_address) + '"') mydb.commit() '''
def risk_score_by_safename(): print("runnnnnn") mycursor.execute("""CREATE TABLE IF NOT EXISTS `sws_risk_score` ( id INT NOT NULL AUTO_INCREMENT,address varchar(100),risk_score_by_tx float(3) NULL,type_id int(3) NULL,riskscore_by_safename float(3) NULL,riskscore_by_knownheist float(3) NULL,PRIMARY KEY (id))""") mycursor.execute('SELECT address,type_id FROM sws_address') check = mycursor.fetchall() print("line 150") for a in check: address=a[0] type_id=a[1] print("line 153") mycursor.execute('SELECT * FROM sws_risk_score WHERE address="'+str(address)+'"') check = mycursor.fetchall() if not check: mycursor.execute('INSERT INTO `sws_risk_score`(address,type_id) VALUES ("'+str(address)+'","'+str(type_id)+'")') mydb.commit() print("line 155") kyc_and_secure_addresses=[] mycursor.execute('SELECT u.address FROM db_safename.sws_user as a left join db_safename.sws_address as u on a.username = u.cms_login_name where (kyc_verified = 1 AND profile_status = "secure")') che = mycursor.fetchall() for addr in che: cms_name=addr[0] kyc_and_secure_addresses.append(cms_name) print("300") print("308") secure_addresses=[] mycursor.execute('SELECT u.address FROM db_safename.sws_user as a left join db_safename.sws_address as u on a.username = u.cms_login_name where profile_status = "secure" AND (kyc_verified <> 1 OR kyc_verified is null )') chek = mycursor.fetchall() for addr in chek: cms_name=addr[0] secure_addresses.append(cms_name) print("315") print("323") mycursor.execute('SELECT address FROM sws_risk_score') check = mycursor.fetchall() for addr in check: address=addr[0] print(address) records = mongo.db.sws_history.find_one({"address":address}) if records is not None: print("488888888888888888888") transactions=records['transactions'] if transactions: print("asdasdasdffdasfdasfdfa51") addresses=[] for transaction in transactions: fro=transaction['from'] for fromm in fro: fr = fromm['send_amount'] addresses.append(fr) for checkk in addresses: print("asdasdadd59") if checkk in kyc_and_secure_addresses: print("adasda") tx_safe_name_formula = (50*10)/100 mycursor.execute('UPDATE sws_risk_score SET riskscore_by_safename ="'+str(tx_safe_name_formula)+'" WHERE address = "'+str(address)+'"') print(checkk) print("updated_10%") mydb.commit() if checkk in secure_addresses: tx_safe_name_formula = (50*5)/100 mycursor.execute('UPDATE sws_risk_score SET riskscore_by_safename ="'+str(tx_safe_name_formula)+'" WHERE address = "'+str(address)+'"') print(checkk) print("updated_5%") mydb.commit() else: pass
def tx_two_yearold(): print("runnnnnn") mycursor.execute( """CREATE TABLE IF NOT EXISTS `sws_risk_score` ( id INT NOT NULL AUTO_INCREMENT,address varchar(100),risk_score_by_tx float(3) NULL,type_id int(3) NULL,riskscore_by_safename float(3) NULL,riskscore_by_knownheist float(3) NULL,PRIMARY KEY (id))""" ) mycursor.execute('SELECT address,type_id FROM sws_address') check = mycursor.fetchall() print("line 150") for details in check: address = details[0] type_id = details[1] print("line 153") mycursor.execute('SELECT * FROM sws_risk_score WHERE address="' + str(address) + '"') check = mycursor.fetchall() if not check: mycursor.execute( 'INSERT INTO `sws_risk_score`(address,type_id) VALUES ("' + str(address) + '","' + str(type_id) + '")') mydb.commit() print("line 155") #mycursor.execute('SELECT address,type_id FROM sws_risk_score WHERE (tx_calculated <> 1 OR tx_calculated is null)') mycursor.execute('SELECT address FROM sws_risk_score') check = mycursor.fetchall() for addrr in check: address = addrr[0] records = mongo.db.sws_history.find_one({"address": address}) if records is not None: transactions = records['transactions'] if transactions: count = 0 for transaction in transactions: first_date = transaction['date'] date_time = dateutil.parser.parse(str(first_date)) month = date_time.strftime("%m/%d/%Y") two_year_back = datetime.datetime.today() + relativedelta( months=-24) back = two_year_back.strftime("%m/%d/%Y") if month < back: count = count + 1 if count == 4: formula = (50 * 10) / 100 #mycursor.execute('UPDATE sws_risk_score SET risk_score_by_tx ="'+str(formula)+'",tx_calculated =1 WHERE address = "'+str(address)+'"') mycursor.execute( 'UPDATE sws_risk_score SET risk_score_by_tx ="' + str(formula) + '" WHERE address = "' + str(address) + '"') print("updated_plus") mydb.commit() else: pass else: pass else: tx_formula = ((50 * 5) / 100) mycursor.execute( 'UPDATE sws_risk_score SET risk_score_by_tx ="' + str(tx_formula) + '" WHERE address = "' + str(address) + '"') print("updated_minus") mydb.commit()
def heist_associated_fetch(): print("runningggggg") mycursor.execute('select coin, address from `sws_heist_address`') result = mycursor.fetchall() for res in result: coin = res[0] address= res[1] if coin == 'ETH': print("eth") url1=ETH_TRANSACTION_URL doc=url1.replace("{{address}}",''+address+'') response_user = requests.get(url=doc) res = response_user.json() if 'status' in res: status_code = res['status'] else: status_code = "1" if status_code != "0": transactions=res['result'] frm=[] to=[] for transaction in transactions: fro =transaction['from'] too=transaction['to'] to.append({"to":too}) frm.append({"from":fro}) for fund_trans in frm: address=fund_trans['from'] mycursor.execute('SELECT * FROM sws_heist_address WHERE address="'+str(address)+'"') check = mycursor.fetchall() if not check: print("added") mycursor.execute('''SELECT MAX(id) FROM sws_heist_address''') maxid = mycursor.fetchone() check=maxid[0] if check is None: ids = 1 else: ids=(maxid[0]+1) print(ids) category = "heist_associated" status = "Active" url = "" subcategory = "" conversion = "" mycursor.execute('INSERT INTO sws_heist_address (id,coin,tag_name,status,address,source,subcategory,description,also_known_as) VALUES ("'+str(ids)+'","'+str(coin)+'","'+str(category)+'","'+str(status)+'","'+str(address)+'","'+str(url)+'","'+str(subcategory)+'","'+str(conversion)+'","related to heist_address")') mydb.commit() else: print("already_exist") for fund_reci in to: address=fund_reci['to'] mycursor.execute('SELECT * FROM sws_heist_address WHERE address="'+str(address)+'"') check = mycursor.fetchall() if not check: print("to_added") mycursor.execute('''SELECT MAX(id) FROM sws_heist_address''') maxid = mycursor.fetchone() check=maxid[0] if check is None: ids = 1 else: ids=(maxid[0]+1) print(ids) name = "" category = "heist_associated" status = "Active" url = "" subcategory = "" conversion = "" mycursor.execute('INSERT INTO sws_heist_address (id,coin,tag_name,status,address,source,subcategory,description,also_known_as) VALUES ("'+str(ids)+'","'+str(coin)+'","'+str(category)+'","'+str(status)+'","'+str(address)+'","'+str(url)+'","'+str(subcategory)+'","'+str(conversion)+'","related to heist_address")') mydb.commit() else: print("already_exist") if coin == 'BTC': print("btc") url1=BTC_TRANSACTION doc=url1.replace("{{address}}",''+address+'') response_user = requests.get(url=doc) res = response_user.json() transactions = res['txs'] frm=[] for transaction in transactions: frmm=transaction['inputs'] for trans in frmm: fro=trans['address'] frm.append({"from":fro}) for fund_trans in frm: address=fund_trans['from'] mycursor.execute('SELECT * FROM sws_heist_address WHERE address="'+str(address)+'"') check = mycursor.fetchall() if not check: print("added") mycursor.execute('''SELECT MAX(id) FROM sws_heist_address''') maxid = mycursor.fetchone() check=maxid[0] if check is None: ids = 1 else: ids=(maxid[0]+1) print(ids) category = "heist_associated" status = "Active" url = "" subcategory = "" conversion = "" mycursor.execute('INSERT INTO sws_heist_address (id,coin,tag_name,status,address,source,subcategory,description,also_known_as) VALUES ("'+str(ids)+'","'+str(coin)+'","'+str(category)+'","'+str(status)+'","'+str(address)+'","'+str(url)+'","'+str(subcategory)+'","'+str(conversion)+'","related to heist_address")') mydb.commit() else: print("already_exist")