Last change
on this file since 775e15e 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:
763 bytes
|
Rev | Line | |
---|
[527b93f] | 1 |
|
---|
| 2 | import psycopg2
|
---|
| 3 | import config_read
|
---|
| 4 | import sys
|
---|
| 5 |
|
---|
| 6 | file_path = 'outputfile.txt'
|
---|
| 7 | sys.stdout = open(file_path, "w")
|
---|
| 8 |
|
---|
| 9 | # Call to read the configuration file and connect to database
|
---|
| 10 | cinfo = config_read.get_databaseconfig("postgresdb.config")
|
---|
| 11 | db_connection = psycopg2.connect(
|
---|
| 12 | database=cinfo[0],
|
---|
| 13 | host=cinfo[1],
|
---|
| 14 | user=cinfo[2],
|
---|
| 15 | password=cinfo[3]
|
---|
| 16 | )
|
---|
| 17 |
|
---|
| 18 | cur = db_connection.cursor()
|
---|
| 19 |
|
---|
| 20 | cur.execute('SELECT id, model FROM phones;')
|
---|
| 21 | phones = cur.fetchall()
|
---|
| 22 |
|
---|
| 23 | for phone in phones:
|
---|
| 24 | cur.execute('SELECT COUNT(*) FROM phone_offers WHERE phone_id='+str(phone[0])+';')
|
---|
| 25 |
|
---|
| 26 | total_offers = cur.fetchone()[0]
|
---|
| 27 |
|
---|
| 28 | cur.execute('UPDATE phones SET total_offers='+str(total_offers)+' WHERE id='+str(phone[0])+';')
|
---|
| 29 | db_connection.commit()
|
---|
| 30 |
|
---|
| 31 |
|
---|
| 32 | cur.close()
|
---|
| 33 | db_connection.close() |
---|
Note:
See
TracBrowser
for help on using the repository browser.