This repository was archived by the owner on Mar 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
166 lines (144 loc) · 4.28 KB
/
Copy pathapp.py
File metadata and controls
166 lines (144 loc) · 4.28 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import eel, os, json, urllib, sys
from typing import Dict
import requests
import base64
def load_config():
try:
with open(os.path.expanduser("config.json"), 'r') as f:
json_data = json.load(f)
return json_data
except:
print("Error loading configuration.")
# Load configuration and initialize session
config = load_config()
session = requests.session()
@eel.expose
def authenticate():
"""Authenticate against the api."""
data = {
'username': config['user'],
'password': config['password'],
'client_name': config['client_name'],
'client_vendor': config['client_vendor']
}
auth_url = '{}/issue-token'.format(config['url'])
r = session.post(auth_url, data=data)
try:
token = r.json()['token']
# print(token)
return token
except:
return False
token = authenticate()
@eel.expose
def get(url):
"""Make a get call to the API."""
headers = {'X-Angie-AuthApiToken': token}
url = '{}{}'.format(config['url'], url)
r = session.get(url, headers=headers)
return r.json()
@eel.expose
def post(url, data):
"""Make post call to the API."""
headers = {'X-Angie-AuthApiToken': token}
url = '{}{}'.format(config['url'], url)
r = session.post(url, data=data, headers=headers)
return r.json()
@eel.expose
def delete(url):
"""Make delete call to the API."""
headers = {'X-Angie-AuthApiToken': token}
url = '{}{}'.format(config['url'], url)
r = session.delete(url, headers=headers)
return r.json()
@eel.expose
def put(url):
"""Make put call to the API."""
headers = {'X-Angie-AuthApiToken': token}
url = '{}{}'.format(config['url'], url)
r = session.post(url, data=data, headers=headers)
return r.json()
@eel.expose
def get_url():
"""Get the non-API url."""
url = config['url'].split("/api/")[0]
return url
@eel.expose
def get_info():
"""Get info about the system information."""
message = get('/info')
return message
@eel.expose
def get_job_types():
"""Get the available job types."""
message = get('/job-types')
return message
@eel.expose
def get_projects():
"""Get the projects."""
message = get('/projects')
return message
@eel.expose
def get_users():
"""Get the users."""
message = get('/users')
return message
@eel.expose
def get_user():
"""Get the current user object."""
users = get_users()
user = next(x for x in users if x['email'] == config['user'])
message = get('/users/{}/'.format(user['id']))
# print(message)
return message
@eel.expose
def get_time_records(user_id):
"""Get the time records for a user."""
message = get('/users/{}/time-records'.format(user_id))
return message
@eel.expose
def get_tasks():
"""Get all tasks."""
tasks = []
for project in get_projects():
for task in get('/projects/{}/tasks'.format(project['id']))['tasks']:
tasks.append(task)
return tasks
@eel.expose
def get_tasks_by_project(project_id):
"""Get the tasks for a specific project."""
message = get('/projects/{}/tasks'.format(project_id))
return message
@eel.expose
def complete_task(task_id):
"""Get complete a given task."""
message = put('/complete/task/{}'.format(task_id))
return message
@eel.expose
def create_time_record(project_id, task_id, job_type_id, date, time_value, billable, summary):
users = get_users()
user = next(x for x in users if x['email'] == config['user'])
data = {
'value': time_value,
'task_id': task_id if task_id else None,
'user_id': user['id'],
'job_type_id': job_type_id,
'record_date': date,
'billable_status': billable,
'summary': summary,
}
url = '/projects/{}/time-records'.format(project_id)
return post(url, data)
@eel.expose
def list_daily_time_records(date, offset):
users = get_users()
user = next(x for x in users if x['email'] == config['user'])
r = get_time_records(user['id'])
time_records = r['time_records']
# Adjusting for current timezone.
daily_time_records = [x for x in time_records if abs(x['record_date'] - (date - offset)) <= 3600]
return daily_time_records
eel.init('web')
eel.start('index.html', size=(400, 600), options={
'port': 8888
})