Skip to content

Commit

Permalink
Also send calendar invites.
Browse files Browse the repository at this point in the history
  • Loading branch information
mlondschien committed Aug 28, 2023
1 parent f15061a commit 95023ef
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
30 changes: 28 additions & 2 deletions crispybeefbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,30 @@

for date, info in response["Clausiusbar"]["weekdays"].items():
for mealtype, meal in info["mealTypes"].items():
if mealtype == "dinner":
continue
for menu in meal["menus"]:
if "crispy beef" in " ".join(menu["description"]).lower():
crispy_beefs += [(info["label"], date)]

if len(crispy_beefs) == 0:
sys.exit()

subject = f"Crispy Beef on {' and '.join(c[0] for c in crispy_beefs)}"
def create_event(creds, date, attendees):
service = build("calendar", "v3", credentials=creds)
start = f"{date}T12:00:00"
end = f"{date}T13:00:00"

event = {
"summary": "Crispy Beef",
"location": "Clausiusbar",
"description": "Crispy Beef",
"start": {"dateTime": start, "timeZone": "Europe/Zurich"},
"end": {"dateTime": end, "timeZone": "Europe/Zurich"},
"attendees": [{"email": attendee} for attendee in attendees]
}

return service.events().insert(calendarId="primary", body=event).execute()


def send_message(creds, subject, content, to, sender="crispybeefbot"):
Expand Down Expand Up @@ -56,8 +72,18 @@ def send_message(creds, subject, content, to, sender="crispybeefbot"):
recipients = r.read().split("\n")

errors = []
events = []

for crispy_beef in crispy_beefs:
try:
res = create_event(creds, crispy_beef[1], recipients)
events.append(f"{crispy_beef[0]}: {res['htmlLink']}")
except Exception as e:
errors.append(e)

subject = f"Crispy Beef on {' and '.join(c[0] for c in crispy_beefs)}"
for recipient in recipients:
error = send_message(creds, subject, "", recipient)
error = send_message(creds, subject, "\n".join(res), recipient)
if error is not None:
errors.append(error)

Expand Down
5 changes: 4 additions & 1 deletion setup_gmail_creds.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
from googleapiclient.errors import HttpError

# If modifying these scopes, delete the file token.json.
SCOPES = ['https://www.googleapis.com/auth/gmail.send']
SCOPES = [
"https://www.googleapis.com/auth/calendar",
'https://www.googleapis.com/auth/gmail.send'
]


def main():
Expand Down

0 comments on commit 95023ef

Please sign in to comment.