Last active
February 12, 2020 10:24
-
-
Save snaketh4x0r/3a08b19726fd65be71984706513ed9dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#reputation calculation | |
def getRep(add): | |
part1="https://map-api-direct.foam.space:443/user" | |
part3='assets' | |
part2='/'.join((add,part3)) | |
url='/'.join((part1,part2)) | |
response=requests.get(url) | |
tempobj=response.json() | |
tempstake=int(tempobj['verifiedPOIs']) | |
rep=0 | |
#positive rep | |
if(tempstake>=250): | |
rep=rep+15 | |
elif(tempstake>=100): | |
rep=rep+10 | |
elif(tempstake>=50): | |
rep=rep+5 | |
else: | |
rep=0 | |
#negative rep | |
if(tempnegstake>=250): | |
rep=rep-10 | |
elif(tempnegstake>=100): | |
rep=rep-5 | |
elif(tempnegstake>=50): | |
rep=rep-2 | |
else: | |
rep=rep-0 | |
return rep | |
#updating reputation in table | |
def updateTable(id, reputation): | |
connection = psycopg2.connect(user="postgres",password="Qwerty500",host="127.0.0.1",port="5432",database="discourse2") | |
cursor = connection.cursor() | |
sql_update_query = """Update accounts set reputation = %s where id = %s""" | |
cursor.execute(sql_update_query, (reputation, id)) | |
connection.commit() | |
#get number of rows in accounts table | |
def getRowRange(): | |
connection = psycopg2.connect(user="postgres",password="Qwerty500",host="127.0.0.1",port="5432",database="discourse2") | |
cursor = connection.cursor() | |
cursor.execute('SELECT COUNT(*) FROM accounts;') | |
range=cursor.fetchone() | |
range=range[0] | |
return range | |
#get list of all addresses in account table as list of string | |
def fetchAddresses(): | |
connection = psycopg2.connect(user="postgres",password="Qwerty500",host="127.0.0.1",port="5432",database="discourse2") | |
cursor=connection.cursor() | |
cursor.execute('SELECT address FROM accounts;') | |
tmp1=cursor.fetchall() | |
tmp2=[''.join(i) for i in tmp1] | |
return tmp2 | |
def finalFunction(): | |
rangetmp=getRowRange() | |
addlist=fetchAddresses() | |
replist=[] | |
for o in addlist: | |
replist=getRep(o) | |
#To-Do | |
#calculate reputation of addresses in addlist | |
#create reputation list and update it to database using updateTable method | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment