Skip to content

Instantly share code, notes, and snippets.

@orcunbaslak
Created February 21, 2017 20:40
Show Gist options
  • Save orcunbaslak/d5b78254549c76d0c3ddeb55e58338f7 to your computer and use it in GitHub Desktop.
Save orcunbaslak/d5b78254549c76d0c3ddeb55e58338f7 to your computer and use it in GitHub Desktop.
St. Moritz Boş Oda Gözlemcisi
# -*- coding: utf-8 -*-
# StMoritz Booking Gözlemcisi
# Author : Orçun Başlak
# E-mail: orcunbaslak [ @ ] gmail [ . ] com
# URL: http://orcun.baslak.com
import urllib.request
import time
import sys
import os
import smtplib
from email.mime.text import MIMEText
from email.header import Header
import Config
keyword = "statusFree"
title = u"Gözlemci:"
mailto = "orcunbaslak@gmail.com"
# You have to enable "Less Secure" Gmail logins for smtplib to work.
GMAIL_LOGIN = Config.GMAIL_LOGIN
GMAIL_PASSWORD = Config.GMAIL_PASSWORD
url = "http://www.booking.com/hotel/ch/kempinski-residences.tr.html?label=gen173nr-1FCAEoggJCAlhYSDNiBW" \
"5vcmVmaOQBiAEBmAEouAEHyAEM2AEB6AEB-AELqAID;sid=48f7b669ee2fac56ecd0c4f4bdbe36af;checkin=2017-02-" \
"11;checkout=2017-02-18;ucfs=1;highlighted_blocks=69212001_89209993_0_33_0;all_sr_blocks=69212001" \
"_89209993_0_33_0;room1=A,A;hpos=1;dest_type=city;dest_id=-2554009;srfid=20cd88dbab800b3a14acdac1" \
"738671778acd4a64X1;highlight_room="
waittime = 30 * 60
proxy_info = {
'user': '',
'pass': '',
'host': "",
'port': 8080 # or 8080 or whatever
}
# build a new opener that uses a proxy requiring authorization
proxy_support = urllib.request.ProxyHandler({'http': "http://%(user)s:%(pass)s@%(host)s:%(port)d" % proxy_info})
if proxy_info['host'] != "":
opener = urllib.request.build_opener(proxy_support)
else:
opener = urllib.request.build_opener()
# install it
urllib.request.install_opener(opener)
def send_email(subject, message, from_addr=GMAIL_LOGIN, to_addr=mailto):
msg = MIMEText(message, 'plain', 'utf-8')
msg['Subject'] = Header(subject,'utf-8')
msg['From'] = from_addr
msg['To'] = to_addr
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login(GMAIL_LOGIN, GMAIL_PASSWORD)
server.sendmail(from_addr, to_addr, msg.as_string())
server.close()
def sonuclar():
global title
try:
f = opener.open(url)
except:
print("[+] Hata: Internet'e bağlı olduğunuzu ve/veya proxy ayarlarınızın doğru olduğunu kontrol edin!")
sys.exit(1)
response = f.read()
if response.count(keyword.encode(encoding='utf-8')) > 1:
title = title + u" Boş Oda Bulundu"
msg = title + u"\n" + u"\nRezervasyon Adresi: " + url
print(title)
try:
send_email(title, msg)
except:
print("[+] Hata: E-posta bilgilerinizin doğru olduğunu kontrol edin!")
sys.exit(1)
sys.exit(1)
if __name__ == '__main__':
try:
while (1):
if sys.platform == 'linux-i386' or sys.platform == 'linux2':
os.system("clear")
elif sys.platform == 'win32':
os.system("cls")
else:
os.system("clear")
print "================================================================"
print u" St. Moritz Kempinski Boş Oda Gözlemcisi"
print "================================================================"
sonuclar()
print title + u" Hiçbir oda henüz boşalmadı, 30 dakika sonra tekrar kontrol edilecektir..."
time.sleep(waittime)
except KeyboardInterrupt:
print "Eyw..."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment