Skip to content
This repository was archived by the owner on Dec 23, 2023. It is now read-only.

Commit 75e3918

Browse files
committed
2nd init
1 parent cc16364 commit 75e3918

File tree

7 files changed

+167
-0
lines changed

7 files changed

+167
-0
lines changed

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
TRACKER_TELEGRAM_TOKEN=sometoken
2+
DATABASE_URL=someurl

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) [year] [fullname]
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Tele-Tracker Bot
2+
A python telegram bot to help track daily expenses onto google sheet
3+
4+
## Getting Started (Users)
5+
1. Access the bot on [telegram](https://t.me/telefinance_tracker_bot)
6+
2. Use the /start command and follow the instructions given.
7+
3. Remember to edit the `Dropdown` sheet on Google Sheet to get started.
8+
4. Happy using!
9+
10+
## Getting Started (Developers)
11+
### Prerequisites
12+
1. Set up Google Sheet API
13+
2. Set up Firebase Realtime Database / or use SQLite3
14+
3. Retrieve your service accounts for both Google Services and put it under the account folders as service_account.json & firebase_account.json
15+
4. Retrieve your database url and set it under .env
16+
5. Set up telegram bot via [BotFather](https://t.me/BotFather)
17+
6. Retrieve your bot API token and set it under .env
18+
19+
### Installation
20+
1. Clone the repo and run to get required dependencies
21+
```python
22+
pip install -r requirements.txt
23+
```
24+
2. Run
25+
```python
26+
python3 main.py
27+
```
28+
29+
## Usage
30+
/start - Start bot and configure your google sheet
31+
32+
/config - To update your google sheet, or configure quick settings for /addtransports and /addothers
33+
34+
/addentry - To add new entry
35+
36+
/addtranports - To quickly add new transport entry
37+
38+
/addothers - To quickly add others entry
39+
40+
/cancel - To cancel previous conversation with bot
41+
42+
## Pending feature
43+
1. More options for /addothers
44+
2. Use webhook instead of polling
45+
3. Host onto serverless function
46+
47+
## Contributing
48+
49+
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.
50+
51+
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
52+
Don't forget to give the project a star! Thanks again!
53+
54+
1. Fork the Project
55+
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
56+
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
57+
4. Push to the Branch (`git push origin feature/AmazingFeature`)
58+
5. Open a Pull Request
59+
60+
## License
61+
62+
Distributed under the MIT License. See `LICENSE.txt` for more information.
63+
64+
<!-- CONTACT -->
65+
## Contact
66+
67+
Bruce Wang: [email protected]
68+
LinkedIn: [https://www.linkedin.com/in/brucewzj/](https://www.linkedin.com/in/brucewzj/)
69+
Project Link: [https://github.com/brucewzj99/tele-tracker](https://github.com/brucewzj99/tele-tracker)
70+
71+
72+

accounts/firebase_account.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"type": "service_account",
3+
"project_id": "project_id",
4+
"private_key_id": "keyidhere",
5+
"private_key": "privatekeyhere",
6+
"client_email": "iam.gserviceaccount.com",
7+
"client_id": "123",
8+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
9+
"token_uri": "https://oauth2.googleapis.com/token",
10+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
11+
"client_x509_cert_url": "somelinks"
12+
}

accounts/service_account.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"type": "service_account",
3+
"project_id": "project_id",
4+
"private_key_id": "keyidhere",
5+
"private_key": "privatekeyhere",
6+
"client_email": "iam.gserviceaccount.com",
7+
"client_id": "123",
8+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
9+
"token_uri": "https://oauth2.googleapis.com/token",
10+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
11+
"client_x509_cert_url": "somelinks"
12+
}

logfile.txt

Whitespace-only changes.

sql_db.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Import module
2+
import sqlite3
3+
import datetime as dt
4+
5+
# build connection to database
6+
def connect_to_db():
7+
conn = sqlite3.connect('user-tele.db')
8+
return conn
9+
10+
# creating table, first time use only
11+
def first_time_only():
12+
with connect_to_db() as conn:
13+
cursor = conn.cursor()
14+
15+
user_table = '''CREATE TABLE IF NOT EXISTS user_table(
16+
telegram_id VARCHAR(255) PRIMARY KEY,
17+
sheet_id VARCHAR(255));'''
18+
cursor.execute(user_table)
19+
20+
# drop table
21+
def drop_table():
22+
with connect_to_db() as conn:
23+
cursor = conn.cursor()
24+
cursor.execute("DROP TABLE IF EXISTS user_table;")
25+
26+
# first time user, create db records
27+
def new_user_setup(telegram_id, sheet_id):
28+
with connect_to_db() as conn:
29+
cursor = conn.cursor()
30+
day = dt.datetime.now().day
31+
cursor.execute("INSERT OR REPLACE INTO user_table(telegram_id, sheet_id) VALUES (?, ?);", (telegram_id, sheet_id))
32+
cursor.execute("INSERT OR REPLACE INTO tracker_table(telegram_id, transport_row_tracker, other_row_tracker, day_row_tracker, first_row) VALUES (?, ?, ?, ?, ?);", (telegram_id, day, 5, 5, 5))
33+
conn.commit()
34+
return cursor.lastrowid
35+
36+
# check if user exists
37+
def check_if_user_exists(telegram_id):
38+
with connect_to_db() as conn:
39+
cursor = conn.cursor()
40+
cursor.execute("SELECT * FROM user_table WHERE telegram_id = ?", (telegram_id,))
41+
return bool(cursor.fetchone())
42+
43+
# get user sheet id
44+
def get_user_sheet_id(telegram_id):
45+
with connect_to_db() as conn:
46+
cursor = conn.cursor()
47+
cursor.execute("SELECT sheet_id FROM user_table WHERE telegram_id = ?", (telegram_id,))
48+
return cursor.fetchone()[0]

0 commit comments

Comments
 (0)