Displaying the Album Information
In my last blog post, I was able to pass the folder to Discogs to get a list of albums, and then pick one at random and give me information back about the album picked. That information was returned as a dictionary and now it is time to wire it up to the Chameleon template in Pyramid that will display the HTML.
Here's an example of the JSON:
{'release_title': 'Massey Fucking Hall', 'release_uri': 'https://www.discogs.com/Japandroids-Massey-Fucking-Hall/release/16118824', 'artist_name': 'Japandroids', 'artist_url': 'https://api.discogs.com/artists/1473872', 'release_date': '2020-06-26', 'discogs_main_id': 1829048, 'discogs_main_url': 'https://api.discogs.com/masters/1829048', 'main_release_date': 2020, 'release_image_uri': 'https://img.discogs.com/BVmRNi_A5_Vm8X0ntzUDh8figvE=/fit-in/300x300/filters:strip_icc():format(jpeg):mode_rgb():quality(90)/discogs-images/R-16118824-1604177632-7503.jpeg.jpg', 'genres': ['Rock']}
```@view_config(route_name="play", renderer="silversaucer:templates/play/play.pt") def play(_):
album_release_id = RandomRecordService.get_folder_count(2162484)
print(album_release_id)
release_data = RandomRecordService.get_album_data(album_release_id)
print(release_data)
return {"release_info": release_data}
It was way easier than expected. (And if you know me, you know that the random record picked above is perfect, as
I'm a huge Japandroids fan.) The first thing I did was connect the image URI that the Discogs API passes in the
Chameleon template:
That worked, which was awesome. The whole image is shown, and I don't have to worry about parsing any of the URL.
I quickly added the values to show the *Artist*, *Album*, and *Release Date* information:
Artist: ${release_info.artist_name}
Album: ${release_info.release_title}
Released: ${release_info.release_date}
\
It looks like this:

Looking at Debbie Gibson's *Electric Youth*, the *Genre* key in the dictionary returns a list:
With some trial and error I was able to display the list, but it showed up as code, looking like:
`['Electronic', 'Pop']`. No one wants to see that. The challenge is that Chameleon templates use something like a
shorthand for Python code. I revisited two of my former projects where I would iterate over a list and show the
results, but after lots of trial and error I felt like I was going backwards. Some more search engine queries and
Stack Overflow searching I did what I always do when I get stuck: I asked my wife. It took her about 15 minutes to
figure out how to loop over the list and show it in bullets: