Skip to content

Commit bb531fd

Browse files
committed
cleanup
1 parent 3c33cc7 commit bb531fd

File tree

9 files changed

+167
-17
lines changed

9 files changed

+167
-17
lines changed

Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ LABEL version="0.0.1"
3131
STOPSIGNAL SIGINT
3232

3333
RUN apk update && \
34-
apk --no-cache --update add libstdc++ && \
34+
apk --no-cache --update add libstdc++ jq netcat-openbsd curl wget && \
3535
rm -rf /var/cache/apk/*
3636

3737

3838
WORKDIR /app
3939
COPY --from=build-env /app /app
40-
ENV PATH="/app/venv/bin:$PATH"
40+
RUN chmod a+x wait-for-http && chmod a+x entrypoint
41+
ENV PATH="/app/venv/bin:/app:$PATH"
4142

42-
ENTRYPOINT ["/app/venv/bin/python", "main.py"]
43+
ENTRYPOINT ["python", "main.py"]

bundle/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.env
2+
data-folder/

bundle/docker-compose.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
version: '3.4'
2+
3+
services:
4+
taxerapi:
5+
image: maxsivkov/taxerapi
6+
environment:
7+
- "TAXER_COOKIES=${TAXER_COOKIES}"
8+
- "PORT=80"
9+
- "HOST=0.0.0.0"
10+
ports:
11+
- "7080:80"
12+
statements:
13+
image: maxsivkov/bank-statements
14+
depends_on:
15+
- taxerapi
16+
environment:
17+
- "BSTMT_TAXER_API_URL=http://taxerapi"
18+
volumes:
19+
- ./data-folder:/app/data
20+
entrypoint: ["entrypoint"]

datadir.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ def __init__(self, config:confuse.Configuration):
7272

7373
self.update_conf()
7474

75+
self.verbose = config['verbose'].as_number()
7576
taxer_config: TaxerConfig = TaxerConfig()
7677
taxer_config.host = self.url
77-
taxer_config.debug = True
78+
taxer_config.debug = True if self.verbose else False
7879
cli: TaxerClient = TaxerClient(configuration=taxer_config)
7980
self.acc_api = TaxerAccountApi(api_client=cli)
8081
self.accs_api = TaxerAccountsApi(api_client=cli)
8182
self.operation_api = TaxerOperationApi(api_client=cli)
8283

83-
self.verbose = config['verbose'].as_number()
8484
self.logger.info(f'config_dir {config.config_dir()}')
8585
self.logger.info(f'user_config_path {config.user_config_path()}')
8686
self.logger.info(f'accounts_folder \'{self.accounts_folder}\'')

doc/how-to-run-docker-lazy.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
## Запуск с использованием Docker
2+
3+
- Запустить АПИ сервер [Taxer API](https://github.com/maxsivkov/py-taxer-api)
4+
- Открыть коммандную строку `cmd`
5+
- Запуск
6+
```
7+
docker run -it --rm maxsivkov/bank-statements test
8+
```
9+
В результате в выводе должно появиться чтото типа `Action test`
10+

doc/how-to-run-docker.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
## Запуск с использованием Docker
2+
3+
- Запустить АПИ сервер [Taxer API](https://github.com/maxsivkov/py-taxer-api)
4+
- Открыть коммандную строку `cmd`
5+
- Запуск
6+
```
7+
docker run -it --rm maxsivkov/bank-statements test
8+
```
9+
В результате в выводе должно появиться чтото типа `Action test`
10+

entrypoint

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
echo Checking $BSTMT_TAXER_API_URL then running $@
3+
wait-for-http $BSTMT_TAXER_API_URL/docs -- python main.py $@

main.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from datadir import DataDir
99
from stmt_driver_xlsx import XlsxDriver
1010
from utils import list_files, get_config_str, get_config_int
11+
from taxerapi import Profile
1112

1213

1314
def setup_logger(filename:str):
@@ -101,18 +102,16 @@ def setup_logger(filename:str):
101102
processed_files = processed_files + 1
102103
print(f'DONE. Processed {processed_files} statements')
103104

104-
def get_request():
105-
import requests
106-
r = requests.get('http://atlaz.win/~maxx/1.json')
107-
d:Dict = r.json()
108-
print(d)
109-
110-
print('status')
111-
112-
print(d["status"])
113-
114105
if config['action'].as_str() == 'test':
115-
print(f'Action {config["action"].as_str()}')
116-
#get_request()
106+
logger.info(f'\nAction {config["action"].as_str()}\n')
107+
logger.info(f'Requesting Profile from TaxerApi')
108+
profile: Profile = d.acc_api.get_account_api()
109+
logger.info(f'Account id: {profile.account_id}')
110+
logger.info(f'Account name: {profile.account_name}')
111+
logger.info(f'Account users list')
112+
for user in profile.users:
113+
logger.info(f' user_id: {user.id}')
114+
logger.info(f' user_tax: {user.id_key}')
115+
logger.info(f' user_title: {user.title_name}')
117116

118117
#https://www.ibancalculator.com/iban_validieren.html

wait-for-http

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#!/bin/sh
2+
3+
TIMEOUT=150
4+
QUIET=0
5+
WAITFOR_RETRY_DELAY=0.1
6+
7+
echoerr() {
8+
if [ "$QUIET" -ne 1 ]; then printf "%s\n" "$*" 1>&2; fi
9+
}
10+
11+
usage() {
12+
exitcode="$1"
13+
cat << USAGE >&2
14+
Usage:
15+
$cmdname host:port|url [-t timeout] [-- command args]
16+
-q | --quiet Do not output any status messages
17+
-t TIMEOUT | --timeout=timeout Timeout in seconds, zero for no timeout
18+
-- COMMAND ARGS Execute command with args after the test finishes
19+
USAGE
20+
exit "$exitcode"
21+
}
22+
23+
wait_for() {
24+
for i in `seq $TIMEOUT` ; do
25+
nc -z "$HOST" "$PORT" > /dev/null 2>&1
26+
27+
result=$?
28+
if [ $result -eq 0 ] ; then
29+
if [ $# -gt 0 ] ; then
30+
exec "$@"
31+
fi
32+
exit 0
33+
fi
34+
sleep $WAITFOR_RETRY_DELAY
35+
done
36+
echo "Operation timed out" >&2
37+
exit 1
38+
}
39+
40+
wait_for_http() {
41+
for i in `seq $TIMEOUT` ; do
42+
wget --timeout=1 -q "$WAITFOR_URL" -O /dev/null > /dev/null 2>&1
43+
44+
result=$?
45+
if [ $result -eq 0 ] ; then
46+
if [ $# -gt 0 ] ; then
47+
exec "$@"
48+
fi
49+
exit 0
50+
fi
51+
sleep $WAITFOR_RETRY_DELAY
52+
done
53+
echo "Operation timed out" >&2
54+
exit 1
55+
}
56+
57+
while [ $# -gt 0 ]
58+
do
59+
case "$1" in
60+
http*)
61+
WAITFOR_URL=$1
62+
shift 1
63+
;;
64+
*:* )
65+
HOST=$(printf "%s\n" "$1"| cut -d : -f 1)
66+
PORT=$(printf "%s\n" "$1"| cut -d : -f 2)
67+
shift 1
68+
;;
69+
-q | --quiet)
70+
QUIET=1
71+
shift 1
72+
;;
73+
-t)
74+
TIMEOUT="$2"
75+
if [ "$TIMEOUT" = "" ]; then break; fi
76+
shift 2
77+
;;
78+
--timeout=*)
79+
TIMEOUT="${1#*=}"
80+
shift 1
81+
;;
82+
--)
83+
shift
84+
break
85+
;;
86+
--help)
87+
usage 0
88+
;;
89+
*)
90+
echoerr "Unknown argument: $1"
91+
usage 1
92+
;;
93+
esac
94+
done
95+
96+
if [ "$HOST" = "" -o "$PORT" = "" ] && [ "$WAITFOR_URL" = "" ]; then
97+
echoerr "Error: you need to provide a host and port OR an URL to test."
98+
usage 2
99+
fi
100+
101+
if [ "$WAITFOR_URL" != "" ]; then
102+
wait_for_http "$@"
103+
else
104+
wait_for "$@"
105+
fi

0 commit comments

Comments
 (0)