mirror of https://github.com/janLo/punkow
Allow to make multiple bookings in ine wun
This commit is contained in:
parent
26037bda55
commit
771102bcc2
|
|
@ -3,7 +3,7 @@ import logging
|
|||
import datetime
|
||||
import time
|
||||
|
||||
from punkow.scraper import BookingService, BASE_URL
|
||||
from punkow.scraper import BookingData, BookingService, BASE_URL
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
|
@ -33,9 +33,11 @@ if __name__ == "__main__":
|
|||
while True:
|
||||
try:
|
||||
logger.info("Try to get an appointment at %s", datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
|
||||
data = BookingData(name=args.name, email=args.email)
|
||||
svc = BookingService(url, debug=False)
|
||||
if svc.book(name=args.name, email=args.email):
|
||||
break
|
||||
for booked in svc.book([data]):
|
||||
if data == booked:
|
||||
break
|
||||
time.sleep(max(30, args.interval))
|
||||
except KeyboardInterrupt:
|
||||
logger.info("Got keyboard interrupt - stopping.")
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import contextlib
|
||||
import logging
|
||||
import typing
|
||||
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
|
|
@ -20,6 +21,11 @@ def print_url(r, *args, **kwargs):
|
|||
logger.debug("response headers: %s", r.headers)
|
||||
|
||||
|
||||
class BookingData(typing.NamedTuple):
|
||||
name: str
|
||||
email: str
|
||||
|
||||
|
||||
class BookingService(object):
|
||||
def __init__(self, start_url, debug=True):
|
||||
self.session = None
|
||||
|
|
@ -172,13 +178,19 @@ class BookingService(object):
|
|||
|
||||
return True
|
||||
|
||||
def book(self, name, email):
|
||||
def book(self, data: typing.List[BookingData]):
|
||||
logging.info("Look for appontments at %s", BASE_URL + self.start_url)
|
||||
|
||||
data_iter = iter(data)
|
||||
cur_data = next(data_iter, None)
|
||||
if cur_data is None:
|
||||
return
|
||||
|
||||
for day_url in self._iter_bookable_day_urls(self.start_url):
|
||||
with self._local_referrer():
|
||||
for slot_url in self._iter_bookable_times(day_url):
|
||||
if self._book_appointment(slot_url, name, email):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
if self._book_appointment(slot_url, cur_data.name, cur_data.email):
|
||||
cur_data = next(data_iter)
|
||||
if cur_data is None:
|
||||
return
|
||||
return
|
||||
|
|
|
|||
Loading…
Reference in New Issue