doyu commited on
Commit
b7a1682
1 Parent(s): 76a8cb9

implement uoh_software_project_time_report.project

Browse files
README.md CHANGED
@@ -17,7 +17,14 @@ pip install uoh_software_project_time_report
17
  Fill me in please! Don’t forget code examples:
18
 
19
  ``` python
20
- 1+1
 
21
  ```
22
 
23
- 2
 
 
 
 
 
 
 
17
  Fill me in please! Don’t forget code examples:
18
 
19
  ``` python
20
+ pr = Project('key.json')
21
+ pr
22
  ```
23
 
24
+ 1DNoNf4glcuMxKoVzHVrFo-MktmsVji1wf4IHeraWH84
25
+
26
+ ``` python
27
+ pr.get()
28
+ ```
29
+
30
+ [['name', 'backlog item #', 'hours spent']]
nbs/00_core.ipynb DELETED
@@ -1,61 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "markdown",
5
- "metadata": {},
6
- "source": [
7
- "# core\n",
8
- "\n",
9
- "> Fill in a module description here"
10
- ]
11
- },
12
- {
13
- "cell_type": "code",
14
- "execution_count": null,
15
- "metadata": {},
16
- "outputs": [],
17
- "source": [
18
- "#| default_exp core"
19
- ]
20
- },
21
- {
22
- "cell_type": "code",
23
- "execution_count": null,
24
- "metadata": {},
25
- "outputs": [],
26
- "source": [
27
- "#| hide\n",
28
- "from nbdev.showdoc import *"
29
- ]
30
- },
31
- {
32
- "cell_type": "code",
33
- "execution_count": null,
34
- "metadata": {},
35
- "outputs": [],
36
- "source": [
37
- "#| export\n",
38
- "def foo(): pass"
39
- ]
40
- },
41
- {
42
- "cell_type": "code",
43
- "execution_count": null,
44
- "metadata": {},
45
- "outputs": [],
46
- "source": [
47
- "#| hide\n",
48
- "import nbdev; nbdev.nbdev_export()"
49
- ]
50
- }
51
- ],
52
- "metadata": {
53
- "kernelspec": {
54
- "display_name": "Python 3 (ipykernel)",
55
- "language": "python",
56
- "name": "python3"
57
- }
58
- },
59
- "nbformat": 4,
60
- "nbformat_minor": 4
61
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
nbs/00_project.ipynb ADDED
@@ -0,0 +1,224 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "#| default_exp project"
10
+ ]
11
+ },
12
+ {
13
+ "cell_type": "markdown",
14
+ "metadata": {},
15
+ "source": [
16
+ "# project\n",
17
+ "\n",
18
+ "> A simple API for handling time spent in a project"
19
+ ]
20
+ },
21
+ {
22
+ "cell_type": "code",
23
+ "execution_count": null,
24
+ "metadata": {},
25
+ "outputs": [],
26
+ "source": [
27
+ "#| hide\n",
28
+ "from nbdev.showdoc import *\n",
29
+ "from fastcore.test import *"
30
+ ]
31
+ },
32
+ {
33
+ "cell_type": "code",
34
+ "execution_count": null,
35
+ "metadata": {},
36
+ "outputs": [],
37
+ "source": [
38
+ "#| export\n",
39
+ "from fastcore.utils import *"
40
+ ]
41
+ },
42
+ {
43
+ "cell_type": "code",
44
+ "execution_count": null,
45
+ "metadata": {},
46
+ "outputs": [],
47
+ "source": [
48
+ "#| hide\n",
49
+ "import nbdev; nbdev.nbdev_export()"
50
+ ]
51
+ },
52
+ {
53
+ "cell_type": "code",
54
+ "execution_count": null,
55
+ "metadata": {},
56
+ "outputs": [],
57
+ "source": [
58
+ "#| export\n",
59
+ "from googleapiclient.discovery import build\n",
60
+ "from google.oauth2 import service_account"
61
+ ]
62
+ },
63
+ {
64
+ "cell_type": "code",
65
+ "execution_count": null,
66
+ "metadata": {},
67
+ "outputs": [],
68
+ "source": [
69
+ "#| export\n",
70
+ "class __Project():\n",
71
+ " \"Project (time) data handler\"\n",
72
+ " def __init__(self,\n",
73
+ " scopes: list, # google apis authentication scopes,\n",
74
+ " fn: str, # service account file name\n",
75
+ " sid: str): # spreadsheet id\n",
76
+ " creds = service_account.Credentials.from_service_account_file(fn, scopes=scopes)\n",
77
+ " service = build('sheets', 'v4', credentials=creds)\n",
78
+ " self.sheet = service.spreadsheets()\n",
79
+ " self.sid = sid\n",
80
+ " def __str__(self): return f\"{self.sid}\"\n",
81
+ " __repr__=__str__"
82
+ ]
83
+ },
84
+ {
85
+ "cell_type": "code",
86
+ "execution_count": null,
87
+ "metadata": {},
88
+ "outputs": [],
89
+ "source": [
90
+ "#| export\n",
91
+ "SERVICE_ACCOUNT_FILE = '../keys.json'\n",
92
+ "SCOPES = ['https://www.googleapis.com/auth/spreadsheets']\n",
93
+ "SPREADSHEET_ID = '1DNoNf4glcuMxKoVzHVrFo-MktmsVji1wf4IHeraWH84'\n",
94
+ "\n",
95
+ "class Project(__Project):\n",
96
+ " def __init__(self,\n",
97
+ " fn: str): # service account file name\n",
98
+ " super(Project, self).__init__(SCOPES, SERVICE_ACCOUNT_FILE, SPREADSHEET_ID)"
99
+ ]
100
+ },
101
+ {
102
+ "cell_type": "markdown",
103
+ "metadata": {},
104
+ "source": [
105
+ "Project() prints spread sheet id, `sid`."
106
+ ]
107
+ },
108
+ {
109
+ "cell_type": "code",
110
+ "execution_count": null,
111
+ "metadata": {},
112
+ "outputs": [],
113
+ "source": [
114
+ "pr = Project(SERVICE_ACCOUNT_FILE)"
115
+ ]
116
+ },
117
+ {
118
+ "cell_type": "code",
119
+ "execution_count": null,
120
+ "metadata": {},
121
+ "outputs": [],
122
+ "source": [
123
+ "#| export\n",
124
+ "@patch\n",
125
+ "def get(self:Project,\n",
126
+ " sname:str=\"\"): # a worksheet name can be specified. If not the 1st sheet is choosen.\n",
127
+ " range = f\"{sname}!\" if sname else \"\"\n",
128
+ " range += \"A1:Z1000\"\n",
129
+ " result = self.sheet.values().get(spreadsheetId=self.sid,\n",
130
+ " range=range).execute()\n",
131
+ " values = result.get('values', [])\n",
132
+ " return values"
133
+ ]
134
+ },
135
+ {
136
+ "cell_type": "markdown",
137
+ "metadata": {},
138
+ "source": [
139
+ "For instance, here's some tests of equality"
140
+ ]
141
+ },
142
+ {
143
+ "cell_type": "code",
144
+ "execution_count": null,
145
+ "metadata": {},
146
+ "outputs": [
147
+ {
148
+ "data": {
149
+ "text/plain": [
150
+ "[['3/1/2022', '4000'], ['4/4/2022', '3000'], ['7/12/2022', '7000']]"
151
+ ]
152
+ },
153
+ "execution_count": null,
154
+ "metadata": {},
155
+ "output_type": "execute_result"
156
+ }
157
+ ],
158
+ "source": [
159
+ "pr.get(\"Test\")"
160
+ ]
161
+ },
162
+ {
163
+ "cell_type": "code",
164
+ "execution_count": null,
165
+ "metadata": {},
166
+ "outputs": [],
167
+ "source": [
168
+ "#| export\n",
169
+ "@patch\n",
170
+ "def put(self:Project,\n",
171
+ " data:list,\n",
172
+ " sname:str=\"\"): # a worksheet name can be specified. If not the 1st sheet is choosen.\n",
173
+ " range = f\"{sname}!\" if sname else \"\"\n",
174
+ " range += \"A1\"\n",
175
+ " request = self.sheet.values().update(spreadsheetId=self.sid,\n",
176
+ " range=range,\n",
177
+ " valueInputOption=\"USER_ENTERED\",\n",
178
+ " body={\"values\":data})\n",
179
+ " response = request.execute()"
180
+ ]
181
+ },
182
+ {
183
+ "cell_type": "code",
184
+ "execution_count": null,
185
+ "metadata": {},
186
+ "outputs": [],
187
+ "source": [
188
+ "data = [[\"3/1/2022\", \"4000\"],[\"4/4/2022\", \"3000\"],[\"7/12/2022\", \"7000\"]]\n",
189
+ "pr.put(data, \"Test\")\n",
190
+ "pr.get(\"Test\")\n",
191
+ "test_eq(pr.get(\"Test\"), data)"
192
+ ]
193
+ },
194
+ {
195
+ "cell_type": "code",
196
+ "execution_count": null,
197
+ "metadata": {},
198
+ "outputs": [
199
+ {
200
+ "data": {
201
+ "text/plain": [
202
+ "[['name', 'backlog item #', 'hours spent'], ['Hiroshi Doyu', '25', '1']]"
203
+ ]
204
+ },
205
+ "execution_count": null,
206
+ "metadata": {},
207
+ "output_type": "execute_result"
208
+ }
209
+ ],
210
+ "source": [
211
+ "pr.get()"
212
+ ]
213
+ }
214
+ ],
215
+ "metadata": {
216
+ "kernelspec": {
217
+ "display_name": "Python 3 (ipykernel)",
218
+ "language": "python",
219
+ "name": "python3"
220
+ }
221
+ },
222
+ "nbformat": 4,
223
+ "nbformat_minor": 4
224
+ }
nbs/index.ipynb CHANGED
@@ -7,7 +7,7 @@
7
  "outputs": [],
