-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
120 lines (97 loc) · 3.23 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import os
from dotenv import load_dotenv
from kavenegar import *
import requests
from bs4 import BeautifulSoup
import sys
import urllib3
import time
urllib3.disable_warnings()
load_dotenv()
# the url contains type and cities
# available_to_book=179 (directly book)
cities = os.getenv('CITIES').split(",")
normal_url = "https://holland2stay.com/residences.html"
student_only_url = "https://holland2stay.com/residences/studentonly.html"
student_only = True if os.getenv('STUDENT_ONLY') == "YES" else False
url = f"{student_only_url if os.getenv('STUDENT_ONLY') == 'YES' else normal_url}?available_to_book=179&city=" + \
"%2C".join(cities)
receptors = os.getenv('RECEPTORS').split(",")
api = KavenegarAPI(os.getenv('KAVE_NEGAR_API'))
HEADERS = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/111.0",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
"Accept-Language": "en-US,en;q=0.5",
"Accept-Encoding": "gzip, deflate, br",
"Connection": "keep-alive",
"Upgrade-Insecure-Requests": "1",
"Sec-Fetch-Dest": "document",
"Sec-Fetch-Mode": "navigate",
"Sec-Fetch-Site": "same-origin",
"Sec-Fetch-User": "?1"
}
def sendMessage(code):
for receptor in receptors:
params = {
'template': 'code',
'token': code,
'receptor': receptor,
'token2': '',
'token3': '',
'type': 'sms'
}
api.verify_lookup(params)
def availableOptionNotify():
sendMessage("AVAILABLE_VP")
for receptor in receptors:
params = {
'template': 'call',
'token': "1234",
'receptor': receptor,
'type': 'call'
}
api.verify_lookup(params)
def checkDirectTag():
r = requests.session()
print("[*] Checking")
try:
res = r.get(url, headers=HEADERS, verify=False)
except Exception as e:
print("[error]: {}".format(e))
sys.exit()
soup = BeautifulSoup(res.content, features="html.parser")
# directTag = soup.find_all('span', {'class': 'direct-tag'})
priceTag = soup.find_all('div', {'class': 'price'})
# itemTag = soup.find_all('div', {'class': 'regi-item'})
if (len(priceTag) > 0):
try:
i = 0
hasOption = False
print("[+] Found something")
while (i <= len(priceTag) - 1):
price = int(
''.join(filter(str.isdigit, priceTag[i].text.split(".")[0])))
i = i+1
if (price < int(os.getenv('BASIC_RENT'))):
i = len(priceTag)
hasOption = True
if (hasOption):
print("[+] Perfect, notify availibility...")
availableOptionNotify()
else:
print("[-] Not suitable!")
except Exception as e:
print("[error]: {}".format(e))
sys.exit()
else:
print("[-] Not found")
counter = 180
while (True):
checkDirectTag()
print("---- | ---- =>", counter)
print("URL -> ", url)
counter = counter + 1
if (counter >= 180):
sendMessage("Alive")
counter = 0
time.sleep(200)