Skip to content

Instantly share code, notes, and snippets.

@BlackVoid
Last active August 29, 2015 14:04
Show Gist options
  • Save BlackVoid/4b73f2c050b3634eaa05 to your computer and use it in GitHub Desktop.
Save BlackVoid/4b73f2c050b3634eaa05 to your computer and use it in GitHub Desktop.
How to remove the luck factor from a luck based system.
# -*- coding: utf-8 -*-
import time
import json
import urllib2
import random
import subprocess
import datetime
from BeautifulSoup import BeautifulSoup
"""
https://marknad.studentbostader.se/widgets/?omraden=&egenskaper=SNABB&objektTyper=&actionId=&callback=jQuery17100253444043202945_1406813982377&widgets[]=koerochprenumerationer%40STD&widgets[]=objektfilter%40lagenheter&widgets[]=objektsortering%%40lagenheter&widgets[]=objektlista%%40lagenheter&widgets[]=pagineringgonew%%40lagenheter&widgets[]=pagineringlista%40lagenheter&widgets[]=pagineringgoold%40lagenheter&_=1406796622575
_ attribute from normal requests:
1406796622575
1406796904098
Unix time in seconds:
1406796966
_= unix timestamp ms
"""
curl = "https://marknad.studentbostader.se/widgets/?omraden=&egenskaper=%s&objektTyper=&actionId=&callback=&widgets[]=koerochprenumerationer%%40STD&widgets[]=objektfilter%%40lagenheter&widgets[]=objektsortering%%40lagenheter&widgets[]=objektlista%%40lagenheter&widgets[]=pagineringgonew%%40lagenheter&widgets[]=pagineringlista%%40lagenheter&widgets[]=pagineringgoold%%40lagenheter&_=%s"
def unix_time():
return str(round(time.time()*1000))
def alert():
for i in range(20):
subprocess.Popen(["paplay", "/usr/share/sounds/KDE-Im-Message-In.ogg"])
time.sleep(0.15)
def poll():
res = urllib2.urlopen(curl % ("SNABB", unix_time(),)).read()
html = json.loads(res[1:len(res)-2])[u'html'][u'objektlista@lagenheter']
soup = BeautifulSoup(html)
t = datetime.datetime.now()
if soup.find('div', {"class": "NoResult"}) is None:
print "[%s] Appartment found!!" % (t.strftime("%H:%M:%S"), )
alert()
else:
print "[%s] Nope" % (t.strftime("%H:%M:%S"), )
while True:
poll()
time.sleep(random.randrange(20, 30))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment