Last change
on this file since d66b8eb was e5b84dc, checked in by Marko <Marko@…>, 2 years ago |
Prototype version
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Line | |
---|
1 | import unicodedata
|
---|
2 | from datetime import datetime
|
---|
3 |
|
---|
4 | import psycopg2
|
---|
5 | import config_read
|
---|
6 | from bs4 import BeautifulSoup
|
---|
7 | import requests
|
---|
8 |
|
---|
9 | import sys
|
---|
10 |
|
---|
11 | file_path = 'outputfile.txt'
|
---|
12 | sys.stdout = open(file_path, "w")
|
---|
13 |
|
---|
14 | # Call to read the configuration file and connect to database
|
---|
15 | cinfo = config_read.get_databaseconfig("postgresdb.config")
|
---|
16 | db_connection = psycopg2.connect(
|
---|
17 | database=cinfo[0],
|
---|
18 | host=cinfo[1],
|
---|
19 | user=cinfo[2],
|
---|
20 | password=cinfo[3]
|
---|
21 | )
|
---|
22 | cur = db_connection.cursor()
|
---|
23 |
|
---|
24 | cur.execute('SELECT * FROM PHONES ORDER BY id')
|
---|
25 |
|
---|
26 | db_connection.commit()
|
---|
27 | phones = cur.fetchall()
|
---|
28 |
|
---|
29 | for phone in phones:
|
---|
30 | print(phone)
|
---|
31 | phone_id = phone[0]
|
---|
32 | cur.execute('SELECT phone_offers.image_url FROM phone_offers JOIN phones ON'
|
---|
33 | ' phone_offers.phone_id = phones.id WHERE '
|
---|
34 | 'phones.id='+str(phone_id)+' AND phone_offers.image_url IS NOT NULL LIMIT 1')
|
---|
35 | tuple_image = cur.fetchone()
|
---|
36 | if tuple_image is not None:
|
---|
37 | print(tuple_image[0])
|
---|
38 | cur.execute('UPDATE phones SET image_url = \''+tuple_image[0]+'\' WHERE id='+str(phone_id));
|
---|
39 | db_connection.commit()
|
---|
40 | else:
|
---|
41 | print('None');
|
---|
42 |
|
---|
43 |
|
---|
44 | cur.close()
|
---|
45 | db_connection.close() |
---|
Note:
See
TracBrowser
for help on using the repository browser.