From bd1db29d8586d7429480b480d6de30e60a47992c Mon Sep 17 00:00:00 2001 From: Rachit Agrawal <111473259+Rancho-rachit@users.noreply.github.com> Date: Wed, 17 Apr 2024 13:35:44 +0000 Subject: [PATCH 1/5] ADD: Create Scheduled events on Discord_Server and Google_Calender --- event-discord-google_calender/README.md | 41 +++++++++++++ event-discord-google_calender/discord_.py | 50 +++++++++++++++ .../event_details.py | 17 ++++++ .../google_calender_.py | 61 +++++++++++++++++++ event-discord-google_calender/main.py | 12 ++++ event-discord-google_calender/packages.txt | 4 ++ event-discord-google_calender/sample_env | 12 ++++ 7 files changed, 197 insertions(+) create mode 100644 event-discord-google_calender/README.md create mode 100644 event-discord-google_calender/discord_.py create mode 100644 event-discord-google_calender/event_details.py create mode 100644 event-discord-google_calender/google_calender_.py create mode 100644 event-discord-google_calender/main.py create mode 100644 event-discord-google_calender/packages.txt create mode 100644 event-discord-google_calender/sample_env diff --git a/event-discord-google_calender/README.md b/event-discord-google_calender/README.md new file mode 100644 index 0000000..6bdb68e --- /dev/null +++ b/event-discord-google_calender/README.md @@ -0,0 +1,41 @@ +# Automation to create events across channels (google calendar & discord) +#### by [Rancho-rachit](https://github.com/Rancho-rachit) + +--- + +## Description: + +This script creates events across - +1. [Google Calendar](https://developersindia.in/events-calendar/) +2. [Discord](https://discord.com/channels/669880381649977354/) + +--- + +### FIRST TIME SETUP + +1. Get Python3 `sudo apt-get install python3 && python3 --version` + +2. Install required packages `pip install -r packages.txt` + +3. Add respective tokens in the `.env` file + 2.1 Discord Bot token (Get it from [Discord Developers portal](https://discord.com/developers/applications/)) (bot must have MANAGE_EVENT & CREATE_EVENT permission) + 2.2 Guild ID (developersIndia => 1229786646468362260) + +3. Connect Google Calender through [Google cloud Console](https://console.cloud.google.com/) + 3.1 Create a Project on Google Cloud Console + 3.2 Search for Calender API and enable it + 3.3 Create Credentials -> OAuth Client ID -> Application type as Desktop + 3.4 Download the Json file + 3.5 Rename that JSON file as `credentials.json` and save it to the project directory. + +4. `python3 main.py` + +--- + +### NOTES- + +> - Google authenication is required for the first time. +> +> - A file `token.json` will be downloaded automatically, and no web login will be needed afterwards. + + \ No newline at end of file diff --git a/event-discord-google_calender/discord_.py b/event-discord-google_calender/discord_.py new file mode 100644 index 0000000..07ed13d --- /dev/null +++ b/event-discord-google_calender/discord_.py @@ -0,0 +1,50 @@ +from datetime import datetime, timedelta +import os +from dotenv import load_dotenv +import event_details +import discord +from discord.ext import commands + +load_dotenv() +bot_token = os.getenv('DISCORD_BOT_TOKEN') +guild_id = int(os.getenv('DISCORD_GUILD_ID')) + +bot = commands.Bot(command_prefix='!', intents=discord.Intents.all()) + +@bot.event +async def on_ready(): + + # Convert the date string to a datetime object + date_object = datetime.strptime(event_details.EVENT_DATE, "%Y-%m-%d") + + # Convert the time string to a datetime object + start_time_object = datetime.strptime(event_details.EVENT_START_TIME, "%H:%M") + end_time_object = datetime.strptime(event_details.EVENT_END_TIME, "%H:%M") + + # Combine the date and time objects + st = date_object.replace(hour=start_time_object.hour, minute=start_time_object.minute).astimezone() + et = date_object.replace(hour=end_time_object.hour, minute=end_time_object.minute).astimezone() + + gg = bot.get_guild(guild_id) + + try: + event = await gg.create_scheduled_event( + name=event_details.EVENT_NAME, + entity_type=discord.EntityType.external, + description=event_details.EVENT_DESCRIPTION, + start_time=st, + end_time=et, + location=event_details.EVENT_LOCATION, + privacy_level=discord.PrivacyLevel.guild_only, + ) + print("Discord Event: ", event.url) + + except Exception as e: + print(e) + + await bot.close() + +# Run the bot +bot.run(bot_token) + +# END \ No newline at end of file diff --git a/event-discord-google_calender/event_details.py b/event-discord-google_calender/event_details.py new file mode 100644 index 0000000..e8620c6 --- /dev/null +++ b/event-discord-google_calender/event_details.py @@ -0,0 +1,17 @@ +# To get the event details from the user + +def get_input(): + NAME = input("Event title: ") + DESCRIPTION = input("Event description: ") + LOCATION = input("Event location (red -> for developersindia subreddit): ") + if LOCATION == "red": + LOCATION = "https://www.reddit.com/r/developersindia/" + DATE = input("Enter the event date (yyyy-mm-dd): ") + START_TIME = input("Enter the event start time (hh:mm)- ") + END_TIME = input("Enter the event end time (hh:mm)- ") + + return NAME, DESCRIPTION, LOCATION, DATE, START_TIME, END_TIME + +EVENT_NAME, EVENT_DESCRIPTION, EVENT_LOCATION, EVENT_DATE, EVENT_START_TIME, EVENT_END_TIME = get_input() + +# END \ No newline at end of file diff --git a/event-discord-google_calender/google_calender_.py b/event-discord-google_calender/google_calender_.py new file mode 100644 index 0000000..d3b86b2 --- /dev/null +++ b/event-discord-google_calender/google_calender_.py @@ -0,0 +1,61 @@ +import os.path +import event_details as main + +from google.auth.transport.requests import Request +from google.oauth2.credentials import Credentials +from google_auth_oauthlib.flow import InstalledAppFlow +from googleapiclient.discovery import build + +SCOPES = ['https://www.googleapis.com/auth/calendar'] + +def create_event(name, description, location, date, start_time, end_time): + + creds = None + + # The file token.json stores the user's access and refresh tokens + if os.path.exists('token.json'): + creds = Credentials.from_authorized_user_file('token.json', SCOPES) + + # If there are no (valid) credentials available, let the user log in. + if not creds or not creds.valid: + if creds and creds.expired and creds.refresh_token: + creds.refresh(Request()) + else: + print("Login to your Google account. [THIS IS A ONE TIME PROCESS]") + flow = InstalledAppFlow.from_client_secrets_file( + 'credentials.json', SCOPES) + creds = flow.run_local_server(port=0) + # Save the credentials for the next run + with open('token.json', 'w') as token: + token.write(creds.to_json()) + + try : + service = build('calendar', 'v3', credentials=creds) + start = f"{date}T{start_time}:00" + end = f"{date}T{end_time}:00" + event = { + 'summary': name, + 'location': location, + 'description': description, + 'start': { + 'dateTime': start, + 'timeZone': 'Asia/Kolkata', + }, + 'end': { + 'dateTime': end, + 'timeZone': 'Asia/Kolkata', + }, + } + + event = service.events().insert(calendarId='primary', body=event).execute() + + print('Google Calender: %s' % (event.get('htmlLink'))) + return event + + except Exception as e: + print(e) + return None + +create_event(main.EVENT_NAME, main.EVENT_DESCRIPTION, main.EVENT_LOCATION, main.EVENT_DATE, main.EVENT_START_TIME, main.EVENT_END_TIME) + +# END \ No newline at end of file diff --git a/event-discord-google_calender/main.py b/event-discord-google_calender/main.py new file mode 100644 index 0000000..407a247 --- /dev/null +++ b/event-discord-google_calender/main.py @@ -0,0 +1,12 @@ +# SCRIPT + +# Execute event_details.py +import event_details + +# Execute discord_.py +import discord_ + +# Execute google_calender.py +import google_calender_ + +# END \ No newline at end of file diff --git a/event-discord-google_calender/packages.txt b/event-discord-google_calender/packages.txt new file mode 100644 index 0000000..7763c48 --- /dev/null +++ b/event-discord-google_calender/packages.txt @@ -0,0 +1,4 @@ +discord.py +google-api-python-client +google-auth-httplib2 +google-auth-oauthlib \ No newline at end of file diff --git a/event-discord-google_calender/sample_env b/event-discord-google_calender/sample_env new file mode 100644 index 0000000..372e763 --- /dev/null +++ b/event-discord-google_calender/sample_env @@ -0,0 +1,12 @@ +# This is the file contains the required tokens. + +# DISCORD BOT TOKEN +# MUST HAVE PERMISSIONS TO CREATE EVENTS & MANAGE EVENTS +# https://discord.com/developers/applications + +DISCORD_BOT_TOKEN = "TOKEN" + +# DISCORD SERVER ID (GUILD ID) +# developersIndia => 1229786646468362260 + +DISCORD_GUILD_ID = 1229786646468362260 From d554b6f1fba769e73d5338256b4db1fbc668beaf Mon Sep 17 00:00:00 2001 From: Rachit Agrawal <111473259+Rancho-rachit@users.noreply.github.com> Date: Thu, 18 Apr 2024 09:04:25 +0530 Subject: [PATCH 2/5] Beautify README.md - Better Indentation --- event-discord-google_calender/README.md | 30 +++++++++++++++---------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/event-discord-google_calender/README.md b/event-discord-google_calender/README.md index 6bdb68e..a1243a2 100644 --- a/event-discord-google_calender/README.md +++ b/event-discord-google_calender/README.md @@ -3,12 +3,11 @@ --- -## Description: +### Description: This script creates events across - 1. [Google Calendar](https://developersindia.in/events-calendar/) 2. [Discord](https://discord.com/channels/669880381649977354/) - --- ### FIRST TIME SETUP @@ -18,17 +17,24 @@ This script creates events across - 2. Install required packages `pip install -r packages.txt` 3. Add respective tokens in the `.env` file - 2.1 Discord Bot token (Get it from [Discord Developers portal](https://discord.com/developers/applications/)) (bot must have MANAGE_EVENT & CREATE_EVENT permission) - 2.2 Guild ID (developersIndia => 1229786646468362260) -3. Connect Google Calender through [Google cloud Console](https://console.cloud.google.com/) - 3.1 Create a Project on Google Cloud Console - 3.2 Search for Calender API and enable it - 3.3 Create Credentials -> OAuth Client ID -> Application type as Desktop - 3.4 Download the Json file - 3.5 Rename that JSON file as `credentials.json` and save it to the project directory. + 3.1 Discord Bot token (Get it from [Discord Developers portal](https://discord.com/developers/applications/)) (bot must have MANAGE_EVENT & CREATE_EVENT permission) -4. `python3 main.py` + 3.2 Guild ID (developersIndia => 1229786646468362260) + +4. Connect Google Calender through [Google cloud Console](https://console.cloud.google.com/) + + 4.1 Create a Project on Google Cloud Console + + 4.2 Search for Calender API and enable it + + 4.3 Create Credentials -> OAuth Client ID -> Application type as Desktop + + 4.4 Download the Json file + + 4.5 Rename that JSON file as `credentials.json` and save it to the project directory. + +5. `python3 main.py` --- @@ -38,4 +44,4 @@ This script creates events across - > > - A file `token.json` will be downloaded automatically, and no web login will be needed afterwards. - \ No newline at end of file + From 23819baea7d283e05780052f6278650e9ad617d3 Mon Sep 17 00:00:00 2001 From: Rachit Agrawal <111473259+Rancho-rachit@users.noreply.github.com> Date: Sun, 21 Apr 2024 15:39:22 +0000 Subject: [PATCH 3/5] FIX: Everything mentioned, except clubbing main.py and event_details.py --- .../README.md | 9 ++++++--- .../discord_.py | 0 .../event_details.py | 0 .../google_calender_.py | 7 ++++++- {event-discord-google_calender => event-manager}/main.py | 0 .../packages.txt => event-manager/requirements.txt | 0 .../sample_env | 9 +++++++++ 7 files changed, 21 insertions(+), 4 deletions(-) rename {event-discord-google_calender => event-manager}/README.md (68%) rename {event-discord-google_calender => event-manager}/discord_.py (100%) rename {event-discord-google_calender => event-manager}/event_details.py (100%) rename {event-discord-google_calender => event-manager}/google_calender_.py (92%) rename {event-discord-google_calender => event-manager}/main.py (100%) rename event-discord-google_calender/packages.txt => event-manager/requirements.txt (100%) rename {event-discord-google_calender => event-manager}/sample_env (53%) diff --git a/event-discord-google_calender/README.md b/event-manager/README.md similarity index 68% rename from event-discord-google_calender/README.md rename to event-manager/README.md index a1243a2..37c5c1c 100644 --- a/event-discord-google_calender/README.md +++ b/event-manager/README.md @@ -8,19 +8,22 @@ This script creates events across - 1. [Google Calendar](https://developersindia.in/events-calendar/) 2. [Discord](https://discord.com/channels/669880381649977354/) + --- ### FIRST TIME SETUP 1. Get Python3 `sudo apt-get install python3 && python3 --version` -2. Install required packages `pip install -r packages.txt` +2. Install required packages `pip install -r requirements.txt` 3. Add respective tokens in the `.env` file - 3.1 Discord Bot token (Get it from [Discord Developers portal](https://discord.com/developers/applications/)) (bot must have MANAGE_EVENT & CREATE_EVENT permission) + 3.1 Discord Bot token [`DISCORD_BOT_TOKEN`] (Get it from [Discord Developers portal](https://discord.com/developers/applications/)) (bot must have MANAGE_EVENT & CREATE_EVENT permission) - 3.2 Guild ID (developersIndia => 1229786646468362260) + 3.2 Guild ID [`DISCORD_GUILD_ID`] (developersIndia => `1229786646468362260`) + + 3.3 Calender Id ['GOOGLE_CALENDER_ID'] (developerIndia => `9f1337e4154910eb1bdb3bfac32b88f69546468b1281a6db58f50a909df5049f@group.calendar.google.com`) 4. Connect Google Calender through [Google cloud Console](https://console.cloud.google.com/) diff --git a/event-discord-google_calender/discord_.py b/event-manager/discord_.py similarity index 100% rename from event-discord-google_calender/discord_.py rename to event-manager/discord_.py diff --git a/event-discord-google_calender/event_details.py b/event-manager/event_details.py similarity index 100% rename from event-discord-google_calender/event_details.py rename to event-manager/event_details.py diff --git a/event-discord-google_calender/google_calender_.py b/event-manager/google_calender_.py similarity index 92% rename from event-discord-google_calender/google_calender_.py rename to event-manager/google_calender_.py index d3b86b2..e08787c 100644 --- a/event-discord-google_calender/google_calender_.py +++ b/event-manager/google_calender_.py @@ -1,11 +1,16 @@ import os.path import event_details as main +from dotenv import load_dotenv + from google.auth.transport.requests import Request from google.oauth2.credentials import Credentials from google_auth_oauthlib.flow import InstalledAppFlow from googleapiclient.discovery import build +load_dotenv() +calendar_id = os.getenv('GOOGLE_CALENDAR_ID') + SCOPES = ['https://www.googleapis.com/auth/calendar'] def create_event(name, description, location, date, start_time, end_time): @@ -47,7 +52,7 @@ def create_event(name, description, location, date, start_time, end_time): }, } - event = service.events().insert(calendarId='primary', body=event).execute() + event = service.events().insert(calendarId=calendar_id, body=event).execute() print('Google Calender: %s' % (event.get('htmlLink'))) return event diff --git a/event-discord-google_calender/main.py b/event-manager/main.py similarity index 100% rename from event-discord-google_calender/main.py rename to event-manager/main.py diff --git a/event-discord-google_calender/packages.txt b/event-manager/requirements.txt similarity index 100% rename from event-discord-google_calender/packages.txt rename to event-manager/requirements.txt diff --git a/event-discord-google_calender/sample_env b/event-manager/sample_env similarity index 53% rename from event-discord-google_calender/sample_env rename to event-manager/sample_env index 372e763..b5a95b6 100644 --- a/event-discord-google_calender/sample_env +++ b/event-manager/sample_env @@ -6,7 +6,16 @@ DISCORD_BOT_TOKEN = "TOKEN" +# ----------- + # DISCORD SERVER ID (GUILD ID) # developersIndia => 1229786646468362260 DISCORD_GUILD_ID = 1229786646468362260 + +# ----------- + +# CALANDER ID +# developersIndia => "9f1337e4154910eb1bdb3bfac32b88f69546468b1281a6db58f50a909df5049f@group.calendar.google.com" + +GOOGLE_CALENDAR_ID = "9f1337e4154910eb1bdb3bfac32b88f69546468b1281a6db58f50a909df5049f@group.calendar.google.com" From 425d7766f077bda0ce1610b26f3fcb794e393ded Mon Sep 17 00:00:00 2001 From: Rachit Agrawal <111473259+Rancho-rachit@users.noreply.github.com> Date: Sun, 21 Apr 2024 15:45:16 +0000 Subject: [PATCH 4/5] Beautify README.md --- event-manager/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/event-manager/README.md b/event-manager/README.md index 37c5c1c..fea751c 100644 --- a/event-manager/README.md +++ b/event-manager/README.md @@ -23,7 +23,7 @@ This script creates events across - 3.2 Guild ID [`DISCORD_GUILD_ID`] (developersIndia => `1229786646468362260`) - 3.3 Calender Id ['GOOGLE_CALENDER_ID'] (developerIndia => `9f1337e4154910eb1bdb3bfac32b88f69546468b1281a6db58f50a909df5049f@group.calendar.google.com`) + 3.3 Calender Id [`GOOGLE_CALENDER_ID`] (developerIndia => `9f1337e4154910eb1bdb3bfac32b88f69546468b1281a6db58f50a909df5049f@group.calendar.google.com`) 4. Connect Google Calender through [Google cloud Console](https://console.cloud.google.com/) From a82ea12c0f7bac977232574b0906d7620c26d32c Mon Sep 17 00:00:00 2001 From: Rachit Agrawal <111473259+Rancho-rachit@users.noreply.github.com> Date: Mon, 22 Apr 2024 17:29:01 +0000 Subject: [PATCH 5/5] Club main and event_details --- event-manager/README.md | 6 +- event-manager/discord_.py | 69 +++++++++---------- event-manager/event_details.py | 17 ----- ...oogle_calender_.py => google_calendar_.py} | 12 +--- event-manager/main.py | 33 +++++++-- 5 files changed, 64 insertions(+), 73 deletions(-) delete mode 100644 event-manager/event_details.py rename event-manager/{google_calender_.py => google_calendar_.py} (84%) diff --git a/event-manager/README.md b/event-manager/README.md index fea751c..506bb05 100644 --- a/event-manager/README.md +++ b/event-manager/README.md @@ -23,13 +23,13 @@ This script creates events across - 3.2 Guild ID [`DISCORD_GUILD_ID`] (developersIndia => `1229786646468362260`) - 3.3 Calender Id [`GOOGLE_CALENDER_ID`] (developerIndia => `9f1337e4154910eb1bdb3bfac32b88f69546468b1281a6db58f50a909df5049f@group.calendar.google.com`) + 3.3 calendar Id [`GOOGLE_calendar_ID`] (developerIndia => `9f1337e4154910eb1bdb3bfac32b88f69546468b1281a6db58f50a909df5049f@group.calendar.google.com`) -4. Connect Google Calender through [Google cloud Console](https://console.cloud.google.com/) +4. Connect Google calendar through [Google cloud Console](https://console.cloud.google.com/) 4.1 Create a Project on Google Cloud Console - 4.2 Search for Calender API and enable it + 4.2 Search for calendar API and enable it 4.3 Create Credentials -> OAuth Client ID -> Application type as Desktop diff --git a/event-manager/discord_.py b/event-manager/discord_.py index 07ed13d..8b16ca4 100644 --- a/event-manager/discord_.py +++ b/event-manager/discord_.py @@ -1,50 +1,47 @@ from datetime import datetime, timedelta -import os -from dotenv import load_dotenv -import event_details import discord from discord.ext import commands -load_dotenv() -bot_token = os.getenv('DISCORD_BOT_TOKEN') -guild_id = int(os.getenv('DISCORD_GUILD_ID')) +def create_discord_event(bot_token, guild_id, + EVENT_NAME, EVENT_DESCRIPTION, EVENT_LOCATION, EVENT_DATE, EVENT_START_TIME, EVENT_END_TIME +): -bot = commands.Bot(command_prefix='!', intents=discord.Intents.all()) + bot = commands.Bot(command_prefix='!', intents=discord.Intents.all()) -@bot.event -async def on_ready(): + @bot.event + async def on_ready(): - # Convert the date string to a datetime object - date_object = datetime.strptime(event_details.EVENT_DATE, "%Y-%m-%d") + # Convert the date string to a datetime object + date_object = datetime.strptime(EVENT_DATE, "%Y-%m-%d") - # Convert the time string to a datetime object - start_time_object = datetime.strptime(event_details.EVENT_START_TIME, "%H:%M") - end_time_object = datetime.strptime(event_details.EVENT_END_TIME, "%H:%M") + # Convert the time string to a datetime object + start_time_object = datetime.strptime(EVENT_START_TIME, "%H:%M") + end_time_object = datetime.strptime(EVENT_END_TIME, "%H:%M") - # Combine the date and time objects - st = date_object.replace(hour=start_time_object.hour, minute=start_time_object.minute).astimezone() - et = date_object.replace(hour=end_time_object.hour, minute=end_time_object.minute).astimezone() + # Combine the date and time objects + st = date_object.replace(hour=start_time_object.hour, minute=start_time_object.minute).astimezone() + et = date_object.replace(hour=end_time_object.hour, minute=end_time_object.minute).astimezone() - gg = bot.get_guild(guild_id) + gg = bot.get_guild(guild_id) - try: - event = await gg.create_scheduled_event( - name=event_details.EVENT_NAME, - entity_type=discord.EntityType.external, - description=event_details.EVENT_DESCRIPTION, - start_time=st, - end_time=et, - location=event_details.EVENT_LOCATION, - privacy_level=discord.PrivacyLevel.guild_only, - ) - print("Discord Event: ", event.url) + try: + event = await gg.create_scheduled_event( + name=EVENT_NAME, + entity_type=discord.EntityType.external, + description=EVENT_DESCRIPTION, + start_time=st, + end_time=et, + location=EVENT_LOCATION, + privacy_level=discord.PrivacyLevel.guild_only, + ) + print("Discord Event: ", event.url) + + except Exception as e: + print(e) + + await bot.close() - except Exception as e: - print(e) - - await bot.close() - -# Run the bot -bot.run(bot_token) + # Run the bot + bot.run(bot_token) # END \ No newline at end of file diff --git a/event-manager/event_details.py b/event-manager/event_details.py deleted file mode 100644 index e8620c6..0000000 --- a/event-manager/event_details.py +++ /dev/null @@ -1,17 +0,0 @@ -# To get the event details from the user - -def get_input(): - NAME = input("Event title: ") - DESCRIPTION = input("Event description: ") - LOCATION = input("Event location (red -> for developersindia subreddit): ") - if LOCATION == "red": - LOCATION = "https://www.reddit.com/r/developersindia/" - DATE = input("Enter the event date (yyyy-mm-dd): ") - START_TIME = input("Enter the event start time (hh:mm)- ") - END_TIME = input("Enter the event end time (hh:mm)- ") - - return NAME, DESCRIPTION, LOCATION, DATE, START_TIME, END_TIME - -EVENT_NAME, EVENT_DESCRIPTION, EVENT_LOCATION, EVENT_DATE, EVENT_START_TIME, EVENT_END_TIME = get_input() - -# END \ No newline at end of file diff --git a/event-manager/google_calender_.py b/event-manager/google_calendar_.py similarity index 84% rename from event-manager/google_calender_.py rename to event-manager/google_calendar_.py index e08787c..ec998c0 100644 --- a/event-manager/google_calender_.py +++ b/event-manager/google_calendar_.py @@ -1,19 +1,13 @@ import os.path -import event_details as main - -from dotenv import load_dotenv from google.auth.transport.requests import Request from google.oauth2.credentials import Credentials from google_auth_oauthlib.flow import InstalledAppFlow from googleapiclient.discovery import build -load_dotenv() -calendar_id = os.getenv('GOOGLE_CALENDAR_ID') - SCOPES = ['https://www.googleapis.com/auth/calendar'] -def create_event(name, description, location, date, start_time, end_time): +def create_google_calendar_event(calendar_id, name, description, location, date, start_time, end_time): creds = None @@ -54,13 +48,11 @@ def create_event(name, description, location, date, start_time, end_time): event = service.events().insert(calendarId=calendar_id, body=event).execute() - print('Google Calender: %s' % (event.get('htmlLink'))) + print('Google calendar: %s' % (event.get('htmlLink'))) return event except Exception as e: print(e) return None -create_event(main.EVENT_NAME, main.EVENT_DESCRIPTION, main.EVENT_LOCATION, main.EVENT_DATE, main.EVENT_START_TIME, main.EVENT_END_TIME) - # END \ No newline at end of file diff --git a/event-manager/main.py b/event-manager/main.py index 407a247..1cb2a34 100644 --- a/event-manager/main.py +++ b/event-manager/main.py @@ -1,12 +1,31 @@ -# SCRIPT +import os +from dotenv import load_dotenv -# Execute event_details.py -import event_details +load_dotenv() +bot_token = os.getenv('DISCORD_BOT_TOKEN') +guild_id = int(os.getenv('DISCORD_GUILD_ID')) +calendar_id = os.getenv('GOOGLE_CALENDAR_ID') -# Execute discord_.py -import discord_ +def get_input(): + NAME = input("Event title: ") + DESCRIPTION = input("Event description: ") + LOCATION = input("Event location (red -> for developersindia subreddit): ") + if LOCATION == "red": + LOCATION = "https://www.reddit.com/r/developersindia/" + DATE = input("Enter the event date (yyyy-mm-dd): ") + START_TIME = input("Enter the event start time (hh:mm)- ") + END_TIME = input("Enter the event end time (hh:mm)- ") -# Execute google_calender.py -import google_calender_ + return NAME, DESCRIPTION, LOCATION, DATE, START_TIME, END_TIME + +EVENT_NAME, EVENT_DESCRIPTION, EVENT_LOCATION, EVENT_DATE, EVENT_START_TIME, EVENT_END_TIME = get_input() + +# Execute create_discord_event +from discord_ import create_discord_event +create_discord_event(bot_token, guild_id, EVENT_NAME, EVENT_DESCRIPTION, EVENT_LOCATION, EVENT_DATE, EVENT_START_TIME, EVENT_END_TIME) + +# Execute google_calendar_event +from google_calendar_ import create_google_calendar_event +create_google_calendar_event(calendar_id, EVENT_NAME, EVENT_DESCRIPTION, EVENT_LOCATION, EVENT_DATE, EVENT_START_TIME, EVENT_END_TIME) # END \ No newline at end of file