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 datetime
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from punkow.scraper import BookingService, BASE_URL
|
from punkow.scraper import BookingData, BookingService, BASE_URL
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
@ -33,9 +33,11 @@ if __name__ == "__main__":
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
logger.info("Try to get an appointment at %s", datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
|
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)
|
svc = BookingService(url, debug=False)
|
||||||
if svc.book(name=args.name, email=args.email):
|
for booked in svc.book([data]):
|
||||||
break
|
if data == booked:
|
||||||
|
break
|
||||||
time.sleep(max(30, args.interval))
|
time.sleep(max(30, args.interval))
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
logger.info("Got keyboard interrupt - stopping.")
|
logger.info("Got keyboard interrupt - stopping.")
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import contextlib
|
import contextlib
|
||||||
import logging
|
import logging
|
||||||
|
import typing
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
@ -20,6 +21,11 @@ def print_url(r, *args, **kwargs):
|
||||||
logger.debug("response headers: %s", r.headers)
|
logger.debug("response headers: %s", r.headers)
|
||||||
|
|
||||||
|
|
||||||
|
class BookingData(typing.NamedTuple):
|
||||||
|
name: str
|
||||||
|
email: str
|
||||||
|
|
||||||
|
|
||||||
class BookingService(object):
|
class BookingService(object):
|
||||||
def __init__(self, start_url, debug=True):
|
def __init__(self, start_url, debug=True):
|
||||||
self.session = None
|
self.session = None
|
||||||
|
|
@ -172,13 +178,19 @@ class BookingService(object):
|
||||||
|
|
||||||
return True
|
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)
|
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):
|
for day_url in self._iter_bookable_day_urls(self.start_url):
|
||||||
with self._local_referrer():
|
with self._local_referrer():
|
||||||
for slot_url in self._iter_bookable_times(day_url):
|
for slot_url in self._iter_bookable_times(day_url):
|
||||||
if self._book_appointment(slot_url, name, email):
|
if self._book_appointment(slot_url, cur_data.name, cur_data.email):
|
||||||
return True
|
cur_data = next(data_iter)
|
||||||
return False
|
if cur_data is None:
|
||||||
|
return
|
||||||
|
return
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue