From 64f99d4247b2d77e85c60eb5fa34ca0b119df815 Mon Sep 17 00:00:00 2001 From: moksh98 Date: Thu, 25 Nov 2021 15:21:29 -0500 Subject: [PATCH 1/5] Updated installation step in readme --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 38869cd46..5be014616 100644 --- a/README.md +++ b/README.md @@ -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 From 0fe2564231a4b695c78dd3a6da8e21bb55f5588a Mon Sep 17 00:00:00 2001 From: moksh98 Date: Thu, 25 Nov 2021 15:47:37 -0500 Subject: [PATCH 2/5] added bar graph as visualisation --- code/user.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/code/user.py b/code/user.py index 892618e13..8b66d63db 100644 --- a/code/user.py +++ b/code/user.py @@ -365,7 +365,11 @@ def create_chart(self, userid): labels.append(category) totals.append(total) plt.switch_backend("Agg") - plt.pie(totals, labels=labels) + plt.title("Your Expenditure Report") + plt.bar(labels, totals) + plt.xlabel('Categories') + plt.ylabel('Expenditure') + # plt.pie(totals, labels=labels) plt.title("Your Expenditure Report") plt.savefig("data/{}_chart.png".format(userid)) return "data/{}_chart.png".format(userid) From d6cd69332493502cda188764cbba0939a2318c77 Mon Sep 17 00:00:00 2001 From: moksh98 Date: Thu, 25 Nov 2021 15:52:44 -0500 Subject: [PATCH 3/5] added multiple charts in a list --- code/user.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/code/user.py b/code/user.py index 8b66d63db..747160c93 100644 --- a/code/user.py +++ b/code/user.py @@ -357,6 +357,7 @@ def create_chart(self, userid): """ labels = [] totals = [] + charts = [] for category in self.spend_categories: total = 0 for transaction in self.transactions[category]: @@ -364,15 +365,23 @@ def create_chart(self, userid): if total != 0: labels.append(category) totals.append(total) + + # Bar Graph plt.switch_backend("Agg") plt.title("Your Expenditure Report") plt.bar(labels, totals) plt.xlabel('Categories') plt.ylabel('Expenditure') - # 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/{}_bar_chart.png".format(userid)) + charts.append("data/{}_bar_chart.png".format(userid)) + + # Pie Chart + plt.pie(totals, labels=labels) + plt.title("Your Expenditure Report") + plt.savefig("data/{}_pie_chart.png".format(userid)) + charts.append("data/{}_pie_chart.png".format(userid)) + return charts def add_category(self, new_category, userid): """ From a5c8e74a56f4930d8574195b6cf5c2c3a627a494 Mon Sep 17 00:00:00 2001 From: moksh98 Date: Thu, 25 Nov 2021 16:07:30 -0500 Subject: [PATCH 4/5] Multiple visualizations are being sent as messages --- code/bot.py | 11 +++++++---- code/user.py | 17 ++++++++++------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/code/bot.py b/code/bot.py index 402b15cb0..1f7ee85dd 100644 --- a/code/bot.py +++ b/code/bot.py @@ -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 = { @@ -990,11 +991,13 @@ def get_chart(message): :param message: :return: None """ + 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) + # Send messages for all visualizations created. + for cf in chart_file: + with open(cf, "rb") as f: + bot.send_photo(chat_id, f) def create_header(user): diff --git a/code/user.py b/code/user.py index 747160c93..5ed22f70f 100644 --- a/code/user.py +++ b/code/user.py @@ -366,6 +366,12 @@ def create_chart(self, userid): labels.append(category) totals.append(total) + # Pie Chart + plt.pie(totals, labels=labels) + plt.title("Your Expenditure Report") + 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.switch_backend("Agg") plt.title("Your Expenditure Report") @@ -373,14 +379,11 @@ def create_chart(self, userid): plt.xlabel('Categories') plt.ylabel('Expenditure') plt.title("Your Expenditure Report") - plt.savefig("data/{}_bar_chart.png".format(userid)) - charts.append("data/{}_bar_chart.png".format(userid)) + 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. - # Pie Chart - plt.pie(totals, labels=labels) - plt.title("Your Expenditure Report") - plt.savefig("data/{}_pie_chart.png".format(userid)) - charts.append("data/{}_pie_chart.png".format(userid)) return charts def add_category(self, new_category, userid): From 3d72bd7dd9c4252b2a5f396f71a84aabd9268d7a Mon Sep 17 00:00:00 2001 From: moksh98 Date: Thu, 25 Nov 2021 16:16:37 -0500 Subject: [PATCH 5/5] fixed overlapping chart issue --- code/bot.py | 13 +++++++++++-- code/user.py | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/code/bot.py b/code/bot.py index 1f7ee85dd..9f308cecc 100644 --- a/code/bot.py +++ b/code/bot.py @@ -991,13 +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) - # Send messages for all visualizations created. 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): diff --git a/code/user.py b/code/user.py index 5ed22f70f..d642ff064 100644 --- a/code/user.py +++ b/code/user.py @@ -367,12 +367,14 @@ def create_chart(self, userid): totals.append(total) # Pie Chart + plt.clf() plt.pie(totals, labels=labels) plt.title("Your Expenditure Report") 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)