-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
63 lines (45 loc) · 1.44 KB
/
main.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from fastapi import Request
import uvicorn
import requests
import threading
import time
app = FastAPI()
app.mount("/static", StaticFiles(directory="static"), name="static")
templates = Jinja2Templates(directory="static/templates")
repos = []
def load_projects():
while True:
try:
resp = requests.get("https://api.github.com/users/Mootfrost777/repos").json()
global repos
repos.clear()
for repo in resp:
repos.append(Project(repo["name"], repo["description"], repo["html_url"]))
except Exception as e:
print(e)
time.sleep(7200)
class Project:
name: str
description: str
url: str
def __init__(self, name, description, url):
self.name = name
self.description = description
self.url = url
@app.get("/api/get_repos")
def get_repos():
return repos
@app.get("/")
def main_page(request: Request):
return templates.TemplateResponse("index.html", {"request": request})
@app.get("/about")
def main_page(request: Request):
return templates.TemplateResponse("about.html", {"request": request})
@app.get("/projects")
def main_page(request: Request):
return templates.TemplateResponse("projects.html", {"request": request})
threading.Thread(target=load_projects).start()
uvicorn.run(app)