{"id":17928581,"url":"https://github.com/alifeee/telegram-budgeter","last_synced_at":"2025-04-03T11:12:35.979Z","repository":{"id":158333614,"uuid":"633986895","full_name":"alifeee/telegram-budgeter","owner":"alifeee","description":"A Telegram bot to help you keep track of daily average spending over time. Stores data in a Google Spreadsheet so you can view it anytime easily.","archived":false,"fork":false,"pushed_at":"2024-02-19T00:04:10.000Z","size":492,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-28T16:49:57.173Z","etag":null,"topics":["google-sheets","gspread","telegram-bot"],"latest_commit_sha":null,"homepage":"https://t.me/daily_budgeter_bot","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alifeee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-28T18:40:12.000Z","updated_at":"2024-11-28T15:14:36.000Z","dependencies_parsed_at":"2024-02-19T01:06:53.920Z","dependency_job_id":null,"html_url":"https://github.com/alifeee/telegram-budgeter","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alifeee%2Ftelegram-budgeter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alifeee%2Ftelegram-budgeter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alifeee%2Ftelegram-budgeter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alifeee%2Ftelegram-budgeter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alifeee","download_url":"https://codeload.github.com/alifeee/telegram-budgeter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246989749,"owners_count":20865331,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["google-sheets","gspread","telegram-bot"],"created_at":"2024-10-28T21:04:12.048Z","updated_at":"2025-04-03T11:12:35.961Z","avatar_url":"https://github.com/alifeee.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Telegram Budgeter\n\nThis is a project to run on a server which sends me a Telegram message every day asking how much I spent the day before. The idea is to keep track of average daily spending.\n\n![Chat with \"Bank Bot\": \"How much did you spend yesterday?\" - \"12.98\" - \"New average: 19.45\"](images/conversation.png)\n\n## Requirements\n\n| Requirement | Version |\n| ----------- | ------- |\n| Python      | 3.11.1  |\n| Google Sheets | - |\n\n## Commands\n\n### Set up environment\n\n```bash\npython3 -m venv env\n```\n\n### Install dependencies\n\n```bash\npip install -r requirements.txt\n```\n\n### Test\n\n```bash\npytest\nptw # Run with watch\n```\n\n### Run\n\n```bash\npython3 ./bot.py\n```\n\n## Google Credentials\n\nCredentials are stored in `google_credentials.json`. Follow the [gspread \"Service Account\" guide][gspread-guide] to set up a service account and download the credentials JSON file.\n\n```json\n{\n  \"type\": \"service_account\",\n  \"project_id\": \"telegram-budgeter\",\n  \"private_key_id\": \"[PRIVATE KEY ID]\",\n  \"private_key\": \"[PRIVATE KEY]\",\n  \"client_email\": \"...@....gserviceaccount.com\",\n  \"client_id\": \"[CLIENT ID]\",\n  ...\n}\n```\n\n[gspread-guide]: https://docs.gspread.org/en/latest/oauth2.html#for-bots-using-service-account\n\n## Telegram\n\n### Credentials\n\nTo obtain an access token for telegram, see [help page](https://github.com/python-telegram-bot/python-telegram-bot/wiki/Introduction-to-the-API), but in essence, talk to the [BotFather](https://t.me/botfather).\n\nThe access token is used via an environment variable, or a `.env` file, which is not tracked by git.\n\nAlso in the environment should be an \"admin ID\", where errors are sent via the error handler.\n\n```bash\ntouch .env\n```\n\n```.env\nTELEGRAM_BOT_ACCESS_TOKEN=...\nADMIN_USER_ID=...\n```\n\n### Change commands\n\nTo change the commands, talk to the [BotFather](https://t.me/botfather) and use the `/setcommands` command.\n\n```text\n/setcommands\n...\nstats - Get spending statistics\nspreadsheet - Get spreadsheet URL\nspend - Set a day's spend\nremind - Set reminders on/off\nstart - Set spreadsheet/restart\nhelp - See help\nprivacy - See privacy information\ncancel - cancel the current operation\n```\n\n## Persistent data\n\nTo store each user's Google Sheet ID, a persistent pickle file is used. This is not tracked by git. This uses the [Persistence API](https://github.com/python-telegram-bot/python-telegram-bot/wiki/Making-your-bot-persistent) from [python-telegram-bot][ptb].\n\n[ptb]: https://github.com/python-telegram-bot/python-telegram-bot/\n\n```python\npersistent_data = PicklePersistence(filepath=\"bot_data.pickle\")\napplication = Application.builder().token(API_KEY).persistence(persistent_data).build()\n```\n\n## Deploy on remote server\n\n### Initial deployment\n\n```bash\nssh $USER@$SERVER\ncd ~/python\ngit clone https://github.com/alifeee/telegram-budgeter.git\ncd telegram-budgeter\nsudo apt-get update\nsudo apt install python3.10-venv\n\ncd ~/python/telegram-budgeter\npython3 -m venv env\npip install -r requirements.txt\n# set up service\ncp telegram-budgeter.service /etc/systemd/system/telegram-budgeter.service\nsudo systemctl enable telegram-budgeter.service\nsudo systemctl start telegram-budgeter.service\nsudo systemctl status telegram-budgeter.service\n```\n\n#### Move over secrets\n\n```bash\nscp google_credentials.json $USER@$SERVER:~/python/telegram-budgeter/\nscp .env $USER@$SERVER:~/python/telegram-budgeter/\n```\n\n### Update deployment\n\n```bash\nssh $USER@$SERVER\ncd ~/python/telegram-budgeter\ngit pull\n# repeat \"set up service\" above\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falifeee%2Ftelegram-budgeter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falifeee%2Ftelegram-budgeter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falifeee%2Ftelegram-budgeter/lists"}