Spaces:
Runtime error
Runtime error
implement uoh_software_project_time_report.project
Browse filesFiles changed (8)
- README.md+9-2
- nbs/00_core.ipynbDeleted-61
- nbs/00_project.ipynbAdded+224
- nbs/index.ipynb+19-5
- nbs/sidebar.ymlAdded+5
- uoh_software_project_time_report/_modidx.py+14-2
- uoh_software_project_time_report/core.pyDeleted-7
- uoh_software_project_time_report/project.pyAdded+59
16 unmodified lines1718192021222316 unmodified linesFill me in please! Don’t forget code examples:``` python1+1```216 unmodified lines171819202122232425262728293016 unmodified linesFill me in please! Don’t forget code examples:``` pythonpr = Project('key.json')pr```1DNoNf4glcuMxKoVzHVrFo-MktmsVji1wf4IHeraWH84``` pythonpr.get()```[['name', 'backlog item #', 'hours spent']]
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# core\n", "\n", "> Fill in a module description here" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#| default_exp core" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#| hide\n", "from nbdev.showdoc import *" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#| export\n", "def foo(): pass" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#| hide\n", "import nbdev; nbdev.nbdev_export()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 4}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#| default_exp project" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# project\n", "\n", "> A simple API for handling time spent in a project" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#| hide\n", "from nbdev.showdoc import *\n", "from fastcore.test import *" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#| export\n", "from fastcore.utils import *" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#| hide\n", "import nbdev; nbdev.nbdev_export()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#| export\n", "from googleapiclient.discovery import build\n", "from google.oauth2 import service_account" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#| export\n", "class __Project():\n", " \"Project (time) data handler\"\n", " def __init__(self,\n", " scopes: list, # google apis authentication scopes,\n", " fn: str, # service account file name\n", " sid: str): # spreadsheet id\n", " creds = service_account.Credentials.from_service_account_file(fn, scopes=scopes)\n", " service = build('sheets', 'v4', credentials=creds)\n", " self.sheet = service.spreadsheets()\n", " self.sid = sid\n", " def __str__(self): return f\"{self.sid}\"\n", " __repr__=__str__" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#| export\n", "SERVICE_ACCOUNT_FILE = '../keys.json'\n", "SCOPES = ['https://www.googleapis.com/auth/spreadsheets']\n", "SPREADSHEET_ID = '1DNoNf4glcuMxKoVzHVrFo-MktmsVji1wf4IHeraWH84'\n", "\n", "class Project(__Project):\n", " def __init__(self,\n", " fn: str): # service account file name\n", " super(Project, self).__init__(SCOPES, SERVICE_ACCOUNT_FILE, SPREADSHEET_ID)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Project() prints spread sheet id, `sid`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pr = Project(SERVICE_ACCOUNT_FILE)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#| export\n", "@patch\n", "def get(self:Project,\n", " sname:str=\"\"): # a worksheet name can be specified. If not the 1st sheet is choosen.\n", " range = f\"{sname}!\" if sname else \"\"\n", " range += \"A1:Z1000\"\n", " result = self.sheet.values().get(spreadsheetId=self.sid,\n", " range=range).execute()\n", " values = result.get('values', [])\n", " return values" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For instance, here's some tests of equality" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[['3/1/2022', '4000'], ['4/4/2022', '3000'], ['7/12/2022', '7000']]" ] }, "execution_count": null, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pr.get(\"Test\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#| export\n", "@patch\n", "def put(self:Project,\n", " data:list,\n", " sname:str=\"\"): # a worksheet name can be specified. If not the 1st sheet is choosen.\n", " range = f\"{sname}!\" if sname else \"\"\n", " range += \"A1\"\n", " request = self.sheet.values().update(spreadsheetId=self.sid,\n", " range=range,\n", " valueInputOption=\"USER_ENTERED\",\n", " body={\"values\":data})\n", " response = request.execute()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "data = [[\"3/1/2022\", \"4000\"],[\"4/4/2022\", \"3000\"],[\"7/12/2022\", \"7000\"]]\n", "pr.put(data, \"Test\")\n", "pr.get(\"Test\")\n", "test_eq(pr.get(\"Test\"), data)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[['name', 'backlog item #', 'hours spent'], ['Hiroshi Doyu', '25', '1']]" ] }, "execution_count": null, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pr.get()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 4}6 unmodified lines7891011121350 unmodified lines646566676869702 unmodified lines7374757677787980818283848586876 unmodified lines"outputs": [],"source": ["#| hide\n","from uoh_software_project_time_report.core import *"]},{50 unmodified lines{"data": {"text/plain": ["2"]},"execution_count": null,2 unmodified lines}],"source": ["1+1"]},{"cell_type": "code","execution_count": null,"metadata": {},"outputs": [],"source": []}],"metadata": {6 unmodified lines7891011121350 unmodified lines646566676869702 unmodified lines7374757677787980818283848586878889909192939495969798991001016 unmodified lines"outputs": [],"source": ["#| hide\n","from uoh_software_project_time_report.project import *"]},{50 unmodified lines{"data": {"text/plain": ["1DNoNf4glcuMxKoVzHVrFo-MktmsVji1wf4IHeraWH84"]},"execution_count": null,2 unmodified lines}],"source": ["pr = Project('key.json')\n","pr"]},{"cell_type": "code","execution_count": null,"metadata": {},"outputs": [{"data": {"text/plain": ["[['name', 'backlog item #', 'hours spent'], ['Hiroshi Doyu', '25', '1']]"]},"execution_count": null,"metadata": {},"output_type": "execute_result"}],"source": ["pr.get()"]}],"metadata": {
12345website: sidebar: contents: - index.ipynb - 00_project.ipynb4 unmodified lines567894 unmodified lines'doc_host': 'https://doyu.github.io','git_url': 'https://github.com/doyu/uoh-software-project-time-report','lib_path': 'uoh_software_project_time_report'},'syms': { 'uoh_software_project_time_report.core': { 'uoh_software_project_time_report.core.foo': ( 'core.html#foo','uoh_software_project_time_report/core.py')}}}4 unmodified lines567891011121314151617181920214 unmodified lines'doc_host': 'https://doyu.github.io','git_url': 'https://github.com/doyu/uoh-software-project-time-report','lib_path': 'uoh_software_project_time_report'},'syms': { 'uoh_software_project_time_report.project': { 'uoh_software_project_time_report.project.Project': ( 'project.html#project','uoh_software_project_time_report/project.py'),'uoh_software_project_time_report.project.Project.__init__': ( 'project.html#project.__init__','uoh_software_project_time_report/project.py'),'uoh_software_project_time_report.project.Project.get': ( 'project.html#project.get','uoh_software_project_time_report/project.py'),'uoh_software_project_time_report.project.Project.put': ( 'project.html#project.put','uoh_software_project_time_report/project.py'),'uoh_software_project_time_report.project.__Project': ( 'project.html#__project','uoh_software_project_time_report/project.py'),'uoh_software_project_time_report.project.__Project.__init__': ( 'project.html#__project.__init__','uoh_software_project_time_report/project.py'),'uoh_software_project_time_report.project.__Project.__str__': ( 'project.html#__project.__str__','uoh_software_project_time_report/project.py')}}}
1234567# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/00_core.ipynb.
# %% auto 0__all__ = ['foo']
# %% ../nbs/00_core.ipynb 3def foo(): pass1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/00_project.ipynb.
# %% auto 0__all__ = ['SERVICE_ACCOUNT_FILE', 'SCOPES', 'SPREADSHEET_ID', 'Project']
# %% ../nbs/00_project.ipynb 3from fastcore.utils import *
# %% ../nbs/00_project.ipynb 5from googleapiclient.discovery import buildfrom google.oauth2 import service_account
# %% ../nbs/00_project.ipynb 6class __Project(): "Project (time) data handler" def __init__(self, scopes: list, # google apis authentication scopes, fn: str, # service account file name sid: str): # spreadsheet id creds = service_account.Credentials.from_service_account_file(fn, scopes=scopes) service = build('sheets', 'v4', credentials=creds) self.sheet = service.spreadsheets() self.sid = sid def __str__(self): return f"{self.sid}" __repr__=__str__
# %% ../nbs/00_project.ipynb 7SERVICE_ACCOUNT_FILE = '../keys.json'SCOPES = ['https://www.googleapis.com/auth/spreadsheets']SPREADSHEET_ID = '1DNoNf4glcuMxKoVzHVrFo-MktmsVji1wf4IHeraWH84'
class Project(__Project): def __init__(self, fn: str): # service account file name super(Project, self).__init__(SCOPES, SERVICE_ACCOUNT_FILE, SPREADSHEET_ID)
# %% ../nbs/00_project.ipynb 10@patchdef get(self:Project, sname:str=""): # a worksheet name can be specified. If not the 1st sheet is choosen. range = f"{sname}!" if sname else "" range += "A1:Z1000" result = self.sheet.values().get(spreadsheetId=self.sid, range=range).execute() values = result.get('values', []) return values
# %% ../nbs/00_project.ipynb 13@patchdef put(self:Project, data:list, sname:str=""): # a worksheet name can be specified. If not the 1st sheet is choosen. range = f"{sname}!" if sname else "" range += "A1" request = self.sheet.values().update(spreadsheetId=self.sid, range=range, valueInputOption="USER_ENTERED", body={"values":data}) response = request.execute()README.md+9-2
nbs/00_core.ipynbDeleted-61
nbs/00_project.ipynbAdded+224
nbs/index.ipynb+19-5
nbs/sidebar.ymlAdded+5
uoh_software_project_time_report/_modidx.py+14-2
uoh_software_project_time_report/core.pyDeleted-7
uoh_software_project_time_report/project.pyAdded+59