-
Notifications
You must be signed in to change notification settings - Fork 0
/
export_harvest.py
55 lines (48 loc) · 2.04 KB
/
export_harvest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os
from datetime import datetime, timedelta
from harvest import Harvest, HarvestError
from spreadsheets_util import *
h = Harvest( os.environ['HARVEST_URL'], os.environ['HARVEST_EMAIL'], os.environ['HARVEST_PASSWORD'] )
end = datetime.today()
start = end - timedelta(720) # 2 Years in the past
gd_client = gdata.spreadsheet.service.SpreadsheetsService()
gd_client.email = os.environ['GDOCS_EMAIL']
gd_client.password = os.environ['GDOCS_PASSWORD']
gd_client.source = 'opengeo-solutions_dashboard-1'
gd_client.ProgrammaticLogin()
#gd_client.debug = True
key = '0AgQ7XY0Atfx5dERpQ2VDcEtGUVpOQVRvVng4Tm1DMGc'
worksheet = 'od6'
def update_project(row, name, client, total, billable, non_billable):
CellsUpdateAction(gd_client, key, worksheet, row, 1, name)
CellsUpdateAction(gd_client, key, worksheet, row, 2, client)
CellsUpdateAction(gd_client, key, worksheet, row, 3, str(total))
CellsUpdateAction(gd_client, key, worksheet, row, 4, str(billable))
CellsUpdateAction(gd_client, key, worksheet, row, 5, str(non_billable))
project_count = 1
for project in h.projects():
total = 0
tasks = {}
billable = 0
non_billable = 0
for assignment in project.task_assignments:
task_dict = {}
name = assignment.task.name
task_dict['name'] = name
task_dict['billable'] = assignment.billable
task_dict['hours'] = 0
task_dict['budget'] = assignment.budget
tasks[name] = task_dict
for entry in project.entries(start, end):
task = tasks[entry.task.name]
total += entry.hours
task['hours'] = task['hours'] + entry.hours
if tasks[entry.task.name]['billable']:
billable += entry.hours
else:
non_billable += entry.hours
print "%s,%s,%02f, %02f, %02f" % (project.name, str(project.client.name), total, billable, non_billable)
for k,v in tasks.iteritems():
print k, v['hours'], v['budget']
update_project(project_count+1, project.name, str(project.client.name), total, billable, non_billable)
project_count += 1