Last change
on this file since e5b84dc was 527b93f, checked in by Marko <Marko@…>, 2 years 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 |
|
---|
2 | import psycopg2
|
---|
3 | import config_read
|
---|
4 |
|
---|
5 | import sys
|
---|
6 |
|
---|
7 | file_path = 'outputfile.txt'
|
---|
8 | sys.stdout = open(file_path, "w")
|
---|
9 |
|
---|
10 | # Call to read the configuration file and connect to database
|
---|
11 | cinfo = config_read.get_databaseconfig("postgresdb.config")
|
---|
12 | db_connection = psycopg2.connect(
|
---|
13 | database=cinfo[0],
|
---|
14 | host=cinfo[1],
|
---|
15 | user=cinfo[2],
|
---|
16 | password=cinfo[3]
|
---|
17 | )
|
---|
18 | cur = db_connection.cursor()
|
---|
19 |
|
---|
20 | cur.execute('SELECT id,model FROM phones ORDER BY id;')
|
---|
21 |
|
---|
22 | phones = cur.fetchall()
|
---|
23 |
|
---|
24 | for 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 |
|
---|
36 | cur.close()
|
---|
37 | db_connection.close()
|
---|
Note:
See
TracBrowser
for help on using the repository browser.