90 lines
3.4 KiB
Python
90 lines
3.4 KiB
Python
import requests,time,os,json,bz2,threading,sys
|
|
proxies = {
|
|
"http": "127.0.0.1:4780"
|
|
}
|
|
dirlist=["database/donors/total","database/donors/each","database/teams/total","database/teams/each","database/teams/monthly","database/os"]
|
|
dataset={"donor":"","team":"","teamMonthly":"","os":""}
|
|
def mkdirs(path):
|
|
try:
|
|
os.makedirs(path)
|
|
except:
|
|
pass
|
|
def getList():
|
|
global listdonor
|
|
global listteam
|
|
donorlist=requests.get("https://apps.foldingathome.org/daily_user_summary.txt.bz2",proxies=proxies).content
|
|
donorlist=bz2.decompress(donorlist).decode()
|
|
with open("database/donors/total/list.txt","w+",encoding='utf-8') as obj:
|
|
obj.write(donorlist)
|
|
s1=donorlist.split("\n")
|
|
listdonor=[]
|
|
for obj in s1:
|
|
listdonor.append(obj.split("\t")[0])
|
|
del listdonor[0],listdonor[1]
|
|
teamlist=requests.get("https://apps.foldingathome.org/daily_team_summary.txt.bz2",proxies=proxies).content
|
|
teamlist=bz2.decompress(teamlist).decode()
|
|
with open("database/teams/total/list.txt","w+",encoding='utf-8') as obj:
|
|
obj.write(teamlist)
|
|
s1=teamlist.split("\n")
|
|
listteam=[]
|
|
for obj in s1:
|
|
listteam.append(obj.split("\t")[0])
|
|
del listteam[0],listteam[1]
|
|
def getIndex():
|
|
dataset['donor']=requests.get("https://stats.foldingathome.org/api/donors",proxies=proxies).text
|
|
dataset['team']=requests.get("https://stats.foldingathome.org/api/teams",proxies=proxies).text
|
|
dataset['teamMonthly']=requests.get("https://stats.foldingathome.org/api/teams-monthly",proxies=proxies).text
|
|
dataset['os']=requests.get("https://stats.foldingathome.org/api/os",proxies=proxies).text
|
|
with open("database/donors/total/index.json","w+") as obj:
|
|
obj.write(dataset['donor'])
|
|
with open("database/teams/total/index.json","w+") as obj:
|
|
obj.write(dataset['team'])
|
|
with open("database/teams/monthly/index.json","w+") as obj:
|
|
obj.write(dataset['teamMonthly'])
|
|
with open("database/os/index.json","w+") as obj:
|
|
obj.write(dataset['os'])
|
|
def getDetail():
|
|
for obj in listteam:
|
|
info=requests.get("https://stats.foldingathome.org/api/team/"+obj,proxies=proxies).text
|
|
with open("database/teams/each/"+obj+".json","w+") as fobj:
|
|
fobj.write(info)
|
|
for obj in listdonor:
|
|
info=requests.get("https://stats.foldingathome.org/api/donor/"+obj,proxies=proxies).text
|
|
with open("database/donors/each/"+obj+".json","w+") as fobj:
|
|
fobj.write(info)
|
|
def getDetailLoop():
|
|
while(True):
|
|
getList()
|
|
getDetail()
|
|
time.sleep(24*60*60)
|
|
def getIndexLoop():
|
|
while(True):
|
|
time.sleep(10*60)
|
|
getIndex()
|
|
def getListLoop():
|
|
while(True):
|
|
time.sleep(30*60)
|
|
getList()
|
|
def main():
|
|
for obj in dirlist:
|
|
mkdirs(obj)
|
|
getIndex()
|
|
getList()
|
|
threading.Thread(target=getDetailLoop,args=()).start()
|
|
threading.Thread(target=getIndexLoop,args=()).start()
|
|
threading.Thread(target=getListLoop,args=()).start()
|
|
while(True):
|
|
inp=input(">")
|
|
if(inp=="exit"):
|
|
sys.exit(0)
|
|
elif(inp=="getDetail"):
|
|
threading.Thread(target=getDetail,args=()).start()
|
|
elif(inp=="getIndex"):
|
|
threading.Thread(target=getIndex,args=()).start()
|
|
elif(inp=="getList"):
|
|
threading.Thread(target=getList,args=()).start()
|
|
else:
|
|
print("Unknown command.")
|
|
main()
|
|
|