-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
49 lines (38 loc) · 1.28 KB
/
main.py
File metadata and controls
49 lines (38 loc) · 1.28 KB
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
from fastapi import FastAPI
from pydantic import BaseModel, Field
from typing import List, Literal
from datetime import datetime
import random
app = FastAPI()
class GeoJSONPoint(BaseModel):
type: Literal["Point"]
coordinates: List[float] = Field(..., min_items=2, max_items=2)
class SongEntry(BaseModel):
song: str
genre: str
country: str
timestamp: datetime
songs_by_genre = {
"Reggaeton": ["Despacito", "Baila Baila", "Dákiti"],
"Pop": ["Blinding Lights", "Levitating", "As It Was"],
"Rock": ["Bohemian Rhapsody", "Smells Like Teen Spirit", "Enter Sandman"],
"Electrónica": ["Titanium", "One More Time", "Levels"],
"Cumbia": ["La Cumbia de los Trapos", "Nunca Es Suficiente", "Yo Tomo"]}
@app.get("/songs", response_model=List[SongEntry])
def get_songs(countries= {"Argentina", "France", "Spain", "Mexico"}):
now = datetime.utcnow()
result = []
for country in countries:
genre = random.choice(list(songs_by_genre.keys()))
song = random.choice(songs_by_genre[genre])
result.append(SongEntry(
song=song,
genre=genre,
country=country,
timestamp=now
))
return result
if __name__ == "__main__":
songs = get_songs()
for song in songs:
print(song)