def import_cal(): if not INPUT: print("Import command requires -i or --input !") else: for path in INPUT: name = input("What would you like to name this calendar? ") settings.set_calendar(name, path) list_cals()
def confirm_input(user_input): print("I got the following: ") if type(user_input) == list: for i in user_input: print(i) else: print(user_input) confirm = input("Is this accurate? ") if "y" in confirm.lower(): return True else: return False
def get_weekends(): """ Gets weekends from user input """ user_reply = input("What days of the week are your weekends? ") days = weekday_dict.keys() ret = [] for day in days: if day.lower() in user_reply.lower(): ret.append(day) if confirm_input(ret): return ret else: return get_weekends()
def get_work_hours(): """ Gets work hours from user input """ user_reply = input("What are your work hours? (Format: 9:00 AM-5:00 PM) ") user_reply_list = user_reply.split("-") for i in user_reply_list: try: arrow.get(i, "H:mm A") except ParserError: print("Invalid Output") return get_work_hours() if confirm_input(user_reply_list): return user_reply_list else: return get_work_hours()
def list_cals(): if settings.calendars_imported and not args.all: settings.list_imported_calendars() else: imported = settings.list_imported_calendars() imported_names = [cal[0] for cal in imported] cals_result = gcal_service.calendarList().list().execute() cals = cals_result.get("items", []) for cal in cals: if cal["summary"].lower() not in imported_names: print(cal["summary"] + ": " + cal["id"]) user_response = input( "Would you like to import these into your settings for future use? " ) if "y" in user_response.lower(): for cal in cals: settings.set_calendar(cal["summary"], cal["id"])
def get_timezone(zones: list): """ Gets timezone from user input """ user_input = input( 'What timezone do you reside in? (Format: "US/Pacific", "US/Eastern", etc): ' ) smaller_zones = [] if user_input not in zones: for zone in zones: if user_input.lower() in zone.lower(): smaller_zones.append(zone) if len(smaller_zones): print("Zones that match that input are: ") for zone in smaller_zones: print(zone) return get_timezone(smaller_zones) else: if confirm_input(user_input): return user_input else: return get_timezone()
def get_credentials_directory(location=None): """ Gets credentials directory from user input """ if not location: try: credentials = os.getenv("HOME") + "/etc/keys/google-api/" return get_credentials_directory(credentials) except TypeError: pass elif os.path.exists(os.path.join(location + "/credentials.json")): credentials = location if confirm_input(credentials): return credentials else: return get_credentials_directory() elif "credentials.json" in location: credentials = os.path.dirname(location) if confirm_input(credentials): return credentials else: return get_credentials_directory() loc = input("Path to credentials.json: ") return get_credentials_directory(location=loc)