tt / app.py
GuillaumeSalouHF's picture
Update app.py
9f779c5
raw
history blame
1.48 kB
import boto3
import os
import re
import json
from pathlib import Path
import sqlite3
from huggingface_hub import Repository, HfFolder
import tqdm
import subprocess
from fastapi import FastAPI
from fastapi_utils.tasks import repeat_every
paginator = s3.get_paginator('list_objects_v2')
repo.git_pull()
def get_datasetdata(dataset_path):
def sync_rooms_to_dataset():
for room_data_db in get_db(ROOMS_DATA_DB):
except Exception as e:
print(e)
continue
objects += results
room_data_db.commit()
all_rows = [dict(row) for row in room_data_db.execute(
"SELECT * FROM rooms_data WHERE room_id = ?", (room_id,)).fetchall()]
data_path = S3_DATA_FOLDER / f"{room_id}.json"
with open(data_path, 'w') as f:
json.dump(all_rows, f, separators=(',', ':'))
print("Updating repository")
subprocess.Popen(
"git add . && git commit --amend -m 'update' && git push --force", cwd=S3_DATA_FOLDER, shell=True)
app = FastAPI()
@app.post("/")
def read_root():
return "Just a bot to sync data to huggingface datasets and tweet tha latest data"
@app.post("/sync")
def sync():
sync_rooms_to_dataset()
return "Synced data to huggingface datasets"
@app.on_event("startup")
@repeat_every(seconds=1800)
def repeat_sync():
sync_rooms_to_dataset()
return "Synced data to huggingface datasets"