Initial commit

This commit is contained in:
Edward Betts 2024-10-18 08:52:41 +01:00
commit 39b2fa24a6
2 changed files with 111 additions and 0 deletions

49
README.md Normal file
View file

@ -0,0 +1,49 @@
# OSM Paris Event Watcher
This Python script periodically checks the OpenStreetMap Calendar API for upcoming events in Paris, particularly focused on hack weekends. If it finds any events, it sends an email notification with the event details.
## Features
- Fetches event data from the OSM Calendar API for events located in France.
- Filters for events that are specifically in Paris.
- Sends an email notification for each event found in Paris.
## Requirements
- Python 3.8 or later.
- `requests` library.
To install the required Python library, run:
```bash
pip install requests
```
## Usage
To run the script, simply execute:
```bash
python3 check.py
```
Make sure to run it in an environment where it has network access to both the OSM Calendar API and your SMTP server.
## Configuration
You will need to configure the following variables within the script:
- `MAIL_FROM`: The email address to send from.
- `MAIL_TO`: The recipient email address.
- `SMTP_HOST`: The hostname of the SMTP server you are using to send emails.
These are currently set to default values and will need to be updated to reflect your actual email setup.
## Contact
For any queries or further customization, please contact:
Edward Betts <edward@4angle.com>
## License
This project is licensed under the MIT License.

62
check.py Executable file
View file

@ -0,0 +1,62 @@
#!/usr/bin/python3
"""Watch https://osmcal.org/ for another Paris OSM hack weekend."""
import email.message
import email.utils
import smtplib
import sys
import requests
MAIL_FROM = "edward@4angle.com"
MAIL_TO = "edward@4angle.com"
SMTP_HOST = "4angle.com"
URL = "https://osmcal.org/api/v2/events/?in=France"
def send_mail(subject: str, body: str) -> None:
"""Send an e-mail."""
msg = email.message.EmailMessage()
msg["Subject"] = subject
msg["To"] = f"Edward Betts <{MAIL_TO}>"
msg["From"] = f"OSM Calendar alert <{MAIL_FROM}>"
msg["Date"] = email.utils.formatdate()
msg["Message-ID"] = email.utils.make_msgid()
msg.set_content(body)
s = smtplib.SMTP(SMTP_HOST)
s.sendmail(MAIL_FROM, [MAIL_TO], msg.as_string())
s.quit()
def check_for_paris_events() -> None:
"""Check for upcoming OSM events in Paris and send an email if found."""
r = requests.get(URL)
events = r.json()
paris_events = [
event for event in events if "paris" in event["location"]["detailed"].lower()
]
if not paris_events:
if sys.stdin.isatty():
print(f"{len(events)} events found, none in Paris.")
return
subject = "Upcoming Paris OSM Hack Weekend Found!"
count = len(paris_events)
body = f"Found {count} {'event' if count == 1 else 'events'} in Paris:\n\n"
for event in paris_events:
body += (
f"{event['name']} - {event['url']}\n"
+ f"Date: {event['date']['human']}\n"
+ f"Location: {event['location']['detailed']}\n\n"
)
send_mail(subject, body)
if __name__ == "__main__":
check_for_paris_events()