原理更新

This commit is contained in:
Bigsk 2021-02-21 15:06:55 +08:00
parent 3918b75874
commit a65b58c3d3
2 changed files with 108 additions and 15 deletions

View File

@ -1,21 +1,20 @@
<?php
header("Content-type:application/json;charset=utf-8");
$stream_opts = [
"ssl" => [
"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"}';

89
fah/json/reptile.py Normal file
View File

@ -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()