From a65b58c3d320e0bf7257d2195fa09287d192bba0 Mon Sep 17 00:00:00 2001 From: Bigsk Date: Sun, 21 Feb 2021 15:06:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=9F=E7=90=86=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fah/json/api.php | 34 +++++++++-------- fah/json/reptile.py | 89 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+), 15 deletions(-) create mode 100644 fah/json/reptile.py diff --git a/fah/json/api.php b/fah/json/api.php index 96d4d96..bbcbcd6 100644 --- a/fah/json/api.php +++ b/fah/json/api.php @@ -1,21 +1,20 @@ [ - "verify_peer"=>false, - "verify_peer_name"=>false, - ] -]; $error = null; if($_GET['donor'] == null){ - if($_GET['team'] == '*'){ - echo @file_get_contents("http://reverse.ghink.net/fah.php?team=*",false, stream_context_create($stream_opts)); + if($_GET['team'] == '*' or $_GET['team'] == ''){ + echo @file_get_contents("database/teams/total/index.json"); }else{ - echo @file_get_contents("http://reverse.ghink.net/fah.php?team=".$_GET['team'],false, stream_context_create($stream_opts)); + if(file_exists("database/teams/each/".$_GET['team'].".json")){ + echo @file_get_contents("database/teams/each/".$_GET['team'].".json"); + }else{ + header('HTTP/1.1 404 Not Found'); + header('status: 404 Not Found'); + echo '{"error":"404"}'; + } } }else{ - if($_GET['team'] == null){ - }else{ + if($_GET['team'] != null){ header('HTTP/1.1 400 Bad Request'); header('status: 400 Bad Request'); echo '{"error":"400"}'; @@ -23,13 +22,18 @@ if($_GET['donor'] == null){ } if($_GET['team'] == null){ if($_GET['donor'] == '*'){ - echo @file_get_contents("http://reverse.ghink.net/fah.php?donor=*",false, stream_context_create($stream_opts)); + echo @file_get_contents("database/donors/total/index.json"); }else{ - echo @file_get_contents("http://reverse.ghink.net/fah.php?donor=".$_GET['donor'],false, stream_context_create($stream_opts)); + if(file_exists("database/donors/each/".$_GET['team'].".json")){ + echo @file_get_contents("database/donors/each/".$_GET['team'].".json"); + }else{ + header('HTTP/1.1 404 Not Found'); + header('status: 404 Not Found'); + echo '{"error":"404"}'; + } } }else{ - if($_GET['donor'] == null){ - }else{ + if($_GET['donor'] != null){ header('HTTP/1.1 400 Bad Request'); header('status: 400 Bad Request'); echo '{"error":"400"}'; diff --git a/fah/json/reptile.py b/fah/json/reptile.py new file mode 100644 index 0000000..93f9db6 --- /dev/null +++ b/fah/json/reptile.py @@ -0,0 +1,89 @@ +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() +