This is the second tool in my toolchain developed on my mission of programming myself out of my childhood room at my parents. Findroommate.dk 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 pygtk.require('2.0') import gtk BROWSER_PATH = "google-chrome" SOUNDPLAYER_PATH = "mplayer" ALARM_SOUND = "Pleasurekraft - Carny.mp3" SLEEP_DELAY = 60 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 = dialog.run() sound_process.terminate() if answer == gtk.RESPONSE_YES: browser_process = subprocess.Popen([BROWSER_PATH, "http://www.findroommate.dk/Profiler/%s" % username]) def fetch_profiles(): headers = { 'Content-Type': 'application/json', } data = { 'UserType':0, 'MapCenterBoundsLat':'55.67246738804332', 'MapCenterBoundsLng':'12.583579399999962', 'ViewPortLat':'55.77648968046662', 'ViewPortLng':'12.782019951757775', 'RentLow':'2000', 'RentHigh':'4000', 'RentalPeriodsArray':'1,2,3', 'SmokingMustBeAllowed':False, 'AnimalsMustBeAllowed':False, 'WifiMustBePresent':False, 'CableTvMustBePresent':False, 'WasherMustBePresent':False, 'DishWasherMustBePresent':False, 'IncludeWomen':True, 'IncludeMen':True, 'PersonIsSmoker':False, 'ExcludePersonsWithChildren':False, 'MustHavePicture':False, 'SortingTypeId':'adPlaced', 'SortingValue':'desc' } r = requests.post('http://www.findroommate.dk/API/Search/Search.asmx/GetSearchResults', 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 findroommate.dk' file_name = "ids.pickle" first_run = False try: 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: visited_profile_ids.append(identifier) if not first_run or True: alarm(identifier, username) with open(file_name, 'w') as f: pickle.dump(visited_profile_ids, f) time.sleep(SLEEP_DELAY) |