Last active
December 1, 2022 16:08
-
-
Save j40903272/08ce08b1e9119e859f980b02c6582a9c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import requests | |
import logging | |
headers = { | |
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36', | |
'Content-Type': 'application/json', | |
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0", | |
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", | |
"Accept-Encoding": "gzip, deflate, br", | |
"Accept-Language": "zh-TW,zh;q=0.8,en-US;q=0.5,en;q=0.3", | |
"Cache-Control": "no-cache", | |
"Connection": "keep-alive", | |
} | |
def configure_logging(): | |
logging_level = "INFO" | |
numeric_level = getattr(logging, logging_level, None) | |
logging.basicConfig( | |
level=numeric_level, | |
datefmt="%Y-%m-%d %H:%M:%S", | |
format="[%(asctime)s] [%(levelname)s] [%(module)s] #%(funcName)s @%(lineno)d: %(message)s", | |
) | |
logging.info(f"Logging level: {logging_level}") | |
def send_booking(): | |
response = requests.post( | |
"https://inline.app/api/reservations/booking", | |
headers=headers, | |
json={ | |
"language": "en", | |
"company": "-MzwvnhBNKKuZyFNn5wB:inline-live-2", | |
"branch": "-MzwvnyXDPmZ0y0IwAEo", | |
"groupSize": 2, | |
"kids": 0, | |
"gender": 1, | |
"purposes": [], | |
"diningPurposes": [], | |
"email": "bb04902103@gmail.com", | |
"name": "張睿宇", | |
"phone": "+886972169686", | |
"note": "", | |
"date": "2022-12-23", | |
"time": "19:00", | |
"numberOfKidChairs": 0, | |
"numberOfKidSets": 0, | |
"skipPhoneValidation": False, | |
"referer": "inline.app" | |
} | |
) | |
return response | |
def start_listen(): | |
logging.info("start listening") | |
failed = 0 | |
while True: | |
time.sleep(1) | |
try: | |
# check booking capacity | |
response = requests.get( | |
"https://inline.app/api/booking-capacitiesV3?companyId=-MzwvnhBNKKuZyFNn5wB%3Ainline-live-2&branchId=-MzwvnyXDPmZ0y0IwAEo", | |
headers=headers | |
) | |
if response.status_code != 200: | |
logging.error(response.text) | |
logging.error("") | |
continue | |
capcity = response.json() | |
if capcity['default'].get('2022-12-23', {}).get('status') == "open": | |
response = send_booking() | |
if response.status_code != 200: | |
logging.error(response.text) | |
failed += 1 | |
else: | |
logging.info(response.json()) | |
break | |
if failed >= 5: | |
# more than 5 times requests will be blocked | |
break | |
except Exception: | |
logging.exception("") | |
if __name__ == '__main__': | |
configure_logging() | |
start_listen() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment