-
Notifications
You must be signed in to change notification settings - Fork 41
/
localhost_server.py
35 lines (27 loc) · 939 Bytes
/
localhost_server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Using FastAPI to build a localhost server for getting back the data from the url
# API libs
# import rich.console
import uvicorn
from fastapi import FastAPI
import time, os, shutil
from pathlib import Path
from rich.console import Console
import urllib.parse as ups
# Zero Time
start_time = time.time()
# Initiate API
app = FastAPI()
@app.get("/")
def main_root(state: str, code: str, scope: str):
string = f"{code}&scope={scope}"
cleaned_code = ups.unquote(string)
return {
"status": "success",
"Message": f"Your code is ready to be used: {cleaned_code}",
}
def rich_print(message: str, console: Console = Console()) -> None:
"""Print the message with rich style. Give me anything with rich style."""
console.print(f"{message}")
return
rich_print(f"[gold1][Time][white] Loading 'localhost' Serve Running on: {time.time()}")
uvicorn.run(app, host='0.0.0.0', port=3030)