-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrsvp_bot.py
80 lines (66 loc) · 2.46 KB
/
rsvp_bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import os
import datetime
import json
import httplib2
from apiclient.discovery import build
from oauth2client.file import Storage
from oauth2client.client import flow_from_clientsecrets
from oauth2client.tools import run_flow
SCOPES = ['https://www.googleapis.com/auth/calendar.events']
CLIENT_SECRET_FILE = 'credentials.json'
TOKEN_FILE = 'token.json'
def print_banner():
print("=" * 50)
print(" AUTOMATED RSVP BOT".center(50))
print("=" * 50)
print(" Manage RSVPs Easily and Quickly".center(50))
print("=" * 50)
def authenticate_google():
storage = Storage(TOKEN_FILE)
credentials = storage.get()
if not credentials or credentials.invalid:
flow = flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES)
credentials = run_flow(flow, storage)
http = credentials.authorize(httplib2.Http())
service = build('calendar', 'v3', http=http)
return service
def get_upcoming_events(service):
now = datetime.datetime.utcnow().isoformat() + 'Z'
events_result = service.events().list(
calendarId='primary', timeMin=now,
maxResults=10, singleEvents=True,
orderBy='startTime').execute()
events = events_result.get('items', [])
return events
def auto_rsvp(service, events):
for event in events:
event_id = event['id']
summary = event.get('summary', 'No Title')
start = event['start'].get('dateTime', event['start'].get('date'))
print("[INFO] Event: {} at {}".format(summary, start))
decision = raw_input("RSVP (Accept/Tentative/Decline)? [A/T/D]: ").strip().lower()
if decision == 'a':
response = 'accepted'
elif decision == 't':
response = 'tentative'
else:
response = 'declined'
service.events().update(
calendarId='primary',
eventId=event_id,
body={"status": response}
).execute()
print("[SUCCESS] RSVP '{}' untuk {}".format(response, summary))
def main():
print_banner()
print("[INFO] Autentikasi Google Calendar...")
service = authenticate_google()
print("[INFO] Mendapatkan acara mendatang...")
events = get_upcoming_events(service)
if not events:
print("[ERROR] Tidak ada acara yang ditemukan.")
return
print("[INFO] Mulai RSVP otomatis...")
auto_rsvp(service, events)
if __name__ == '__main__':
main()