| import os | |
| import time | |
| import sqlite3 | |
| import threading | |
| from pydantic import BaseModel | |
| from fastapi import FastAPI | |
| from fastapi.responses import HTMLResponse | |
| from huggingface_hub import HfApi | |
| from filesystem import upload, download | |
| app = FastAPI() | |
| class sql(BaseModel): | |
| sql: str | |
| def Upload(): | |
| download() | |
| while True: | |
| try: | |
| upload() | |
| except: | |
| pass | |
| time.sleep(30) | |
| def Connect(): | |
| conn = sqlite3.connect("database.db") | |
| cursor = conn.cursor() | |
| return conn, cursor | |
| def Close(conn: sqlite3.Connection): | |
| conn.commit() | |
| conn.close() | |
| thread = threading.Thread(target=Upload) | |
| thread.start() | |
| def HuggingFaceSpaceRoot(): | |
| return open("usage.html").read() | |
| def UptimeRobot(): | |
| return "OK" | |
| def execute_sql(sql: str): | |
| conn, cursor = Connect() | |
| cursor.execute(sql) | |
| Close(conn) | |
| def execute_sql_post(param: sql): | |
| return execute_sql(param.sql) | |
| def execute_sql_get(sql: str): | |
| return execute_sql(sql) | |
| def select(sql: str): | |
| conn, cursor = Connect() | |
| result = cursor.execute(sql).fetchall() | |
| Close(conn) | |
| return result | |
| def select_post(param: sql): | |
| return select(param.sql) | |
| def select_get(sql: str): | |
| return select(sql) |