-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathmain.py
55 lines (45 loc) · 1.52 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
from typing import Optional
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
from pydantic import BaseModel
from starlette.templating import Jinja2Templates
import requests
class TalkApplication(BaseModel):
name: str
email: str
topic: Optional[str] = None
app = FastAPI()
# allow cross origin access while in development
app.add_middleware(
CORSMiddleware,
allow_origins=['http://localhost:3000'],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get('/api/talks/future')
def talks_future():
response = requests.get('https://api.meetup.com/Perth-Django-Users-Group/events/')
if response.status_code == 200:
data = response.json()
sorted_data = sorted(data, key=lambda d: d['time'])
events = []
for event in sorted_data:
events.append({
'name': event['name'],
'time': event['time'],
'venue': event.get('venue', ''),
'attendance': event['yes_rsvp_count'],
'description': event['description'],
'link': event['link'],
})
return events
@app.post('/api/talks/apply')
def talks_apply(application: TalkApplication):
return application
templates = Jinja2Templates(directory='frontend/dist')
@app.get('/')
def index():
return templates.TemplateResponse('index.html', { 'request': {}})
app.mount("/", StaticFiles(directory='frontend/dist'), name='static')