def connect_to_sheets(self): token_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "token.pickle") google_settings = Settings.get().google_connection_settings self.service = google_settings.get_service('sheets', 'v4', SCOPES_SHEETS, token_path)
def connect_to_doc(self): token_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), "token.pickle" ) google_settings = Settings.get().google_connection_settings self.service = google_settings.get_service('docs', 'v1', scopes=SCOPES_DOC, token_file_path=token_path)
def connect_to_calendar(self): token_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "token.pickle") google_settings = Settings.get().google_connection_settings self.service = google_settings.get_service('calendar', 'v3', scopes=SCOPES_CALENDAR, token_file_path=token_path)
def connect_to_db(self, alias: str = MONGOENGINE_DEFAULT_CONNECTION_NAME): """ Connects to a DB with the given alias. The alias of every db equals to the db name, except for the talpibot_main db that it's alias is "default" :param alias: The name of the DB or "default" for talpibot_main :return: """ # Check if this connection is not already open if alias in self._active_db_connections: return # Get username&password from db settings = Settings.get().database_settings database_creds = Settings.get().database_creds # Get real db name db_name = alias if alias == MONGOENGINE_DEFAULT_CONNECTION_NAME: db_name = "admin" # Connect to the DB BotItLogger.info("Connecting to db `%s` [%s]..." % (alias, db_name)) connect( db=db_name, username=database_creds.username, password=database_creds.password, authentication_source=settings.authentication_table, host=settings.server_url, port=settings.server_port, ssl=settings.use_ssl, alias=alias ) self._active_db_connections[alias] = True
def load_settings(): # IMPORTANT: RUN THE FOLLOWING COMMAND BEFORE CHANGING THIS FILE: # # git update-index --assume-unchanged settings.py # git update-index --skip-worktree settings.py # # THIS WILL PREVENT YOUR SECRET CREDENTIALS FROM BEING UPLOADED TO THE MAIN REPO. Settings( database_creds=get_credentials(), database_settings=DatabaseSettings(server_url="localhost", server_port=27017, use_ssl=False, ssl_server_certificate='', authentication_table='admin'), )
""" result = self.service.events().delete( calendarId=calendar_id, eventId=event.calendar_event_id, sendUpdates=send_updates).execute() if len(result) == 0: return True return False @staticmethod def _parse_google_calendar_date(date_dict: dict) -> Union[datetime, date]: if "dateTime" in date_dict: return dateutil.parser.parse(date_dict.get("dateTime")) if "date" in date_dict: return dateutil.parser.parse(date_dict.get("date")).date() if __name__ == "__main__": from datetime import timedelta Settings() with GoogleCalendar.get_instance() as gc: print( gc.get_events( '*****@*****.**', start_time=datetime.now() - timedelta(days=1), end_time=datetime.now() + timedelta(days=1), ))