source: phonelux_scrappers/phones_image_setter.py@ 775e15e

Last change on this file since 775e15e was e5b84dc, checked in by Marko <Marko@…>, 22 months ago

Prototype version

  • Property mode set to 100644
File size: 1.1 KB
Line 
1import unicodedata
2from datetime import datetime
3
4import psycopg2
5import config_read
6from bs4 import BeautifulSoup
7import requests
8
9import sys
10
11file_path = 'outputfile.txt'
12sys.stdout = open(file_path, "w")
13
14# Call to read the configuration file and connect to database
15cinfo = config_read.get_databaseconfig("postgresdb.config")
16db_connection = psycopg2.connect(
17 database=cinfo[0],
18 host=cinfo[1],
19 user=cinfo[2],
20 password=cinfo[3]
21)
22cur = db_connection.cursor()
23
24cur.execute('SELECT * FROM PHONES ORDER BY id')
25
26db_connection.commit()
27phones = cur.fetchall()
28
29for 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
44cur.close()
45db_connection.close()
Note: See TracBrowser for help on using the repository browser.