Compare commits
2 commits
526c3e3d67
...
0b1683933f
Author | SHA1 | Date | |
---|---|---|---|
0b1683933f | |||
5ba466b7aa |
2 changed files with 27 additions and 2 deletions
|
@ -41,6 +41,7 @@ class MatrixBot:
|
||||||
logger.debug(f"left room {room_id} since all other users left")
|
logger.debug(f"left room {room_id} since all other users left")
|
||||||
|
|
||||||
logger.info("initial sync done, ready for work")
|
logger.info("initial sync done, ready for work")
|
||||||
|
await self._send_greeting()
|
||||||
|
|
||||||
async def _on_invite(self, room, event):
|
async def _on_invite(self, room, event):
|
||||||
logger.info(f"invited by {event.sender} to {room.room_id}")
|
logger.info(f"invited by {event.sender} to {room.room_id}")
|
||||||
|
@ -93,6 +94,20 @@ class MatrixBot:
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
async def _send_greeting(self):
|
||||||
|
"""Send a greeting to make sure the bot is working."""
|
||||||
|
assert self.client
|
||||||
|
|
||||||
|
for room_id in self.client.rooms:
|
||||||
|
await self.client.room_send(
|
||||||
|
room_id=room_id,
|
||||||
|
message_type="m.room.message",
|
||||||
|
content={
|
||||||
|
"msgtype": "m.text",
|
||||||
|
"body": "Whaaaaaaa, good monning. I'll check slots for you.",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
async def run(self):
|
async def run(self):
|
||||||
"""Start the bot."""
|
"""Start the bot."""
|
||||||
logger.info(f"Connecting to {self.homeserver}")
|
logger.info(f"Connecting to {self.homeserver}")
|
||||||
|
|
|
@ -37,6 +37,8 @@ class TLSAppointmentBot:
|
||||||
while not self.matrix_bot.initial_sync_done:
|
while not self.matrix_bot.initial_sync_done:
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
|
tries = 0
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
logger.info("checking for appointment slots")
|
logger.info("checking for appointment slots")
|
||||||
|
@ -57,10 +59,18 @@ class TLSAppointmentBot:
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
logging.error(traceback.format_exc().strip())
|
logging.error(traceback.format_exc().strip())
|
||||||
await self.matrix_bot.send_warning()
|
if tries > 3:
|
||||||
|
await self.matrix_bot.send_warning()
|
||||||
|
break
|
||||||
|
|
||||||
|
tries += 1
|
||||||
|
continue
|
||||||
|
|
||||||
|
tries = 0
|
||||||
await asyncio.sleep(2 * 60)
|
await asyncio.sleep(2 * 60)
|
||||||
|
|
||||||
|
self.quit()
|
||||||
|
|
||||||
def _is_logged_in(self) -> bool:
|
def _is_logged_in(self) -> bool:
|
||||||
self.driver.get(f"{self.config.tls_instance}/BJS/index.php")
|
self.driver.get(f"{self.config.tls_instance}/BJS/index.php")
|
||||||
button = wait.WebDriverWait(self.driver, 10).until(
|
button = wait.WebDriverWait(self.driver, 10).until(
|
||||||
|
@ -87,7 +97,7 @@ class TLSAppointmentBot:
|
||||||
|
|
||||||
# Make sure we're on the page, and that we can see the
|
# Make sure we're on the page, and that we can see the
|
||||||
# appointment table
|
# appointment table
|
||||||
wait.WebDriverWait(self.driver, 10).until(
|
wait.WebDriverWait(self.driver, 20).until(
|
||||||
ec.visibility_of_element_located((By.XPATH, "//tr[@class='amend']"))
|
ec.visibility_of_element_located((By.XPATH, "//tr[@class='amend']"))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue