-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbd.py
More file actions
42 lines (31 loc) · 930 Bytes
/
bd.py
File metadata and controls
42 lines (31 loc) · 930 Bytes
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
import postgresql
import avito
import telebot
from telebot import types
import config
TOKEN = config.TOKEN
bot = telebot.TeleBot(TOKEN)
URL = 'https://www.avito.ru'
objCities = avito.parseLocation(avito.get_html(URL))
db = postgresql.open('pq://postgres:585465077m@localhost:5432/postgres')
def getCitiesFromDb():
cities = db.query('SELECT name FROM city')
arrCities = []
for city in cities:
for item in city:
arrCities.append(item)
return arrCities
def getZn():
links = db.prepare("SELECT user_id, link FROM task_table WHERE active = true")
arrlink = []
for link in links:
items = avito.parse(avito.get_html(link[1]))[:8]
for item in items:
bot.send_message(
link[0],
'{price} \n {link}'.format(price=item['price'], link=item['link'])
)
def main():
getZn()
if __name__ == '__main__':
main()