Skip to content

Commit

Permalink
v3 cache function
Browse files Browse the repository at this point in the history
  • Loading branch information
bigsk05 committed Aug 20, 2022
1 parent e797fae commit e5702a2
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 7 deletions.
28 changes: 28 additions & 0 deletions cache.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import os, time
import requests

while True:
# Read donor lists
for file in os.listdir("donors"):
print(file)
try:
donor_object = requests.get("https://api.foldingathome.org/user/{}".format(file))
if donor_object.status_code == 200:
with open(os.path.join("donors", file), "w+") as fb:
fb.write(donor_object.text)
except Exception as e:
print(e)

# Read team lists
for file in os.listdir("teams"):
print(file)
try:
donor_object = requests.get("https://api.foldingathome.org/team/{}".format(file))
if donor_object.status_code == 200:
with open(os.path.join("teams", file), "w+") as fb:
fb.write(donor_object.text)
except Exception as e:
print(e)

time.sleep(5)

Empty file added donors/.keep
Empty file.
Empty file added fonts/.keep
Empty file.
46 changes: 39 additions & 7 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
// Get donor
$donor = $_GET["donor"];

// Get team
$team = $_GET["team"];

// Setting foor ssl
$arr_context_options = array(
"ssl" => array(
Expand All @@ -24,14 +27,43 @@
) ,
);

// Request for data
$donor_data = file_get_contents("https://api.foldingathome.org/user/".$donor, false, stream_context_create($arr_context_options)) or die("api failed");
$donor_object = json_decode($donor_data, true);
if ($DEBUG) var_dump($donor_object);
// Read record
if (file_exists("donors/".$donor)) {
$local_donor = file_get_contents("donors/".$donor);
if (!$local_donor) {
// Request for data
$donor_data = @file_get_contents("https://api.foldingathome.org/user/".$donor, false, stream_context_create($arr_context_options)) or die("api failed");
$donor_object = json_decode($donor_data, true);
if (array_key_exists("status", $donor_object)) {
exit("api failed");
}
if ($DEBUG) var_dump($donor_object);
} else {
$donor_object = json_decode($local_donor, true);
}
}
if (file_exists("teams/".$team)) {
$local_team = file_get_contents("teams/".$team);
if (!$local_team) {
// Request for data
$team_data = @file_get_contents("https://api.foldingathome.org/team/".$team, false, stream_context_create($arr_context_options)) or die("api failed");
$team_object = json_decode($team_data, true);
if (array_key_exists("status", $team_object)) {
exit("api failed");
}
if ($DEBUG) var_dump($team_object);
} else {
$team_object = json_decode($local_donor, true);
}
}

$team_data = file_get_contents("https://api.foldingathome.org/team/".$_GET["team"], false, stream_context_create($arr_context_options)) or die("api failed");
$team_object = json_decode($team_data, true);
if ($DEBUG) var_dump($team_object);
// Save record
if (!file_exists("donors/".$donor)) {
file_put_contents("donors/".$donor, "");
}
if (!file_exists("teams/".$team)) {
file_put_contents("teams/".$team, "");
}

// Load canvas
$canvas = imagecreatetruecolor(465, 92);
Expand Down
Empty file added teams/.keep
Empty file.

0 comments on commit e5702a2

Please sign in to comment.