songs2slides

A tool that automatically finds song lyrics and creates lyric slideshows
git clone https://git.ashermorgan.net/songs2slides/
Log | Files | Refs | README

mock_api.py (877B)


      1 # Mock lyrics API for testing
      2 # Run API with:
      3 #   flask --app mock_api.py run --debug --port 5001
      4 # Then add API URL to .env:
      5 #   API_URL="http://localhost:5001/{title}/{artist}/"
      6 
      7 SONGS = {
      8     'song 1': {
      9         'title': 'Song 1',
     10         'artist': 'Artist A',
     11         'lyrics': 'These are the lyrics\nto song 1\nby artist A',
     12     },
     13     'song 2': {
     14         'title': 'Song 2',
     15         'artist': 'Artist A',
     16         'lyrics': 'These are the lyrics\nto song 2\nby artist A',
     17     },
     18     'song 3': {
     19         'title': 'Song 3',
     20         'artist': 'Artist B',
     21         'lyrics': 'These are the lyrics\nto song 3\nby artist B',
     22     },
     23 }
     24 
     25 from flask import Flask
     26 app = Flask(__name__)
     27 
     28 @app.get('/<string:title>/')
     29 @app.get('/<string:title>/<string:artist>/')
     30 def api(title, artist=None):
     31     if title.lower() in SONGS:
     32         return SONGS[title.lower()]
     33     else:
     34         return {}