-
Notifications
You must be signed in to change notification settings - Fork 0
/
mock_api.py
34 lines (31 loc) · 877 Bytes
/
mock_api.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
# Mock lyrics API for testing
# Run API with:
# flask --app mock_api.py run --debug --port 5001
# Then add API URL to .env:
# API_URL="http://localhost:5001/{title}/{artist}/"
SONGS = {
'song 1': {
'title': 'Song 1',
'artist': 'Artist A',
'lyrics': 'These are the lyrics\nto song 1\nby artist A',
},
'song 2': {
'title': 'Song 2',
'artist': 'Artist A',
'lyrics': 'These are the lyrics\nto song 2\nby artist A',
},
'song 3': {
'title': 'Song 3',
'artist': 'Artist B',
'lyrics': 'These are the lyrics\nto song 3\nby artist B',
},
}
from flask import Flask
app = Flask(__name__)
@app.get('/<string:title>/')
@app.get('/<string:title>/<string:artist>/')
def api(title, artist=None):
if title.lower() in SONGS:
return SONGS[title.lower()]
else:
return {}