Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import logging
- from mysql.connector import MySQLConnection, Error
- import retrying
- from sys import exit
- import time
- logger = logging.getLogger()
- logging.basicConfig(level=logging.INFO)
- connection = MySQLConnection()
- retry = retrying.retry()
- logger.info("Loading Libraries...")
- logger.info("Starting up task manager")
- logger.info("Trying to connect to sql..")
- try:
- connection.connect(host="",
- database="",
- user="",
- password="")
- logger.info("Successfully connected to the database!")
- except connection.Error:
- logger.error("Could not connect to sql database!")
- cursor = connection.cursor()
- def generate():
- import time
- ticks = time.time()
- return hex(int(ticks))[2:]
- def printAllTasks():
- logger.info("Printing Shorthands")
- try:
- cursor.execute("SELECT * FROM tasks")
- rows = cursor.fetchall()
- except Error as e:
- print(e)
- for row in rows:
- print(" - {}) {} ({})".format(row[0], row[2], row[1]))
- main()
- def viewTask(view):
- view = printAllTasks()
- select = int(input("\nPlease select the id of the task you want to view: "))
- def printSingleTask():
- try:
- cursor.execute("SELECT * FROM tasks")
- except Error:
- print(Error)
- @retry(wrap_exception=True)
- def main():
- logger.info("Displaying Main Menu")
- time.sleep(1)
- print("\nWelcome to the TaskKiwi. Please select an option..\n\n - 1) Create Task\n - 2) View All Tasks\n - 3) Delete Task\n - 4) Delete All Tasks\n - 5) Exit\n")
- select = int(input("Option Selection - Integer: "))
- if 5 < select < 1:
- logger.error("Out of range. Trying again.")
- print("Your selection was out of range. Please try again.")
- return retrying.retry(
- retry_on_exception=lambda e: isinstance(
- e, ValueError))
- elif 5 >= select >= 1:
- if select == 1:
- createTask()
- elif select == 2:
- printAllTasks()
- elif select == 3:
- deleteTask()
- elif select == 4:
- logger.info("Dropping All Records")
- print("Now Deleting All Tasks.")
- cursor.execute("DELETE FROM tasks")
- elif select == 5:
- exit()
- main()
- #main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement