Finish saving & loading projects-clients mapping from Harvest API and document
This commit is contained in:
parent
e1a2b0cd8b
commit
6aaaffd45b
4 changed files with 26 additions and 6 deletions
|
@ -41,6 +41,15 @@ cd parse-timelogs-for-upload
|
||||||
python -m pip install --user -r requirements.txt
|
python -m pip install --user -r requirements.txt
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Create local environments file
|
||||||
|
|
||||||
|
In a `.env` file, put your Harvest account ID and access token, both of which you can get at https://id.getharvest.com/
|
||||||
|
|
||||||
|
```
|
||||||
|
HARVEST_ACCESS_TOKEN=12345.pt.6W7wKRJEsG73NaNwBWBhv_5rQz1YkiC7_0U-OuYNnYZlMh4xP-HvmloBlrFcpJ5ZbT666HJOhNo3tXispFz4wk
|
||||||
|
HARVEST_ACCOUNT_ID=123456
|
||||||
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import urllib.request
|
import urllib.request
|
||||||
from dotenv import load_dotenv
|
# Import our local settings management.
|
||||||
|
import settings
|
||||||
|
|
||||||
|
# Allow HARVEST_ACCESS_TOKEN etc to be loaded from a .env file.
|
||||||
|
from dotenv import load_dotenv
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
url = "https://api.harvestapp.com/v2/projects?updated_since=2021-05-01"
|
url = "https://api.harvestapp.com/v2/projects?is_active=true"
|
||||||
headers = {
|
headers = {
|
||||||
"User-Agent": "Python Harvest API",
|
"User-Agent": "Python Harvest API",
|
||||||
"Authorization": "Bearer " + os.environ.get("HARVEST_ACCESS_TOKEN"),
|
"Authorization": "Bearer " + os.environ.get("HARVEST_ACCESS_TOKEN"),
|
||||||
|
@ -24,4 +27,4 @@ projects = {}
|
||||||
for project in api_projects["projects"]:
|
for project in api_projects["projects"]:
|
||||||
projects[project["name"]] = project["client"]["name"]
|
projects[project["name"]] = project["client"]["name"]
|
||||||
|
|
||||||
|
settings.harvest_set_projects_clients_map(projects)
|
||||||
|
|
|
@ -177,9 +177,7 @@ harvest = hrvst.rename(columns = {'date': 'Date', 'project': 'Project', 'subproj
|
||||||
harvest["Hours"] = harvest["time"]/60
|
harvest["Hours"] = harvest["time"]/60
|
||||||
harvest["First name"] = "Benjamin"
|
harvest["First name"] = "Benjamin"
|
||||||
harvest["Last name"] = "Melançon"
|
harvest["Last name"] = "Melançon"
|
||||||
project_client_mapping = {
|
project_client_mapping = settings.harvest_get_projects_clients_map()
|
||||||
"": "",
|
|
||||||
}
|
|
||||||
harvest["Client"] = harvest["Project"].map(project_client_mapping)
|
harvest["Client"] = harvest["Project"].map(project_client_mapping)
|
||||||
harvest.drop(columns = ['started', 'recorded', 'time'], inplace=True)
|
harvest.drop(columns = ['started', 'recorded', 'time'], inplace=True)
|
||||||
|
|
||||||
|
|
10
settings.py
10
settings.py
|
@ -1,11 +1,14 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import configparser
|
import configparser
|
||||||
|
import json
|
||||||
import os
|
import os
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config['pomodoro'] = {}
|
config['pomodoro'] = {}
|
||||||
pomodoro = config['pomodoro']
|
pomodoro = config['pomodoro']
|
||||||
|
config['harvest'] = {}
|
||||||
|
harvest = config['harvest']
|
||||||
|
|
||||||
def write():
|
def write():
|
||||||
with open('settings.ini', 'w') as configfile:
|
with open('settings.ini', 'w') as configfile:
|
||||||
|
@ -37,3 +40,10 @@ def pomodoro_latest_recorded(timestamp = None):
|
||||||
write()
|
write()
|
||||||
else:
|
else:
|
||||||
return pomodoro.get('latest_recorded', None)
|
return pomodoro.get('latest_recorded', None)
|
||||||
|
|
||||||
|
def harvest_set_projects_clients_map(projects_clients_map = {}):
|
||||||
|
config.set('harvest', 'projects_clients', json.dumps(projects_clients_map))
|
||||||
|
write()
|
||||||
|
|
||||||
|
def harvest_get_projects_clients_map():
|
||||||
|
return json.loads(harvest['projects_clients'])
|
||||||
|
|
Loading…
Reference in a new issue