New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Telegram Notification Functionality Added #2
Conversation
This looks great! At the moment, the project is waiting for the city's approval, so I will wait before putting more effort into it. Here are a few notes about the changes:
|
One more thing: there's no need to notify someone when nothing is found. The function only needs to be called if something is new. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, minor comments 👍
|
||
Now it is possible to get notified via telegram regarding the appointment dates along with the appointment url. Just click on it and book it right away. | ||
|
||
- Go to config directory and rename the config.bak.json to config.json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Go to config directory and rename the config.bak.json to config.json | |
- Go to config directory and rename the `config.example.json` to `config.json` |
This might provide more clarity about the file vs bak implying a backup
|
||
Now it is possible to get notified via telegram regarding the appointment dates along with the appointment url. Just click on it and book it right away. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now it is possible to get notified via telegram regarding the appointment dates along with the appointment url. Just click on it and book it right away. | |
Now it is possible to get notified via Telegram regarding the appointment dates along with the appointment URL. Just click on it and book it right away. |
|
||
- Go to config directory and rename the config.bak.json to config.json | ||
|
||
- Add the telegram api key and the chat id in config.json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Add the telegram api key and the chat id in config.json | |
- Add the Telegram API key and the chat ID in `config.json` |
It might be worth describing how to obtain these too - e.g. https://github.com/inverse/termin#telegram
|
||
async def main(): | ||
global last_message | ||
async with websockets.serve(on_connect, port=80): | ||
while True: | ||
last_message = look_for_appointments() | ||
telegram_notify(last_message) # Telegram Notification |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
telegram_notify(last_message) # Telegram Notification | |
telegram_notify(last_message) |
Comment adds little value
# Loads the Json results | ||
available_dates = [] | ||
available_datestring = [] | ||
if not last_message['appointmentDates']: # To check if its an empty array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @nicbou comment - we shouldn't notify on no appointments
@@ -11,7 +11,7 @@ | |||
import requests | |||
import time | |||
import websockets | |||
|
|||
import telegram |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be added to requirements.txt
?
available_dates_str = ','.join(available_dates) | ||
available_datestring.append(dates) | ||
notify_str= "The next appointment for flat registration is available on the following dates "+available_dates_str+". Please use this URL to book the appointment faster: "+appointments_url | ||
notify.sendMessage(chat_id=chat_id, text=notify_str) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What library are you using here? perhaps we could format the message with Markdown for better readability.
# Telegram Notifcation Added by Siva Rajendran | ||
|
||
def telegram_notify(message): | ||
with open('./config/config.json', 'r') as config_file: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to guard against non-existing config files/invalid config and only continue when notify
Bot created.
Could extract the init to another function for better readability.
Since the tool now has permission to exist, a Telegram bot is a great idea. But wouldn't it be more sensible to create a separate Telegram bot that listens to the websocket server? This lets people use the websocket server for other purposes, without running the Telegram bot. |
Description
The telegram notification functionality is added to the existing application. Therefore, one can setup his telegram bot and receive the message every 30 seconds regarding the status. If the appointment dates are available, then the person will receive the message along with the available dates and appointment URL.
Screenshot
Output
The next appointment for flat registration is available on the following dates 29-Mar-2022 Please use this URL to book the appointment faster: (https://service.berlin.de/terminvereinbarung/termin/tag.php?termin=1&anliegen[]=120686&dienstleisterlist=122210,122217,327316,122219,327312,122227,327314,122231,122243,327348,122252,329742,122260,329745,122262,329748,122254,329751,122271,327278,122273,327274,122277,327276,330436,122280,327294,122282,327290,122284,327292,327539,122291,327270,122285,327266,122286,327264,122296,327268,150230,329760,122301,327282,122297,327286,122294,327284,122312,329763,122314,329775,122304,327330,122311,327334,122309,327332,122281,327352,122279,329772,122276,327324,122274,327326,122267,329766,122246,327318,122251,327320,122257,327322,122208,327298,122226,327300&herkunft=http%3A%2F%2Fservice.berlin.de%2Fdienstleistung%2F120686%2F
)