Music blog playlists with entries linking to Last.FM & YouTube

As I mentioned in a previous post of mine, Radio + Me = ❤, I was doing a radio show for over 2 years. During those 2 years, I kept a blog on which I would post the playlist of each show, so that people could find the artist and title of a song they liked, and discover new artists and songs. Just putting the names up is an easy task, but I wanted something more. So I made a Python script that would automatically link the artist’s name to their Last.FM page, and the title to a search on YouTube for that song. That way, discovering more information about the artists, and listening to the song again was easy for the users, and easy for me to maintain.

from Tkinter import Tk

stime = raw_input("Time: ")
f = open("list.txt", "w")
while stime != "":
	artist = raw_input("Artist: ")
	title = raw_input("Title: ")
	artist_y = str.replace(artist, "&", "%26")
	title_y = str.replace(title, "&", "%26")
	msg = stime + r' | <a href="' + artist_y + r'">' + artist + r'</a> - <a href="' + artist_y + " " + title_y + r'&search_type=&aq=f">' + title + '</a><br />'
	f.write(msg + '\n')
	stime = raw_input("\nTime: ")

The str.replace(…) commands are there because YouTube doesn’t like “&”or


in the URL, but uses “%26” to represent the ampersand, which works for Last.FM as well. If you try to use the artist and title variables in the URLs, you’ll see that YouTube stops at the first “&” character in the search query, and ignores the rest.

The result is saved in a “list.txt” file in the same folder as the script, and pasting it into a Blogger or WordPress blog post should give you a result like this.

P.S. This script is now in a GitHub repo I’ve created so that I can upload any small scripts that don’t need a repository of their own.

How to avoid fluctuations around a threshold

Although my experience with Python is limited to whatever university assignments recommended it as a programming language (mostly Natural Language Processing ones) and some other smaller projects of my own, I’ve found reasons to love (and to hate) it. A former fellow student of mine, Dimitris, is obviously in love with it, and I don’t mean that in a bad way. His book on the language is one of the best programming language guides I’ve ever read, and his blog approaches a lot of problems, some less common than others, using Python. Here’s his approach on avoiding fluctuations around a threshold, based on a post from another fellow student, and friend, Vasilis.

I’ll make sure to post my thoughts on Python, and small scripts I’ve made, soon.

Thoughts in more than 140 characters

I read the interesting post Checking fluctuating variables using thresholds, the smart way from tzikis. Unfortunately, for some reason I can not post a comment there.

The problem is how to avoid the problem of fluctuations around “soft” thresholds. My solution simply defines a tolerance parameter. If we are “almost” at the same interval as before, we change nothing.

By the way, the bisect module is nice.

View original post