コード例 #1
0
                              database=mysql_creds['database'],
                              port=mysql_creds['port'])
cursor = cnx.cursor()
    

    
try:
    for user in h.users():
        user_hours[user.email] = 0
        user_names[user.email] = user.first_name + " " + user.last_name
        for entry in user.entries( start, end ):
            if(not entry.adjustment_record):
                user_hours[user.email] += entry.hours                                
                project = h.project(entry.project_id)
                client = h.client(project.client_id)
                task = h.task(entry.task_id)
                if(project_hours.has_key(project.name)):
                    project_hours[project.name] += entry.hours
                else:
                    project_hours[project.name] = entry.hours

                add_entry = ("INSERT INTO timesheet "
                             "(id, project_id, task_id, user_id, hours, "
                             "notes, client, created_at, updated_at, project, task) "
                             "VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s )")
            
                entry_data = (entry.id, project.id, entry.task_id, entry.user_id, entry.hours,
                              entry.notes, client.name, entry.created_at, entry.updated_at, project.name, task.name)
                cursor.execute(add_entry, entry_data)
                #print cursor.lastrowid
                cnx.commit()