Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,8 @@ No setup required! Try our production bot here: https://t.me/mydollarbotprod_bot

8. BotFather will now confirm the creation of your bot and provide a TOKEN to access the HTTP API - copy this token for future use.

9. In the directory where this repo has been cloned, navigate to the "code" folder and open the "code.py" file. This file consists of a variable by the name "api_token". Paste the token copied in step 8 in the placeholder provided for this variable:
```
api_token = "INSERT API KEY HERE"
```
9. Search for "Edit the system environment variables" on your local computer. Click on Environment Variables and create a new System Variable called "API_TOKEN" and paste the token copied in step 8.

10. In the Telegram app, search for your newly created bot by entering the username and open the same. Once this is done, go back to the terminal session. Navigate to the directory containing the "code.py" file and run the following command:
```
python code/bot.py
Expand Down
20 changes: 16 additions & 4 deletions code/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
import telebot
from telebot import types

from code.user import User
# from code.user import User
from user import User

api_token = os.environ["API_TOKEN"]
commands = {
Expand Down Expand Up @@ -990,11 +991,22 @@ def get_chart(message):
:param message:
:return: None
"""
# Original Code

# chat_id = str(message.chat.id)
# chart_file = user_list[chat_id].create_chart(chat_id)
# with open(chart_file, "rb") as f:
# bot.send_photo(chat_id, f)
# bot.send_photo(chat_id, chart_file)

# Modified Code
chat_id = str(message.chat.id)
chart_file = user_list[chat_id].create_chart(chat_id)
with open(chart_file, "rb") as f:
bot.send_photo(chat_id, f)
bot.send_photo(chat_id, chart_file)
for cf in chart_file:
with open(cf, "rb") as f:
bot.send_photo(chat_id, f)
# bot.send_photo(chat_id, cf)



def create_header(user):
Expand Down
24 changes: 21 additions & 3 deletions code/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,18 +357,36 @@ def create_chart(self, userid):
"""
labels = []
totals = []
charts = []
for category in self.spend_categories:
total = 0
for transaction in self.transactions[category]:
total = total + transaction["Value"]
if total != 0:
labels.append(category)
totals.append(total)
plt.switch_backend("Agg")

# Pie Chart
plt.clf()
plt.pie(totals, labels=labels)
plt.title("Your Expenditure Report")
plt.savefig("data/{}_chart.png".format(userid))
return "data/{}_chart.png".format(userid)
plt.savefig("data/{}_pie_chart.png".format(userid)) # Ensure that the file name is unique
charts.append("data/{}_pie_chart.png".format(userid)) # Ensure that the file name is unique

# Bar Graph
plt.clf()
plt.switch_backend("Agg")
plt.title("Your Expenditure Report")
plt.bar(labels, totals)
plt.xlabel('Categories')
plt.ylabel('Expenditure')
plt.title("Your Expenditure Report")
plt.savefig("data/{}_bar_chart.png".format(userid)) # Ensure that the file name is unique
charts.append("data/{}_bar_chart.png".format(userid)) # Ensure that the file name is unique

# Add more visualizations here. Maintain the above format while adding more visualizations.

return charts

def add_category(self, new_category, userid):
"""
Expand Down