Skip to content

Commit fb56c07

Browse files
authored
Merge pull request #29 from wilau2/use-docker-env-file
Use docker env file
2 parents 59583b7 + 1bef2a8 commit fb56c07

31 files changed

+166
-140
lines changed

.github/CONTRIBUTING.md

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ Read and follow according template
1717
Read and follow according template
1818

1919

20+
## Run
21+
22+
Read and follow `package.json`
23+
24+
2025
## commitizen + cz-conventional-changelog
2126

2227
https://github.com/commitizen/cz-cli

.github/README.md

-48
This file was deleted.

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM williamlauze/harvest-balance-calculator-infra:latest
22

3-
COPY . /www
3+
COPY src /www
44

55
WORKDIR www
66

HarvestBalanceCalculator/Config/Loader.py

-7
This file was deleted.

HarvestBalanceCalculator/Config/__init__.py

-1
This file was deleted.

HarvestBalanceCalculator/Config/tests/testLoader.py

-16
This file was deleted.

HarvestBalanceCalculator/__init__.pyc

-600 Bytes
Binary file not shown.

README.md

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
[![CircleCI](https://circleci.com/gh/wilau2/harvest-balance-calculator.svg?style=svg)](https://circleci.com/gh/wilau2/harvest-balance-calculator)
2+
3+
# harvest-balance-calculator
4+
5+
Calculate how much overtime or time you owe based on the average hours you should work per weeks.
6+
7+
## Run
8+
9+
```
10+
docker run --env-file ./env.secret williamlauze/harvest-balance-calculator:1.0.0
11+
```
12+
13+
## Setup
14+
create `env.secret` file containing the following information
15+
16+
```
17+
HARVEST_ACCOUNT_ID=
18+
HARVEST_AUTHORIZATION=
19+
BEGIN_DATE='2016-5-2'
20+
END_DATE='2017-11-24'
21+
HOURS_PER_WORK_DAY=7.5
22+
WORK_DAYS_OF_THE_WEEK=0 1 2 3 4
23+
```
24+
25+
## Environment variables details
26+
27+
### HARVEST_ACCOUNT_ID
28+
details [here](https://github.com/wilau2/harvest-balance-calculator/blob/master/docs/harvest-credentials.md)
29+
30+
### HARVEST_AUTHORIZATION
31+
details [here](https://github.com/wilau2/harvest-balance-calculator/blob/master/docs/harvest-credentials.md)
32+
33+
### BEGIN_DATE
34+
The first day you want to count "**included**"
35+
36+
### END_DATE
37+
The last day you want to count "**included**"
38+
39+
### HOURS_PER_WORK_DAY
40+
where 7.5 is 7 hours and 30 minutes
41+
42+
### WORK_DAYS_OF_THE_WEEK
43+
0 is monday
44+
45+
## Github
46+
47+
click [here](https://github.com/wilau2/harvest-balance-calculator/)
48+
49+
## Dockerhub
50+
51+
click [here](https://hub.docker.com/r/williamlauze/harvest-balance-calculator/)
52+
53+
## Timezone
54+
Don't worry !
55+
Harvest will return every time already converted with your timezone
56+
you can make sure your user has the good timezone -> `GET https://api.harvestapp.com/v2/users/me`
57+
58+
## Beer
59+
If you like this project and want to help. You can buy me a beer [here](https://www.paypal.me/williamlauze)

config.json

-6
This file was deleted.

docs/harvest-credentials.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
- Login to [harvest](https://id.getharvest.com/developers)
2+
3+
4+
![alt text](https://github.com/wilau2/harvest-balance-calculator/blob/master/.github/harvest_creds_creation_step1.png)
5+
6+
![alt text](https://github.com/wilau2/harvest-balance-calculator/blob/master/.github/harvest_creds_creation_step2.png)
7+
8+
![alt text](https://github.com/wilau2/harvest-balance-calculator/blob/master/.github/harvest_creds_creation_step3.png)
9+
10+
- Add to following section to your `env.secret`
11+
12+
```
13+
HARVEST_ACCOUNT_ID=123456
14+
HARVEST_AUTHORIZATION=Bearer 65776576576675765765
15+
```

infra/Dockerfile

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ FROM python:3.6.3-alpine3.6
33
RUN pip3 install python-dateutil
44
RUN pip3 install isoweek
55
RUN pip3 install pycodestyle
6+
RUN pip3 install -U "python-dotenv[cli]"
7+

infra/package.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"name": "harvest-balance-calculator-infra",
33
"version": "1.0.0",
4-
"description": "",
5-
"main": "index.js",
4+
"config" : {
5+
"dockerorganization" : "williamlauze"
6+
},
67
"scripts": {
7-
"docker:build": "docker build -t williamlauze/harvest-balance-calculator-infra .",
8-
"docker:push": "docker push williamlauze/harvest-balance-calculator-infra"
8+
"docker:build": "docker build -t ${npm_package_config_dockerorganization}/${npm_package_name} .",
9+
"docker:push": "docker push ${npm_package_config_dockerorganization}/${npm_package_name}"
910
},
10-
"author": "",
11-
"license": "ISC"
11+
"license": "MIT"
1212
}

package.json

+18-15
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
{
22
"name": "harvest-balance-calculator",
3-
"version": "1.0.0",
4-
"description": "With this project you can calculate how much overtime or time you owe based on the average hours you should work per weeks.",
5-
"main": "index.js",
6-
"directories": {
7-
"doc": "docs"
3+
"version": "1.0.1",
4+
"config" : {
5+
"dockerorganization" : "williamlauze"
86
},
97
"scripts": {
10-
"docker:build": "docker build -t harvest-balance-calculator .",
11-
"docker:run": "docker run harvest-balance-calculator",
12-
"docker:teststep": "docker run harvest-balance-calculator python3 -m unittest discover -v",
13-
"docker:codestyle": "docker run harvest-balance-calculator pycodestyle HarvestBalanceCalculator",
14-
"docker:start": "npm run docker:build && npm run docker:run",
8+
"deploy": "npm run deploy:build && npm run deploy:push",
9+
"deploy:build": "docker build -t ${npm_package_config_dockerorganization}/${npm_package_name}:${npm_package_version} .",
10+
"deploy:push": "docker push ${npm_package_config_dockerorganization}/${npm_package_name}:${npm_package_version}",
11+
"start": "npm run start:pull && npm run start:exec",
12+
"start:pull": "docker pull ${npm_package_config_dockerorganization}/${npm_package_name}:${npm_package_version}",
13+
"start:exec": "docker run --env-file ./env.secret ${npm_package_config_dockerorganization}/${npm_package_name}:${npm_package_version}",
14+
"docker:teststep": "docker run ${npm_package_name} python3 -m unittest discover -v",
15+
"docker:codestyle": "docker run ${npm_package_name} pycodestyle HarvestBalanceCalculator",
16+
"docker:build": "docker build -t ${npm_package_name} .",
17+
"docker:start": "docker run --env-file ./env.secret ${npm_package_name}",
1518
"docker:test": "npm run docker:build && npm run docker:codestyle && npm run docker:teststep",
16-
"codestyle": "pipenv run pycodestyle HarvestBalanceCalculator",
17-
"test": "pipenv run python -m unittest discover -v",
18-
"start": "pipenv run python main.py"
19+
"python:codestyle": "pipenv run pycodestyle src",
20+
"python:test": "pipenv run python -m unittest discover -v src",
21+
"python:start": "pipenv run python src/main.py"
1922
},
2023
"repository": {
2124
"type": "git",
2225
"url": "git+https://github.com/wilau2/harvest-balance-calculator.git"
2326
},
24-
"author": "",
25-
"license": "ISC",
27+
"author": "William Lauze",
28+
"license": "MIT",
2629
"bugs": {
2730
"url": "https://github.com/wilau2/harvest-balance-calculator/issues"
2831
},

HarvestBalanceCalculator/WorkingPreference.py src/HarvestBalanceCalculator/WorkingPreference.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import os
2+
3+
14
class WorkingPreference:
2-
def __init__(self, config):
3-
self.config = config
4-
self.workdays = config["workDaysOfTheWeek"]
5-
self.hours_per_day = float(config["hoursPerWorkDay"])
5+
def __init__(self):
6+
self.workdays = list(map(float, os.environ['WORK_DAYS_OF_THE_WEEK'].split()))
7+
self.hours_per_day = float(os.environ['HOURS_PER_WORK_DAY'])
68

79
def is_a_working_day(self, date):
810
return True if date.weekday() in self.workdays else False

HarvestBalanceCalculator/WorkingTimeInterval.py src/HarvestBalanceCalculator/WorkingTimeInterval.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
import os
2+
13
from datetime import timedelta
24
from dateutil.parser import parse
35

46
from HarvestBalanceCalculator import WorkingPreference
57

68

79
class WorkingTimeInterval:
8-
def __init__(self, config):
9-
self.working_preference = WorkingPreference(config)
10-
self.begin_date = parse(config["beginDate"]).date()
11-
self.end_date = parse(config["endDate"]).date()
10+
def __init__(self):
11+
self.working_preference = WorkingPreference()
12+
self.begin_date = parse(os.environ['BEGIN_DATE']).date()
13+
self.end_date = parse(os.environ['END_DATE']).date()
1214

1315
def get_number_of_working_days(self):
1416
delta = (self.end_date - self.begin_date)
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from HarvestBalanceCalculator.Config import Loader
21
from HarvestBalanceCalculator.HarvestTimeEntries import HarvestTimeEntries
32
from HarvestBalanceCalculator.WorkingPreference import WorkingPreference
43
from HarvestBalanceCalculator.WorkingTimeInterval import WorkingTimeInterval

HarvestBalanceCalculator/tests/testWorkingPreference.py src/HarvestBalanceCalculator/tests/testWorkingPreference.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import unittest
2+
import os
23
from datetime import datetime
34
from HarvestBalanceCalculator import WorkingPreference
45

5-
config = {
6-
"workDaysOfTheWeek": [0, 1, 2],
7-
"hoursPerWorkDay": 7
8-
}
9-
working_preference = WorkingPreference(config)
6+
# config = {
7+
# "workDaysOfTheWeek": [0, 1, 2],
8+
# "hoursPerWorkDay": 7
9+
# }
10+
11+
os.environ['WORK_DAYS_OF_THE_WEEK'] = '0 1 2'
12+
os.environ['HOURS_PER_WORK_DAY'] = '7'
13+
14+
working_preference = WorkingPreference()
1015
a_monday = datetime(2016, 5, 2)
1116
a_tuesday = datetime(2016, 5, 3)
1217
a_wednesday = datetime(2016, 5, 4)

HarvestBalanceCalculator/tests/testWorkingTimeInterval.py src/HarvestBalanceCalculator/tests/testWorkingTimeInterval.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import unittest
2+
import os
23
from HarvestBalanceCalculator import WorkingTimeInterval
34

4-
config = {
5-
"beginDate": "2016-5-2",
6-
"endDate": "2016-5-8",
7-
"workDaysOfTheWeek": [0, 1, 2],
8-
"hoursPerWorkDay": 7
9-
}
10-
working_time_interval = WorkingTimeInterval(config)
5+
os.environ['BEGIN_DATE'] = '2016-5-2'
6+
os.environ['END_DATE'] = '2016-5-8'
7+
working_time_interval = WorkingTimeInterval()
118

129

1310
class TestWorkingTimeInterval(unittest.TestCase):

HarvestHttpClient/Client.py src/HarvestHttpClient/Client.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
import http.client
22
import json
3-
4-
from HarvestBalanceCalculator.Config.Loader import load_configuration_file
3+
import os
54

65

76
class HarvestHttpClient:
87
def __init__(self,
9-
config_loader=load_configuration_file,
108
https_connection=http.client.HTTPSConnection):
119
self.HARVEST_API_URL = "api.harvestapp.com"
1210
self.HARVEST_ACCOUNT_ID_HEADER = "Harvest-Account-ID"
1311
self.HARVEST_AUTHORIZATION_HEADER = "Authorization"
1412
self.HARVEST_USER_AGENT = "User-Agent"
1513
self.conn = https_connection(self.HARVEST_API_URL)
16-
secret_config = config_loader('config.json.secret')
1714
self.headers = {
18-
self.HARVEST_ACCOUNT_ID_HEADER: secret_config["harvest"]["accountId"],
19-
self.HARVEST_AUTHORIZATION_HEADER: secret_config["harvest"]["authorization"],
15+
self.HARVEST_ACCOUNT_ID_HEADER: os.environ['HARVEST_ACCOUNT_ID'],
16+
self.HARVEST_AUTHORIZATION_HEADER: os.environ['HARVEST_AUTHORIZATION'],
2017
self.HARVEST_USER_AGENT: "HarvestBalanceCalculator API Example"
2118
}
2219

File renamed without changes.

HarvestHttpClient/tests/testClient.py src/HarvestHttpClient/tests/testClient.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import unittest
2+
import os
23
from datetime import datetime
34
from unittest.mock import MagicMock, Mock
45

56
from HarvestHttpClient import Client
67

78

89
class TestTimeUtils(unittest.TestCase):
10+
os.environ['HARVEST_ACCOUNT_ID'] = 'dumpAccountId'
11+
os.environ['HARVEST_AUTHORIZATION'] = 'dumbAuthorization'
12+
913
def test_get_user_time_entries_when_error(self):
1014
with self.assertRaises(RuntimeError):
1115
self.__given_an_error()
@@ -71,9 +75,7 @@ def __given_an_error(self):
7175

7276
@staticmethod
7377
def __given_http_client_with_secret_config_and_http_client():
74-
harvest_http_client = Client.HarvestHttpClient(MagicMock(return_value={
75-
"harvest": {"accountId": "dumpAccountId", "authorization": "dumbAuthorization"}
76-
}), MagicMock())
78+
harvest_http_client = Client.HarvestHttpClient(MagicMock())
7779
mock = Mock()
7880
mock.status = 200
7981
harvest_http_client.conn.getresponse.return_value = mock
@@ -82,7 +84,5 @@ def __given_http_client_with_secret_config_and_http_client():
8284
return harvest_http_client
8385

8486

85-
86-
8787
if __name__ == '__main__':
8888
unittest.main()

0 commit comments

Comments
 (0)