Skip to content

Commit

Permalink
Added the feature described in yoda-pa#162
Browse files Browse the repository at this point in the history
  • Loading branch information
Abelarm committed Oct 6, 2018
1 parent 6922431 commit b08d7d6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,14 @@ For tracking money, this is.

![](https://raw.githubusercontent.com/yoda-pa/yoda/master/screencasts/money.gif)

Get your expenses per month
```
$ yoda money exps_month
$ Sep: spent 75 USD
$ Nov: spent 15 USD
$ Dec: spent 125 USD
```

#### Idea list

For creating list of ideas, type
Expand Down
30 changes: 29 additions & 1 deletion modules/money.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,33 @@ def expenses():
currency_name + ' ' + number + ' ' + item)


def expenses_month():
"""
check expenses per month
"""

tmp_dict = {}
default_cur = None
with open(MONEY_CONFIG_FOLDER_PATH + '/expenditures.txt') as fp:
for line in fp.read().split('\n'):
if len(line) == 0:
continue
(date, _time, currency_name, number, item) = shlex.split(line)
y, m, d = list(map(int, date.split('-')))

if m not in tmp_dict:
tmp_dict[m] = float(number)
else:
tmp_dict[m] += float(number)

default_cur = currency_name

import calendar
if len(tmp_dict) != 0:
for k in tmp_dict:
click.echo(calendar.month_abbr[k] + ': spent ' + str(tmp_dict[k]) + ' ' + default_cur)


def check_sub_command(c):
"""
command checker
Expand All @@ -138,7 +165,8 @@ def check_sub_command(c):
'status': status,
'setup': setup,
'exp': expense,
'exps': expenses
'exps': expenses,
'exps_month': expenses_month
}
try:
return sub_commands[c]()
Expand Down
3 changes: 3 additions & 0 deletions tests/test_money.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ def runTest(self):

result = self.runner.invoke(yoda.cli, ['money', 'exps'])
self.assertEqual(result.exit_code, 0)

result = self.runner.invoke(yoda.cli, ['money', 'exps_months'])
self.assertEqual(result.exit_code, 0)

0 comments on commit b08d7d6

Please sign in to comment.