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 diff --git a/code/bot.py b/code/bot.py index 402b15cb0..9f308cecc 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,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): diff --git a/code/user.py b/code/user.py index 892618e13..d642ff064 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,11 +365,28 @@ def create_chart(self, userid): 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): """