User Tools

Site Tools


python:deezer-album-tracker

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
python:deezer-album-tracker [2024/03/30 12:22] Wulf Rajekpython:deezer-album-tracker [2024/04/21 20:05] (current) Wulf Rajek
Line 25: Line 25:
 Example output: Example output:
 <code> <code>
-./dat.py --days 7+$ /dat.py --days 7
 Albums released in the past 7 days: Albums released in the past 7 days:
-Release Date: 2024-03-29 
-Artist: Beyoncé 
-Album Name: COWBOY CARTER 
-Link: https://www.deezer.com/album/565889181 
  
-Release Date: 2024-03-29 +Release Date: 2024-04-19 
-Artist: KALEO +Artist: Staind 
-Album Name: Lonely Cowboy +Album Name: Better Days (feat. Dorothy) (1 track) 
-Link: https://www.deezer.com/album/560928422+Link: https://www.deezer.com/album/571491071
  
-Release Date: 2024-03-29 +Release Date: 2024-04-19 
-Artist: Lauren Daigle +Artist: Distilled Harmony 
-Album Name: Be Okay +Album Name: Nova (3 tracks) 
-Link: https://www.deezer.com/album/563282112+Link: https://www.deezer.com/album/572632871 
 + 
 +Release Date: 2024-04-19 
 +Artist: Taylor Swift 
 +Album Name: THE TORTURED POETS DEPARTMENT [EXPLICIT] (16 tracks) 
 +Link: https://www.deezer.com/album/574109801
  
 </code> </code>
Line 91: Line 92:
  
 # Constants for file paths # Constants for file paths
-CONFIG_FILE = "config.json"+CONFIG_FILENAME = "config.json" 
 +SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) 
 +CONFIG_FILE = os.path.join(SCRIPT_DIR, CONFIG_FILENAME)
  
  
Line 193: Line 196:
             for album in data['data']:             for album in data['data']:
                 release_date = datetime.strptime(album['release_date'], '%Y-%m-%d')                 release_date = datetime.strptime(album['release_date'], '%Y-%m-%d')
-                if datetime.strptime(earliest_release, '%Y-%m-%d') <= release_date <= datetime.strptime(today, +                if (datetime.strptime(earliest_release, '%Y-%m-%d') <= release_date <= 
-                                                                                                        '%Y-%m-%d'):+                        datetime.strptime(today, '%Y-%m-%d')): 
 +                    trackresponse = requests.get(album['tracklist']) 
 +                    request_count += 1 
 +                    if trackresponse.status_code == 200: 
 +                        tracklist = trackresponse.json() 
 +                        trackamount = tracklist['total'
 +                    else: 
 +                        trackamount = 0 
                     albums.append({                     albums.append({
                         'artist': artist_name,                         'artist': artist_name,
                         'album_name': album['title'],                         'album_name': album['title'],
                         'release_date': album['release_date'],                         'release_date': album['release_date'],
 +                        'trackamount': trackamount,
                         'explicit_lyrics': album['explicit_lyrics'],                         'explicit_lyrics': album['explicit_lyrics'],
-                        'link': album['link']+                        'link': album['link']
-                        'cover_small': album['cover_small'], +
-                        'cover_medium': album['cover_medium'],+
                     })                     })
  
Line 246: Line 256:
     for index, (artist_name, score) in enumerate(choices):     for index, (artist_name, score) in enumerate(choices):
         print(f"{index + 1}. {artist_name} ({score})")         print(f"{index + 1}. {artist_name} ({score})")
-    choice_index int(input("Enter the number of the artist to delete: ")) - 1 +    choice_input = input("Enter the number of the artist to delete: ") 
-    if 0 <= choice_index < len(choices): +    if choice_input.isnumeric(): 
-        artist_name = choices[choice_index][0] +        choice_index = int(choice_input) - 1 
-        artist_id = [key for key, value in subscribed_artists.items() if value == artist_name][0] +        if 0 <= choice_index < len(choices): 
-        del config[artist_id] +            artist_name = choices[choice_index][0] 
-        save_config(config) +            artist_id = [key for key, value in subscribed_artists.items() if value == artist_name][0] 
-        print(f"Artist '{artist_name}' deleted successfully.")+            del config['artist_ids'][artist_id] 
 +            save_config(config) 
 +            print(f"Artist '{artist_name}' deleted successfully.") 
 +        else: 
 +            print("Invalid choice.")
     else:     else:
-        print("Invalid choice.")+        print("No number entered.")
  
  
Line 282: Line 296:
         albums = get_albums(artist_ids, lookupdays)         albums = get_albums(artist_ids, lookupdays)
  
-        output = f"Albums released in the past {lookupdays} days:\n"+        output = f"Albums released in the past {lookupdays} days:\n\n"
         for album in albums:         for album in albums:
-            output += "Release Date:", album['release_date'], "\n" +            output += f"Release Date: {album['release_date']}\n" 
-            output += "Artist:", album['artist'], "\n"+            output += f"Artist: {album['artist']}\n
 +            output += f"Album Name: {album['album_name']}"
             if album['explicit_lyrics'] is True:             if album['explicit_lyrics'] is True:
-                output += "Album Name:", album['album_name'], " [EXPLICIT]", "\n+                output += " [EXPLICIT]" 
-            else+            if album['trackamount'] > 0
-                output += "Album Name:"album['album_name']"\n" +                output += f({album['trackamount']} track" 
-            output += "Link:", album['link'], "\n"+                if album['trackamount'> 1: 
 +                    output += "s" 
 +                output += ")" 
 +            output += "\n" 
 +            output += f"Link: {album['link']}\n"
             output += "\n"             output += "\n"
-            print(output)+        print(output)
  
         if args.email:         if args.email:
python/deezer-album-tracker.1711801332.txt.gz · Last modified: 2024/03/30 12:22 by Wulf Rajek