8
  "source": [
9
  "#| hide\n",
10
- "from uoh_software_project_time_report.core import *"
11
  ]
12
  },
13
  {
@@ -64,7 +64,7 @@
64
  {
65
  "data": {
66
  "text/plain": [
67
- "2"
68
  ]
69
  },
70
  "execution_count": null,
@@ -73,15 +73,29 @@
73
  }
74
  ],
75
  "source": [
76
- "1+1"
 
77
  ]
78
  },
79
  {
80
  "cell_type": "code",
81
  "execution_count": null,
82
  "metadata": {},
83
- "outputs": [],
84
- "source": []
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  }
86
  ],
87
  "metadata": {
 
7
  "outputs": [],
8
  "source": [
9
  "#| hide\n",
10
+ "from uoh_software_project_time_report.project import *"
11
  ]
12
  },
13
  {
 
64
  {
65
  "data": {
66
  "text/plain": [
67
+ "1DNoNf4glcuMxKoVzHVrFo-MktmsVji1wf4IHeraWH84"
68
  ]
69
  },
70
  "execution_count": null,
 
73
  }
74
  ],
75
  "source": [
76
+ "pr = Project('key.json')\n",
77
+ "pr"
78
  ]
79
  },
80
  {
81
  "cell_type": "code",
82
  "execution_count": null,
83
  "metadata": {},
84
+ "outputs": [
85
+ {
86
+ "data": {
87
+ "text/plain": [
88
+ "[['name', 'backlog item #', 'hours spent'], ['Hiroshi Doyu', '25', '1']]"
89
+ ]
90
+ },
91
+ "execution_count": null,
92
+ "metadata": {},
93
+ "output_type": "execute_result"
94
+ }
95
+ ],
96
+ "source": [
97
+ "pr.get()"
98
+ ]
99
  }
