53 lines
1.6 KiB
Python
53 lines
1.6 KiB
Python
import os
|
|
import sys
|
|
import time
|
|
|
|
import pause
|
|
import requests
|
|
|
|
from application import Application
|
|
|
|
import sqlite3
|
|
from selenium import webdriver
|
|
|
|
from workingHours import is_working_hours, next_working_hour
|
|
|
|
refresh_rate_minutes = 5
|
|
api_url = 'https://hass.jennett-wheeler.co.uk/api/webhook/-Qx6jHsGLHwbBlJpLek5Nj8qS'
|
|
|
|
if __name__ == '__main__':
|
|
try:
|
|
with sqlite3.connect("./database.db") as connection:
|
|
cursor = connection.cursor()
|
|
|
|
options = webdriver.ChromeOptions()
|
|
options.add_argument('--headless')
|
|
|
|
application = Application(cursor, "25/00605/FUL")
|
|
num_documents = 18
|
|
|
|
while True:
|
|
if is_working_hours():
|
|
with webdriver.Chrome(options=options) as browser:
|
|
application.scrape_portal(browser, force=True, count_documents=True)
|
|
|
|
if num_documents < application.num_documents:
|
|
num_new_documents = application.num_documents - num_documents
|
|
num_documents = application.num_documents
|
|
requests.post(api_url)
|
|
print(f"New documents! {num_new_documents}")
|
|
|
|
pause.minutes(refresh_rate_minutes)
|
|
|
|
else:
|
|
next_start = next_working_hour()
|
|
print(f"Pausing until: {next_start}")
|
|
pause.until(next_start)
|
|
|
|
except KeyboardInterrupt:
|
|
print('Interrupted')
|
|
try:
|
|
sys.exit(130)
|
|
except SystemExit:
|
|
os._exit(130)
|