-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
fcremer
committed
Nov 18, 2023
1 parent
4ba31ef
commit 4032939
Showing
5 changed files
with
50 additions
and
11 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,46 @@ | ||
import yaml | ||
import os | ||
import requests | ||
import json | ||
|
||
DATA_PATH = "data.yaml" | ||
GIST_ID = "8542e223cdd0ff01905aa79b439927bb" # Replace with your Gist ID | ||
TOKEN = "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" # Replace with your GitHub token | ||
GIST_FILENAME = "score.yaml" | ||
|
||
headers = {"Authorization": f"token {TOKEN}"} | ||
|
||
def fetch_gist_content(): | ||
url = f"https://api.github.com/gists/{GIST_ID}" | ||
response = requests.get(url, headers=headers) | ||
response.raise_for_status() | ||
gist_data = response.json() | ||
return gist_data['files'][GIST_FILENAME]['content'] | ||
|
||
def update_gist(content): | ||
url = f"https://api.github.com/gists/{GIST_ID}" | ||
data = { | ||
"files": { | ||
GIST_FILENAME: { | ||
"content": content | ||
} | ||
} | ||
} | ||
response = requests.patch(url, headers=headers, data=json.dumps(data)) | ||
response.raise_for_status() | ||
return response.json() | ||
|
||
def load_data(): | ||
if not os.path.exists(DATA_PATH): | ||
try: | ||
content = fetch_gist_content() | ||
# print("LOAD DEBUG"+content) | ||
return yaml.safe_load(content) | ||
except Exception as e: | ||
return {"pinball_machines": [], "players": [], "scores": []} | ||
with open(DATA_PATH, "r") as file: | ||
return yaml.safe_load(file) | ||
|
||
def save_data(data): | ||
with open(DATA_PATH, "w") as file: | ||
yaml.dump(data, file) | ||
try: | ||
content = yaml.dump(data) | ||
update_gist(content) | ||
#print("SAVECONTENT: " + data) | ||
except Exception as e: | ||
print(f"Error saving data: {e}") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
Flask | ||
PyYAML | ||
PyYAML | ||
requests |
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
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