Guest User

Untitled

a guest
Oct 25th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. import mysql
  2. import pymysql
  3. from datetime import date, datetime, timedelta
  4.  
  5. cursor = pymysql.cursors.Cursor
  6.  
  7.  
  8. # Function for adding a new entry
  9. def new_entry(name, date, task, time, notes):
  10. # Build dictionary with new entry information
  11.  
  12. myDict = {
  13. 'Employee': name, # Name of employee
  14. 'Date': date, # Date of worked task
  15. 'Task': task, # Title of Task
  16. 'Time': time, # Time spent on task
  17. 'Notes': notes # Notes on the task
  18. }
  19. table = ('timesheet')
  20. placeholders = ', '.join(['%s'] * len(myDict))
  21. columns = ', '.join(myDict.keys())
  22. sql = "INSERT INTO %s ( %s ) VALUES ( %s )" % (table, columns,
  23. placeholders)
  24. pymysql.cursors.Cursor.execute(sql, myDict)
  25.  
  26.  
  27.  
  28.  
  29. #list all entries for a particular employee
  30. def previous_entries(emp_name):
  31. pymysql.cursors.Cursor.execute("SELECT * from user_data WHERE Name = %s",
  32. (emp_name,))
  33.  
  34. #list all entries that match a date or search term
  35. #def search_entries():
  36. # return null
  37.  
  38.  
  39.  
  40. #Print a report of this information to the screen, including the date, title
  41. of task, time spent, employee, and general notes.
  42.  
  43.  
  44.  
  45. if __name__ == '__main__':
  46. #cnx = mysql.connect(user='root', database='me10_mig')
  47. cnx = pymysql.connect(user='root', password='password',
  48. database='me10_mig')
  49.  
  50.  
  51.  
  52. print("Please enter (1), (2), or (3)")
  53. begin = input("Would you like to (1) enter a new entry or (2) display all
  54. previous entries or (3) display entries that match a date or search term? ")
  55.  
  56. if begin == '1':
  57. name = input("Your Name: ")
  58. date = input("Date of Time Worked: ")
  59. task = input("Title of Task: ")
  60. time = input("Time Spent on Task: ")
  61. notes = input("Notes on Time Worked: ")
  62. new_entry(name, date, task, time, notes)
  63.  
  64. if begin == '2':
  65. name = input("What is the employee name: ")
  66. previous_entries(name)
  67.  
  68. #if begin == '3':
Add Comment
Please, Sign In to add comment