-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconec.py
More file actions
59 lines (45 loc) · 1.79 KB
/
conec.py
File metadata and controls
59 lines (45 loc) · 1.79 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import sqlite3
def create_db_and_table():
# Создаем подключение к базе данных (файл my_database.db будет создан)
connection = sqlite3.connect('db_cities.db')
cursor = connection.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS Cites (
name TEXT NOT NULL,
link TEXT NOT NULL
)
''')
connection.close()
default_city()
def default_city():
connection = sqlite3.connect('db_cities.db')
cursor = connection.cursor()
# Добавляем нового пользователя
cursor.execute('INSERT INTO Cites (name, link) VALUES (?, ?)', ('Челябинск', 'https://t.me/+fUYi5TIQZudkNjli'))
cursor.execute('INSERT INTO Cites (name, link) VALUES (?, ?)', ('Екатеринбург', 'https://t.me/+i1n2u7yTb0cwZjVi'))
cursor.execute('INSERT INTO Cites (name, link) VALUES (?, ?)', ('Пермь', 'https://t.me/+seLoCbBb_3o0OTgy'))
# Сохраняем изменения и закрываем соединение
connection.commit()
connection.close()
def get_cities():
connection = sqlite3.connect('db_cities.db')
cursor = connection.cursor()
cursor.execute('SELECT name FROM Cites')
cities = cursor.fetchall()
return cities
def get_link(city):
connection = sqlite3.connect('db_cities.db')
cursor = connection.cursor()
cursor.execute("SELECT link FROM Cites WHERE name = ?", (city,))
link = cursor.fetchall()
return link[0][0]
def update_link_city(city, link):
try:
connection = sqlite3.connect('db_cities.db')
cursor = connection.cursor()
cursor.execute('UPDATE Cites SET link = ? WHERE name = ?', (link, city))
connection.commit()
connection.close()
return True
except:
return False