-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmovnotif.py
87 lines (67 loc) · 2.83 KB
/
movnotif.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
import time
import json
import requests
from selenium import webdriver
from selenium.webdriver.common.by import By
# Pushover credentials (get from your pushover account)
PUSHOVER_USER_KEY = '' #User key
PUSHOVER_APP_TOKEN = '' #APP token
MOVIE_URL = "" #movie link
driver = webdriver.Safari()
def send_pushover_notification(message):
"""Send mobile notification using Pushover."""
payload = {
"token": PUSHOVER_APP_TOKEN,
"user": PUSHOVER_USER_KEY,
"message": message
}
response = requests.post("https://api.pushover.net/1/messages.json", data=payload)
if response.status_code == 200:
print("Notification sent successfully!")
else:
print("Failed to send notification:", response.text)
def get_current_showtimes():
"""Scrape current theater and showtime listings from BookMyShow."""
driver.get(MOVIE_URL)
time.sleep(5) # Wait for the page to load fully
# Dismiss pop-ups (assuming 'Not Now' button has ID 'wzrk-cancel')
try:
not_now_button = driver.find_element(By.ID, 'wzrk-cancel')
not_now_button.click()
except:
pass # Ignore if the button is not found
theater_elements = driver.find_elements(By.CSS_SELECTOR, 'a.__venue-name')
theaters = [theater.text for theater in theater_elements]
# Scrape showtimes
showtime_elements = driver.find_elements(By.CSS_SELECTOR, 'div.__text')
showtimes = [showtime.text.strip() for showtime in showtime_elements]
theater_showtimes = {}
for idx, theater in enumerate(theaters):
showtimes = []
try:
showtime_elements = showtime_elements[idx].find_elements(By.CSS_SELECTOR, 'div.__text')
for showtime in showtime_elements:
time_text = showtime.text.strip()
# A simple check to see if the text looks like a time (e.g., "07:30 AM")
if any(am_pm in time_text for am_pm in ["AM", "PM"]):
showtimes.append(time_text)
except IndexError:
pass # If there's an indexing error, just skip the theater
theater_showtimes[theater] = showtimes
return theater_showtimes
def main():
"""Main loop to check for new listings and send notifications."""
last_known_showtimes = {}
while True:
current_showtimes = get_current_showtimes()
if current_showtimes != last_known_showtimes:
# Send notification of new showtimes
message = f"New showtimes added: {json.dumps(current_showtimes, indent=2)}"
send_pushover_notification(message)
last_known_showtimes = current_showtimes
else:
print("No new updates.")
# Wait for () minutes before checking again
time.sleep() # Give Time in Secs as per the need
if __name__ == "__main__":
main()