-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.py
31 lines (25 loc) · 808 Bytes
/
db.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import sqlite3
import traceback
import requests
from secrets import TABLE_NAME, DB_NAME, BOT_TOKEN, CHAT_ID
con = sqlite3.connect(f"{DB_NAME}.db")
cur = con.cursor()
def insert_data(title, url, date):
cur.execute(
f"""CREATE TABLE IF NOT EXISTS {TABLE_NAME}
(id INTEGER PRIMARY KEY AUTOINCREMENT,title TEXT, url TEXT type UNIQUE, date TEXT)"""
)
try:
cur.execute(
f"INSERT INTO {TABLE_NAME} (title, url,date) VALUES"
f" ('{title}','{url}','{date}')"
)
con.commit()
requests.get(
f"https://api.telegram.org/bot{BOT_TOKEN}/sendMessage?chat_id={CHAT_ID}&text={url}"
)
print(title)
except sqlite3.IntegrityError:
pass
except Exception:
traceback.print_exc()