def get(output_path="GCal.pkl"): CALENDAR_NAME = "PoliCal" CLIENT_SECRET_FILE = configuration.get_file_location("client_secret.json") APP_NAME = "PoliCal" scopes = ["https://www.googleapis.com/auth/calendar"] store = Storage(configuration.get_file_location(output_path)) credentials = store.get() if not credentials or credentials.invalid: flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, scopes) flow.user_agent = APP_NAME credentials = tools.run_flow(flow, store) print("Credenciales almacenadas en" + configuration.get_file_location(output_path)) return credentials
def convertICStoCSV(): # print("Empezando:") # print("Eliminando si existe") print("Descargando calendario desde Aula Virtual...") logging.info("Descargando calendario desde Aula Virtual...") filename = configuration.get_file_location("mycalendar.ics") if os.path.exists(filename): os.remove(filename) url = configuration.load_config_file('polical.yaml')['calendar_url'] wget.download(url, filename) addEvent(findHeader(filename), filename) print("\nEspere...") logging.info("Descarga de calendario finalizada.")
def LoadCSVTasktoDB(): with open(configuration.get_file_location('calendar.csv')) as csv_file: csv_reader = csv.reader(csv_file, delimiter=';') line_count = 0 for row in csv_reader: if line_count == 0: #print(f'Column names are {", ".join(row)}') line_count += 1 elif len(row) > 9 and not line_count == 0: print(len(row)) create_subject.create(row[9][3:9]) sbjID = connectSQLite.getSubjectID(row[9][3:9]) print(row[0]) task = TareaClass.Tarea( row[1], row[2], row[3], datetime.strptime(row[7][0:8], '%Y%m%d'), sbjID ) #Siempre se extraera la fecha aun cuando pueda tener un formato YMDTXXX sql = connectSQLite.saveTask(task) print("Las tareas nuevas se agregaron a la BD") sql.connection.close()
def LoadCSVTasktoDB(): with open(configuration.get_file_location('calendar.csv')) as csv_file: logging.info("CSV abierto.") csv_reader = csv.reader(csv_file, delimiter=';') line_count = 0 for row in csv_reader: if line_count == 0: line_count += 1 elif len(row) > 9 and not line_count == 0: # print(len(row)) create_subject.create(Get_Subject_Name_From_CSV(row[9]), row[2]) sbjID = connectSQLite.getSubjectID( Get_Subject_Name_From_CSV(row[9])) # print(row[0]) # Siempre se extraera la fecha aun cuando pueda tener un # formato YMDTXXX task = TareaClass.Tarea( row[1], row[2], row[3], datetime.strptime(row[7][0:8], '%Y%m%d'), sbjID) sql = connectSQLite.saveTask(task) # print("Las tareas nuevas se agregaron a la BD") logging.info("Las tareas nuevas se agregaron a la BD") sql.connection.close()
def main(): """Start the bot.""" # Create the Updater and pass it your bot's token. # Make sure to set use_context=True to use the new context based callbacks # Post version 12 this will no longer be necessary updater = Updater(token=configuration.get_bot_token( configuration.get_file_location("config.yaml")), ) # Get the dispatcher to register handlers dispatcher = updater.dispatcher # on different commands - answer in Telegram dispatcher.add_handler(CommandHandler("start", start)) # dispatcher.add_handler(CommandHandler("id", id)) dispatcher.add_handler(CommandHandler("help", help_command)) dispatcher.add_handler(CommandHandler("list", list_memes)) dispatcher.add_handler(CommandHandler("top", top_memes)) dispatcher.add_handler(CommandHandler("random", random_meme)) dispatcher.add_handler(CommandHandler("pose", jojo_pose)) # add inlinequery dispatcher.add_handler(InlineQueryHandler(inlinequery)) # on noncommand i.e message - echo the message on Telegram dispatcher.add_handler(MessageHandler(Filters.sticker, get_sticker_id)) dispatcher.add_handler(MessageHandler(Filters.photo, answer_webp)) dispatcher.add_handler( MessageHandler(Filters.text & ~Filters.command, echo)) dispatcher.add_error_handler(error_handler) # Start the Bot updater.start_polling() # Run the bot until you press Ctrl-C or the process receives SIGINT, # SIGTERM or SIGABRT. This should be used most of the time, since # start_polling() is non-blocking and will stop the bot gracefully. updater.idle()
def findHeader(icsCal): f = open(configuration.get_file_location(icsCal), "r", encoding="utf-8") # print("Looking for headers in this file....") f2 = open(configuration.get_file_location("calendar.csv"), "w+") f1 = f.readlines() wrBegin = False # Flag to detect the line BEGIN:VEVENT # , and start saving the parameters of the event # in this case is for getting the headers for the CSV wrNormal = False wrDescription = False # Saving a description that could be large for x in f1: # print(x) # print(str(x.count('\t'))+"---"+x) # headers = [] list = x.split(":", 1) chars = [c for c in list[0]] # Looking for the line that begins an event if list[0] == "BEGIN" and list[1] == "VEVENT\n": wrNormal = True wrBegin = True # Looking for the line where the description begins to activate its # flag elif list[0] == "DESCRIPTION": wrDescription = True # If the lines are not beginning with an space or an "\t", means that # is another tag and not currently a decription, but it can change elif chars[0] != ' ' and chars[0] != '\t' and chars[ 0] != '\n' and wrDescription: wrDescription = False if list[0] == "END": # If the event comes to its end the flag # deactivates wrNormal = False else: "" # If all of the headers are reached it only writes and \n and stops the for loop if wrNormal == False and wrBegin == True: f2.write("END\n") elif wrNormal and wrDescription == False: # Everything that can be and tag inside an event is appended to the # list, but if the events are irregulars this can cause errors f2.write(list[0].replace(';', '') + ";") elif wrNormal and wrDescription: # If the tag is description this is added, but can be lines that # are part of the description if list[0] == "DESCRIPTION": f2.write(list[0].replace(';', '') + ";") f2.close() # File calendar.csv is closed listHeaders = [] # A list of every posible header if the ics file is # IRREGULAR # Reading the calendar.csv temporary to get the header with the most number # of tags with open(configuration.get_file_location("calendar.csv")) as csv_file: csv_reader = csv.reader(csv_file, delimiter=';') # line_count = 0 for row in csv_reader: listHeaders.append(row) # File name to erase the calendar.csv that is temporary filename = configuration.get_file_location("calendar.csv") if os.path.exists(filename): os.remove(filename) # Get the header with the most number of tags return max(listHeaders, key=len)
def addEvent(header, filename): f = open(configuration.get_file_location(filename), "r", encoding='utf-8') f2 = open(configuration.get_file_location("calendar.csv"), "w+") f1 = f.readlines() # print(header) for x in header: # Write the defenitive header f2.write(x) if x != "END": f2.write(";") f2.write("\n") wrBegin = False # Flag to detect the line BEGIN:VEVENT # , and start saving the parameters of the event # in this case is for getting the headers for the CSV wrNormal = False # Flag to say that is writting everything but no description wrDescription = False # Flag to say that is writting a description for x in f1: # Read all of the lines between BEGIN:VEVENT and END:VEVENT # Separate the tags from the content, the results are limited to 2 list = x.split(":", 1) # list for looking the first character on the line chars = [c for c in list[0]] if list[0] == "BEGIN" and list[1] == "VEVENT\n": # Here an event begins wrNormal = True # Flag activated, for ONE EVENT wrBegin = True # Flag activated, for the whole set of events list[1] = "VEVENT" # ERASED the "\n" character # Here a DESCRIPTION begins, can have a lot of lines. elif list[0] == "DESCRIPTION": wrDescription = True # Flag activated, for the DESCRIPTION # A description can be conformed by a lot of especial characters so # the description will be between "" f2.write("\"") # If the lines are not beginning with an space or an "\t", means that # is another tag and not currently a decription, but it can change elif chars[0] != ' ' and chars[0] != '\t' and chars[ 0] != '\n' and wrDescription: wrDescription = False # Flag deactivated, it means a description content ends f2.write("\"" + ";") # Also finished with a semicolon elif list[0] == "END" and list[1] == "VEVENT\n": # An event fisnish wrNormal = False # Flag deactivated, a event ends else: "" if wrNormal and wrDescription == False: # If wrNormal is activated and wrDescription deactivated means that # is every posible tag except a description # print(list) try: # Delete the especial character removebsn = list[1].split("\n", 1) f2.write(removebsn[0] + ";") # Adds semicolon except Exception as e: print(e) elif wrNormal and wrDescription: # If wrNormal and wrDescription are # activated it is a description and can have differentes kind of # lines for y in list: # A for loop for replacing special characters as # "\n", "\t" and the word "DESCRIPTION" new_list = { x.replace('\n', '').replace('\t', '').replace('DESCRIPTION', '') for x in list } for x in new_list: # A for loop to add the contents to the description f2.write(x) elif wrNormal == False and wrBegin: # if wrNormal is deactivated and wrBegin activated, that means that # a event has ended so a "\n" is added f2.write("\n")
def getdb(): db = sqlite3.connect(configuration.get_file_location('tasks.db')) return db
return service.events().insert(calendarId='primary', body=event, sendNotifications=True).execute() """ scopes = ['https://www.googleapis.com/auth/calendar.events'] flow = InstalledAppFlow.from_client_secrets_file( configuration.get_file_location("client_secret.json"), scopes=scopes) credentials = flow.run_console() pickle.dump(credentials, open( configuration.get_file_location("GCal.pkl", "wb"))) """ gcal_pkl = Path(configuration.get_file_location("GCal.pkl")) # while(not gcal_pkl.is_file()): # get_GCal_Keys.get(configuration.get_file_location("GCal.pkl")) # credentials = pickle.load( # open(configuration.get_file_location("GCal.pkl"), "rb")) credentials = get_GCal_Keys.get() http = credentials.authorize(httplib2.Http()) service = build("calendar", "v3", http=http) result = service.calendarList().list().execute() calendar_id = result['items'][0]['id'] result = service.events().list(calendarId=calendar_id).execute() print(result['items'][0])
import MateriaClass import csv import connectSQLite import configuration import logging logging.basicConfig(filename='Running.log', level=logging.INFO, format='%(asctime)s:%(levelname)s:%(message)s') try: with open(configuration.get_file_location('materias.csv')) as csv_file: csv_reader = csv.reader(csv_file, delimiter=';') line_count = 0 for row in csv_reader: if line_count == 0: logging.info(f'Column names are {", ".join(row)}') line_count += 1 else: subject = MateriaClass.Materia(row[1], row[0]) logging.info(subject.print()) sql = connectSQLite.saveSubjects(subject) for row in sql.fetchall(): logging.info(row) sql = connectSQLite.getdb().close() except: logging.info("FALSE, exception ocurred") # line_count += 1 # print(f'Processed {line_count} lines.')