Delete backups
Browse files- backups/__init__.py +0 -0
- backups/backup.py +0 -44
- backups/sync.py +0 -39
backups/__init__.py
DELETED
|
File without changes
|
backups/backup.py
DELETED
|
@@ -1,44 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
backup.py - Backup client for the table 'api_tok'
|
| 3 |
-
"""
|
| 4 |
-
|
| 5 |
-
import os
|
| 6 |
-
import requests
|
| 7 |
-
import pandas as pd
|
| 8 |
-
from dotenv import load_dotenv
|
| 9 |
-
load_dotenv()
|
| 10 |
-
|
| 11 |
-
TABLE_NAME = os.getenv("TABLE_NAME")
|
| 12 |
-
SUPABASE_URL = os.getenv("SUPA_URL")
|
| 13 |
-
SUPABASE_KEY = os.getenv("SUPA_KEY")
|
| 14 |
-
|
| 15 |
-
def backup_data() -> None:
|
| 16 |
-
curr = os.path.dirname(__file__)
|
| 17 |
-
data_dir = os.path.abspath(os.path.join(curr, "..", "backups/data"))
|
| 18 |
-
|
| 19 |
-
RAW_CSV_PATH = os.path.join(data_dir, "api_tok.csv")
|
| 20 |
-
|
| 21 |
-
API_TABLE_ENDPOINT = f"{SUPABASE_URL}/rest/v1/{TABLE_NAME}"
|
| 22 |
-
|
| 23 |
-
headers = {
|
| 24 |
-
"apikey": SUPABASE_KEY,
|
| 25 |
-
"Authorization": f"Bearer {SUPABASE_KEY}",
|
| 26 |
-
"Content-Type": "application/json",
|
| 27 |
-
}
|
| 28 |
-
|
| 29 |
-
query = {
|
| 30 |
-
"select": "*",
|
| 31 |
-
"order": "user_id.asc"
|
| 32 |
-
}
|
| 33 |
-
|
| 34 |
-
api_res = requests.get(API_TABLE_ENDPOINT, headers=headers, params=query)
|
| 35 |
-
|
| 36 |
-
if api_res.status_code == 200:
|
| 37 |
-
data = api_res.json()
|
| 38 |
-
pd.DataFrame(data).to_csv(RAW_CSV_PATH, index=False, mode='w')
|
| 39 |
-
print(f"Backed up api_tok TABLE to {RAW_CSV_PATH}")
|
| 40 |
-
else :
|
| 41 |
-
print(f"Failed to backup : {api_res.status_code} - {api_res.text}")
|
| 42 |
-
|
| 43 |
-
if __name__ == "__main__":
|
| 44 |
-
backup_data()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
backups/sync.py
DELETED
|
@@ -1,39 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
sync.py - This module is responsible for syncing the local CSV files to the Supabase database.
|
| 3 |
-
Use this to add bulk data from the csv located in the data/ folder to the Supabase tables.
|
| 4 |
-
This is a one-time utility to populate the database with existing data.
|
| 5 |
-
"""
|
| 6 |
-
|
| 7 |
-
import pandas as pd
|
| 8 |
-
import requests
|
| 9 |
-
import os
|
| 10 |
-
from dotenv import load_dotenv
|
| 11 |
-
load_dotenv()
|
| 12 |
-
|
| 13 |
-
TABLE_NAME = os.getenv("TABLE_NAME")
|
| 14 |
-
SUPABASE_URL = os.getenv("SUPA_URL")
|
| 15 |
-
SUPABASE_KEY = os.getenv("SUPA_KEY")
|
| 16 |
-
|
| 17 |
-
def sync_api_csv_to_supabase() -> None:
|
| 18 |
-
df = pd.read_csv('./data/api_tok.csv')
|
| 19 |
-
print("Synced api_tok CSV to Supabase")
|
| 20 |
-
|
| 21 |
-
records = df.to_dict(orient='records')
|
| 22 |
-
|
| 23 |
-
headers = {
|
| 24 |
-
"apikey": SUPABASE_KEY,
|
| 25 |
-
"Authorization": f"Bearer {SUPABASE_KEY}",
|
| 26 |
-
"Content-Type": "application/json",
|
| 27 |
-
"Prefer": "resolution=merge-duplicates"
|
| 28 |
-
}
|
| 29 |
-
|
| 30 |
-
endpoint = f"{SUPABASE_URL}/rest/v1/{TABLE_NAME}"
|
| 31 |
-
res = requests.post(endpoint, headers=headers, json=records)
|
| 32 |
-
|
| 33 |
-
if res.status_code in [200, 201]:
|
| 34 |
-
print("Successfully synced data!")
|
| 35 |
-
else:
|
| 36 |
-
print(f"Error: {res.status_code} - {res.text}")
|
| 37 |
-
|
| 38 |
-
if __name__ == "__main__":
|
| 39 |
-
sync_api_csv_to_supabase()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|