Advertisement
Guest User

Untitled

a guest
Sep 4th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. import logging
  2. from mysql.connector import MySQLConnection, Error
  3. import retrying
  4. from sys import exit
  5. import time
  6.  
  7. logger = logging.getLogger()
  8. logging.basicConfig(level=logging.INFO)
  9.  
  10. connection = MySQLConnection()
  11. retry = retrying.retry()
  12.  
  13. logger.info("Loading Libraries...")
  14. logger.info("Starting up task manager")
  15. logger.info("Trying to connect to sql..")
  16. try:
  17. connection.connect(host="",
  18. database="",
  19. user="",
  20. password="")
  21. logger.info("Successfully connected to the database!")
  22. except connection.Error:
  23. logger.error("Could not connect to sql database!")
  24.  
  25. cursor = connection.cursor()
  26.  
  27.  
  28. def generate():
  29. import time
  30. ticks = time.time()
  31. return hex(int(ticks))[2:]
  32.  
  33.  
  34. def printAllTasks():
  35. logger.info("Printing Shorthands")
  36. try:
  37. cursor.execute("SELECT * FROM tasks")
  38. rows = cursor.fetchall()
  39. except Error as e:
  40. print(e)
  41. for row in rows:
  42. print(" - {}) {} ({})".format(row[0], row[2], row[1]))
  43. main()
  44.  
  45. def viewTask(view):
  46. view = printAllTasks()
  47. select = int(input("\nPlease select the id of the task you want to view: "))
  48.  
  49.  
  50. def printSingleTask():
  51. try:
  52. cursor.execute("SELECT * FROM tasks")
  53. except Error:
  54. print(Error)
  55.  
  56.  
  57. @retry(wrap_exception=True)
  58. def main():
  59. logger.info("Displaying Main Menu")
  60. time.sleep(1)
  61. 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")
  62. select = int(input("Option Selection - Integer: "))
  63. if 5 < select < 1:
  64. logger.error("Out of range. Trying again.")
  65. print("Your selection was out of range. Please try again.")
  66. return retrying.retry(
  67. retry_on_exception=lambda e: isinstance(
  68. e, ValueError))
  69. elif 5 >= select >= 1:
  70. if select == 1:
  71. createTask()
  72. elif select == 2:
  73. printAllTasks()
  74. elif select == 3:
  75. deleteTask()
  76. elif select == 4:
  77. logger.info("Dropping All Records")
  78. print("Now Deleting All Tasks.")
  79. cursor.execute("DELETE FROM tasks")
  80. elif select == 5:
  81. exit()
  82.  
  83. main()
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117. #main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement