-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
executable file
·53 lines (40 loc) · 1.3 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
#!/usr/bin/env python3
import os
import sys
import time
import argparse
import datetime
import requests
import subprocess
from lxml import html
from twilio.rest import Client
def notify(title, text):
os.system("""
osascript -e 'display notification "{}" with title "{}"'
""".format(text, title))
parser = argparse.ArgumentParser(
description="Poll a given Resident Advisor URL and notify if resale tickets are available.",
)
parser.add_argument('url', help="Resident Advisor event page URL")
args = parser.parse_args()
TWILIO_SID = 'TWILIO_SID'
TWILIO_TOKEN = 'TWILIO_TOKEN'
FROM_PHONE_NUMBER = '+44'
PHONE_NUMBER = '+44'
client = Client(TWILIO_SID, TWILIO_TOKEN)
text_sent = False
while True:
response = requests.get(args.url)
root = html.document_fromstring(response.content)
tickets_with_resale = root.xpath('//li[@id="tickets"]/ul/li[@data-resale-tickets-available > 0]')
if len(tickets_with_resale) > 0:
print("%s: Tickets available" % (str(datetime.datetime.now())))
notify("Tickets available", "")
if not text_sent:
message = client.messages.create(
to=PHONE_NUMBER,
from_=FROM_PHONE_NUMBER,
body="Tickets available!",
)
text_sent = True
time.sleep(10)