Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import mysql
- import pymysql
- from datetime import date, datetime, timedelta
- cursor = pymysql.cursors.Cursor
- # Function for adding a new entry
- def new_entry(name, date, task, time, notes):
- # Build dictionary with new entry information
- myDict = {
- 'Employee': name, # Name of employee
- 'Date': date, # Date of worked task
- 'Task': task, # Title of Task
- 'Time': time, # Time spent on task
- 'Notes': notes # Notes on the task
- }
- table = ('timesheet')
- placeholders = ', '.join(['%s'] * len(myDict))
- columns = ', '.join(myDict.keys())
- sql = "INSERT INTO %s ( %s ) VALUES ( %s )" % (table, columns,
- placeholders)
- pymysql.cursors.Cursor.execute(sql, myDict)
- #list all entries for a particular employee
- def previous_entries(emp_name):
- pymysql.cursors.Cursor.execute("SELECT * from user_data WHERE Name = %s",
- (emp_name,))
- #list all entries that match a date or search term
- #def search_entries():
- # return null
- #Print a report of this information to the screen, including the date, title
- of task, time spent, employee, and general notes.
- if __name__ == '__main__':
- #cnx = mysql.connect(user='root', database='me10_mig')
- cnx = pymysql.connect(user='root', password='password',
- database='me10_mig')
- print("Please enter (1), (2), or (3)")
- begin = input("Would you like to (1) enter a new entry or (2) display all
- previous entries or (3) display entries that match a date or search term? ")
- if begin == '1':
- name = input("Your Name: ")
- date = input("Date of Time Worked: ")
- task = input("Title of Task: ")
- time = input("Time Spent on Task: ")
- notes = input("Notes on Time Worked: ")
- new_entry(name, date, task, time, notes)
- if begin == '2':
- name = input("What is the employee name: ")
- previous_entries(name)
- #if begin == '3':
Add Comment
Please, Sign In to add comment