100
  ],
101
  "metadata": {
nbs/sidebar.yml ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ website:
2
+ sidebar:
3
+ contents:
4
+ - index.ipynb
5
+ - 00_project.ipynb
uoh_software_project_time_report/_modidx.py CHANGED
@@ -5,5 +5,17 @@ d = { 'settings': { 'branch': 'main',
5
  'doc_host': 'https://doyu.github.io',
6
  'git_url': 'https://github.com/doyu/uoh-software-project-time-report',
7
  'lib_path': 'uoh_software_project_time_report'},
8
- 'syms': { 'uoh_software_project_time_report.core': { 'uoh_software_project_time_report.core.foo': ( 'core.html#foo',
9
- 'uoh_software_project_time_report/core.py')}}}
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  'doc_host': 'https://doyu.github.io',
6
  'git_url': 'https://github.com/doyu/uoh-software-project-time-report',
7
  'lib_path': 'uoh_software_project_time_report'},
8
+ 'syms': { 'uoh_software_project_time_report.project': { 'uoh_software_project_time_report.project.Project': ( 'project.html#project',
9
+ 'uoh_software_project_time_report/project.py'),
10
+ 'uoh_software_project_time_report.project.Project.__init__': ( 'project.html#project.__init__',
11
+ 'uoh_software_project_time_report/project.py'),
12
+ 'uoh_software_project_time_report.project.Project.get': ( 'project.html#project.get',
13
+ 'uoh_software_project_time_report/project.py'),
14
+ 'uoh_software_project_time_report.project.Project.put': ( 'project.html#project.put',
15
+ 'uoh_software_project_time_report/project.py'),
16
+ 'uoh_software_project_time_report.project.__Project': ( 'project.html#__project',
17
+ 'uoh_software_project_time_report/project.py'),
18
+ 'uoh_software_project_time_report.project.__Project.__init__': ( 'project.html#__project.__init__',
19
+ 'uoh_software_project_time_report/project.py'),
20
+ 'uoh_software_project_time_report.project.__Project.__str__': ( 'project.html#__project.__str__',
21
+ 'uoh_software_project_time_report/project.py')}}}
uoh_software_project_time_report/core.py DELETED
@@ -1,7 +0,0 @@
1
- # AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/00_core.ipynb.
2
-
3
- # %% auto 0
4
- __all__ = ['foo']
5
-
6
- # %% ../nbs/00_core.ipynb 3
7
- def foo(): pass
 
 
 
 
 
 
 
 
uoh_software_project_time_report/project.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/00_project.ipynb.
2
+
3
+ # %% auto 0
4
+ __all__ = ['SERVICE_ACCOUNT_FILE', 'SCOPES', 'SPREADSHEET_ID', 'Project']
5
+
6
+ # %% ../nbs/00_project.ipynb 3
7
+ from fastcore.utils import *
8
+
9
+ # %% ../nbs/00_project.ipynb 5
10
+ from googleapiclient.discovery import build
11
+ from google.oauth2 import service_account
12
+
13
+ # %% ../nbs/00_project.ipynb 6
14
+ class __Project():
15
+ "Project (time) data handler"
16
+ def __init__(self,
17
+ scopes: list, # google apis authentication scopes,
18
+ fn: str, # service account file name
19
+ sid: str): # spreadsheet id
20
+ creds = service_account.Credentials.from_service_account_file(fn, scopes=scopes)
21
+ service = build('sheets', 'v4', credentials=creds)
22
+ self.sheet = service.spreadsheets()
23
+ self.sid = sid
24
+ def __str__(self): return f"{self.sid}"
25
+ __repr__=__str__
26
+
27
+ # %% ../nbs/00_project.ipynb 7
28
+ SERVICE_ACCOUNT_FILE = '../keys.json'
29
+ SCOPES = ['https://www.googleapis.com/auth/spreadsheets']
30
+ SPREADSHEET_ID = '1DNoNf4glcuMxKoVzHVrFo-MktmsVji1wf4IHeraWH84'
31
+
32
+ class Project(__Project):
33
+ def __init__(self,
34
+ fn: str): # service account file name
35
+ super(Project, self).__init__(SCOPES, SERVICE_ACCOUNT_FILE, SPREADSHEET_ID)
36
+
37
+ # %% ../nbs/00_project.ipynb 10
38
+ @patch
39
+ def get(self:Project,
40
+ sname:str=""): # a worksheet name can be specified. If not the 1st sheet is choosen.
41
+ range = f"{sname}!" if sname else ""
42
+ range += "A1:Z1000"
43
+ result = self.sheet.values().get(spreadsheetId=self.sid,
44
+ range=range).execute()
45
+ values = result.get('values', [])
46
+ return values
47
+
48
+ # %% ../nbs/00_project.ipynb 13
49
+ @patch
50
+ def put(self:Project,
51
+ data:list,
52
+ sname:str=""): # a worksheet name can be specified. If not the 1st sheet is choosen.
53
+ range = f"{sname}!" if sname else ""
54
+ range += "A1"
55
+ request = self.sheet.values().update(spreadsheetId=self.sid,
56
+ range=range,
57
+ valueInputOption="USER_ENTERED",
58
+ body={"values":data})
59
+ response = request.execute()