source: phonelux_scrappers/lowest_price_setter.py@ 48f3030

Last change on this file since 48f3030 was 527b93f, checked in by Marko <Marko@…>, 22 months ago

Setter for phone's total offers and setter for phone's lowest price created

  • Property mode set to 100644
File size: 930 bytes
Line 
1
2import psycopg2
3import config_read
4
5import sys
6
7file_path = 'outputfile.txt'
8sys.stdout = open(file_path, "w")
9
10# Call to read the configuration file and connect to database
11cinfo = config_read.get_databaseconfig("postgresdb.config")
12db_connection = psycopg2.connect(
13 database=cinfo[0],
14 host=cinfo[1],
15 user=cinfo[2],
16 password=cinfo[3]
17)
18cur = db_connection.cursor()
19
20cur.execute('SELECT id,model FROM phones ORDER BY id;')
21
22phones = cur.fetchall()
23
24for phone in phones:
25 phone_id = str(phone[0])
26 print('id: '+phone_id)
27 cur.execute('SELECT offer_name,price FROM phone_offers WHERE phone_id=' + phone_id + ' ORDER BY price;')
28 details = cur.fetchone()
29 lowestPrice = None
30
31 if details is not None:
32 lowestPrice = details[1]
33 cur.execute('UPDATE phones SET lowest_price='+str(lowestPrice)+' WHERE id='+phone_id+';')
34 db_connection.commit()
35
36cur.close()
37db_connection.close()
Note: See TracBrowser for help on using the repository browser.