How I get notifications on rentable rooms on

Posted by & filed under How I solved my problem, In English, Tech.

This is the second tool in my toolchain developed on my mission of programming myself out of my childhood room at my parents. has a search alert feature, where they claim that “A new room was just announced!”, but when you lookup the date that the room was announced, its always three days old. By new tool basically performs a search on the website for rooms in my desired area of interest with my desired bounds on the rent. A log is kept on the rooms already seen and the search result is then processed to check if any new room has appeared. When a new room appears I get a message box notification and a sound file starts playing until the message dialog is dismissed.
When I hit the “Yes” button of the dialog, I get the room shown in my Google Chrome webbrowser. The script performs a search every 60 seconds. Dependencies are the imported libraries as well as the Google Chrome browser and the mplayer CLI multi media player.

import requests
import json
import pickle
import time
import subprocess
import pygtk
import gtk
BROWSER_PATH = "google-chrome"
ALARM_SOUND = "Pleasurekraft - Carny.mp3"
def alarm(identifier, username):
	print "Found a new room! %s #%u" % (username, identifier)
	sound_process = subprocess.Popen([SOUNDPLAYER_PATH, ALARM_SOUND])
	dialog = gtk.MessageDialog(parent=None, flags=0, type=gtk.MESSAGE_QUESTION, buttons=gtk.BUTTONS_YES_NO, message_format=None)
	dialog.set_markup("Found a new room on findroommat.dknDo you wish to show it now?")
	answer =
	if answer == gtk.RESPONSE_YES:
		browser_process = subprocess.Popen([BROWSER_PATH, "" % username])
def fetch_profiles():
	headers = {
		'Content-Type': 'application/json',
	data = {
	r ='', data=json.dumps(data), headers=headers)
	response = json.loads(r.content)
	return_value = response["d"]["ReturnValue"]
	return json.loads(return_value)
if __name__ == '__main__':
	print 'New room alarm on'
	file_name = "ids.pickle"
	first_run = False
		with open(file_name) as f:
			visited_profile_ids = pickle.load(f)
	except IOError as e:
		visited_profile_ids = []
		first_run = True
	while True:
		profiles = fetch_profiles()
		print "Found %u profiles when searching." % profiles['Count']
		for profile in profiles['Profiles']:
			identifier = profile['UserIdInt']
			username = profile['Username']
			if identifier not in visited_profile_ids:
				if not first_run or True:
					alarm(identifier, username)
		with open(file_name, 'w') as f:
			pickle.dump(visited_profile_ids, f)

Leave a Reply