add log support
This commit is contained in:
+17
-11
@@ -1,19 +1,18 @@
|
||||
import time
|
||||
|
||||
import playwright
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
from db.DbManager import DataManager
|
||||
from pojo.ReserveResultPojo import ReserveResultPojo
|
||||
|
||||
SORRY_SENTENCE = "we are extremely sorry that we were not able to fulfill your request this time"
|
||||
|
||||
|
||||
# check result with playright
|
||||
def check_result_page(url):
|
||||
def check_result_page(url) -> bool:
|
||||
with sync_playwright() as p:
|
||||
run(p, url)
|
||||
return run(p, url)
|
||||
|
||||
|
||||
def run(playwright, url):
|
||||
def run(playwright, url) -> bool:
|
||||
browser = playwright.webkit.launch(headless=False)
|
||||
page = browser.new_page(
|
||||
user_agent="Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.87 Mobile Safari/537.36")
|
||||
@@ -21,15 +20,22 @@ def run(playwright, url):
|
||||
print(url_to_check)
|
||||
page.goto(url_to_check)
|
||||
print(page.title())
|
||||
print(page.content())
|
||||
content = page.content()
|
||||
browser.close()
|
||||
if SORRY_SENTENCE in content:
|
||||
print("refused")
|
||||
return False
|
||||
else:
|
||||
print("accepted")
|
||||
return True
|
||||
|
||||
|
||||
# need to start at 21h00
|
||||
if __name__ == '__main__':
|
||||
# get the list
|
||||
db_manager = DataManager()
|
||||
for appointment in db_manager.get_all_successful_items():
|
||||
result = ReserveResultPojo.from_firestore_dict(appointment.to_dict())
|
||||
check_result_page(result.url)
|
||||
print(result)
|
||||
collection = db_manager.get_all_successful_items()
|
||||
for appointment in collection.stream():
|
||||
reserve_pojo = ReserveResultPojo.from_firestore_dict(appointment.to_dict())
|
||||
result = check_result_page(reserve_pojo.url)
|
||||
collection.document(reserve_pojo.id).update({u'accepted': result})
|
||||
|
||||
Reference in New Issue
Block a user