Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -13,15 +13,23 @@ GITHUB_TOKEN = "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"
|
|
13 |
DATA_FILE = "data.json"
|
14 |
|
15 |
def upload_to_github():
|
16 |
-
repo_dir = "
|
17 |
if not os.path.exists(repo_dir):
|
18 |
Repo.clone_from(GITHUB_REPO.replace("https://", f"https://{GITHUB_TOKEN}@"), repo_dir)
|
|
|
19 |
repo = Repo(repo_dir)
|
20 |
file_path = os.path.join(repo_dir, "data.json")
|
|
|
21 |
with open(file_path, "w", encoding="utf-8") as f:
|
22 |
json.dump(data, f, indent=4)
|
|
|
23 |
repo.git.add("data.json")
|
24 |
repo.index.commit("Aggiornato data.json")
|
|
|
|
|
|
|
|
|
|
|
25 |
repo.remote().push()
|
26 |
st.sidebar.success("File JSON aggiornato su GitHub!")
|
27 |
|
|
|
13 |
DATA_FILE = "data.json"
|
14 |
|
15 |
def upload_to_github():
|
16 |
+
repo_dir = "temp_repo"
|
17 |
if not os.path.exists(repo_dir):
|
18 |
Repo.clone_from(GITHUB_REPO.replace("https://", f"https://{GITHUB_TOKEN}@"), repo_dir)
|
19 |
+
|
20 |
repo = Repo(repo_dir)
|
21 |
file_path = os.path.join(repo_dir, "data.json")
|
22 |
+
|
23 |
with open(file_path, "w", encoding="utf-8") as f:
|
24 |
json.dump(data, f, indent=4)
|
25 |
+
|
26 |
repo.git.add("data.json")
|
27 |
repo.index.commit("Aggiornato data.json")
|
28 |
+
|
29 |
+
# Imposta l'URL remoto con autenticazione per evitare problemi di credenziali
|
30 |
+
origin = repo.remote(name='origin')
|
31 |
+
origin.set_url(GITHUB_REPO.replace("https://", f"https://{GITHUB_TOKEN}@"))
|
32 |
+
|
33 |
repo.remote().push()
|
34 |
st.sidebar.success("File JSON aggiornato su GitHub!")
|
35 |
|