import json
from objects.album import Album
from spotify_crawler import SpotifyCrawler

if __name__ == "__main__":
    crawler = SpotifyCrawler()
    
    artist = crawler.searchArtist("Ed Sheeran")

    if artist:
        albums = crawler.getAlbumsByArtist(artist.getArtistId())

        for album in albums:
            tracks = crawler.getTracksByAlbum(album.getAlbumId())
            album.setTracks(tracks)

        artist.setAlbums(albums)
    
    print(artist.toJSON())

import json
from objects.album import Album
from spotify_crawler import SpotifyCrawler

if __name__ == "__main__":
    crawler = SpotifyCrawler()
    
    artist_name = "Ed Sheeran"
    artist = crawler.searchArtist(artist_name)

    if artist:
        albums = crawler.getAlbumsByArtist(artist.getArtistId())

        for album in albums:
            tracks = crawler.getTracksByAlbum(album.getAlbumId())
            album.setTracks(tracks)

        artist.setAlbums(albums)
    
        print(artist.toJSON())
    else:
        print("Cannot find " + artist_name)

Add the error handle if artist doesn't exist..
Add the error handle if artist doesn't exist..

  import json
  from objects.album import Album
  from spotify_crawler import SpotifyCrawler
  
  if __name__ == "__main__":
      crawler = SpotifyCrawler()
      
+     artist_name = "Ed Sheeran"
-     artist = crawler.searchArtist("Ed Sheeran")
+     artist = crawler.searchArtist(artist_name)
  
      if artist:
          albums = crawler.getAlbumsByArtist(artist.getArtistId())
  
          for album in albums:
              tracks = crawler.getTracksByAlbum(album.getAlbumId())
              album.setTracks(tracks)
  
          artist.setAlbums(albums)
      
-     print(artist.toJSON())
+         print(artist.toJSON())
+     else:
+         print("Cannot find " + artist_name)
  
Add the error handle if artist doesn't exist..
## Code Before:
import json
from objects.album import Album
from spotify_crawler import SpotifyCrawler

if __name__ == "__main__":
    crawler = SpotifyCrawler()
    
    artist = crawler.searchArtist("Ed Sheeran")

    if artist:
        albums = crawler.getAlbumsByArtist(artist.getArtistId())

        for album in albums:
            tracks = crawler.getTracksByAlbum(album.getAlbumId())
            album.setTracks(tracks)

        artist.setAlbums(albums)
    
    print(artist.toJSON())

## Instruction:
Add the error handle if artist doesn't exist..
## Code After:
import json
from objects.album import Album
from spotify_crawler import SpotifyCrawler

if __name__ == "__main__":
    crawler = SpotifyCrawler()
    
    artist_name = "Ed Sheeran"
    artist = crawler.searchArtist(artist_name)

    if artist:
        albums = crawler.getAlbumsByArtist(artist.getArtistId())

        for album in albums:
            tracks = crawler.getTracksByAlbum(album.getAlbumId())
            album.setTracks(tracks)

        artist.setAlbums(albums)
    
        print(artist.toJSON())
    else:
        print("Cannot find " + artist_name)
