Skip to content

Commit 308536b

Browse files
committed
updated commands and files
renamed dockerfile, added support for month balance, updated readme
1 parent 6f7fb15 commit 308536b

File tree

7 files changed

+46
-5
lines changed

7 files changed

+46
-5
lines changed
File renamed without changes.

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
# Description
2+
This is the first version of my telegram bot which allows a simple expenses tracker.
23

3-
## Installtion
4-
* First create the `master.txt` and `token.txt` files, filled respectively with your master chat id and telegram bot token
4+
The bot can now take income and outcome and display the current month resume; here is a list of commands:
5+
* `/listoutcome` print the list of current month outcome
6+
* `/listincome` print the list of current month income
7+
* `/delete +/-<income/outcome amount> <comment>` delete the specified entry
8+
* `/balance` print total income, total outcome and the difference between those 2 (aka balance)
9+
* `+<income amount> <comment>` add to the income table the amount and the comment associated
10+
* `-<outcome amount> <comment>` add to the outcome table the amount and the comment associated
11+
12+
## Installation
13+
* First create the `master.txt` and `token.txt` files, filled respectively with your master chat id
14+
and telegram bot token
15+
* `Install docker`
16+
* Go into the clone folder and run `docker build moneytrakerBot/`
17+
* Copy the container id
18+
* Run `docker run <container id>`
572 Bytes
Binary file not shown.
222 Bytes
Binary file not shown.

bot.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ def text_handler(text, chat_id):
7070
message = "Current month income list:\n\n"
7171
for r in rows:
7272
message = message + str(r).replace("(", "").replace(")", "").replace("'", "") + "\n"
73+
total_income = db.get_total_income(month)
74+
message = message+"\n\nTotal income: "+str(total_income)+" €"
7375
else:
7476
message = "No income to be displayed here " + emoji["openhands"]
7577
elif text == "/listoutcome":
@@ -80,8 +82,21 @@ def text_handler(text, chat_id):
8082
message = "Current month outcome list:\n\n"
8183
for r in rows:
8284
message = message+str(r).replace("(", "").replace(")", "").replace("'", "")+"\n"
85+
total_outcome = db.get_total_income(month)
86+
message = message+"\n\nTotal income: "+str(total_outcome)+" €"
8387
else:
8488
message = "No income to be displayed here " + emoji["openhands"]
89+
elif text == "/balance":
90+
month = datetime.now().strftime("%m")
91+
total_income = db.get_total_income(month)
92+
if total_income is None:
93+
total_income = 0.0
94+
total_outcome = db.get_total_outcome(month)
95+
if total_outcome is None:
96+
total_outcome = 0.0
97+
logging.info(total_outcome)
98+
balance = total_income + total_outcome
99+
message = "Current month balance: "+str(balance)+" €\n\n\nTotal income: "+str(total_income)+" €\n\nTotal outcome: "+str(total_outcome)+" €"
85100
handler.send_message(message, chat_id)
86101

87102

dbHelper.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,24 @@ def get_income(self, month):
4444
rows = cur.fetchall()
4545
return rows
4646

47+
def get_total_income(self, month):
48+
cur = self.conn.cursor()
49+
stmt = "SELECT SUM(value) FROM income WHERE strftime('%m', date) = '" + month + "'"
50+
cur.execute(stmt)
51+
total = cur.fetchone()
52+
return total[0]
53+
4754
def get_outcome(self, month):
4855
cur = self.conn.cursor()
4956
stmt = "SELECT * FROM outcome WHERE strftime('%m', date) = '"+month+"'"
5057
cur.execute(stmt)
5158
rows = cur.fetchall()
5259
return rows
60+
61+
def get_total_outcome(self, month):
62+
cur = self.conn.cursor()
63+
stmt = "SELECT SUM(value) FROM outcome WHERE strftime('%m', date) = '" + month + "'"
64+
cur.execute(stmt)
65+
total = cur.fetchone()
66+
return total[0]
67+

requirements.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
1-
sqlite3
2-
logging
3-
datetime
41
requests==2.22.0
52
urllib3==1.24.2

0 commit comments

Comments
 (0)