2023-05-28 22:18:12 +02:00
|
|
|
import os
|
|
|
|
import base64
|
|
|
|
from datetime import datetime
|
|
|
|
from app.libraries.database import Database
|
|
|
|
from app.libraries.forgejo import Forgejo, ForgejoNotFoundError
|
|
|
|
import pdb
|
|
|
|
|
|
|
|
def date_string():
|
|
|
|
|
|
|
|
now = datetime.now()
|
|
|
|
|
|
|
|
day = '{:02d}'.format(now.day)
|
|
|
|
|
|
|
|
month = '{:02d}'.format(now.month)
|
|
|
|
|
2023-06-07 13:28:12 +02:00
|
|
|
year = str(now.year)
|
2023-05-28 22:18:12 +02:00
|
|
|
|
2023-06-07 13:28:12 +02:00
|
|
|
return day, month, year
|
2023-05-28 22:18:12 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
|
|
|
db = Database()
|
|
|
|
|
|
|
|
if not os.path.exists('dataset'):
|
|
|
|
|
|
|
|
os.makedirs('dataset')
|
|
|
|
|
2023-06-07 13:28:12 +02:00
|
|
|
day, month, year = date_string()
|
2023-05-28 22:18:12 +02:00
|
|
|
|
2023-06-07 13:28:12 +02:00
|
|
|
if not os.path.exists(f'dataset/{year}'):
|
2023-05-28 22:18:12 +02:00
|
|
|
|
2023-06-07 13:28:12 +02:00
|
|
|
os.makedirs(f'dataset/{year}')
|
2023-05-28 22:18:12 +02:00
|
|
|
|
2023-06-07 13:28:12 +02:00
|
|
|
if not os.path.exists(f'dataset/{year}/{month}'):
|
2023-05-28 22:18:12 +02:00
|
|
|
|
2023-06-07 13:28:12 +02:00
|
|
|
os.makedirs(f'dataset/{year}/{month}')
|
|
|
|
|
|
|
|
filename = f'dataset_{year}{month}{day}.csv'
|
|
|
|
|
|
|
|
db.csv_save(f'dataset/{year}/{month}/{filename}')
|
2023-05-28 22:18:12 +02:00
|
|
|
|
|
|
|
fgj = Forgejo()
|
|
|
|
|
|
|
|
gituser = fgj.user()
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
2023-06-07 13:28:12 +02:00
|
|
|
with open(f'dataset/{year}/{month}/{filename}', 'rb') as input_file:
|
2023-05-28 22:18:12 +02:00
|
|
|
data = input_file.read()
|
|
|
|
file = base64.b64encode(data)
|
|
|
|
|
2023-06-07 13:28:12 +02:00
|
|
|
response = fgj.repo_owner_create_file(gituser.login, fgj.stats_repo, f'dataset/{year}/{month}/{filename}', gituser.email, gituser.login, "main", file, f"{year}{month}{day} fediverse's dataset")
|
2023-05-28 22:18:12 +02:00
|
|
|
|
|
|
|
if 'content' in response:
|
|
|
|
|
|
|
|
print(f'{filename} uploaded to {fgj.api_base_url}/{gituser.login}/{fgj.stats_repo}')
|
|
|
|
|
|
|
|
except:
|
|
|
|
|
|
|
|
print(response)
|
|
|
|
|
|
|
|
pass
|