source: phonelux_scrappers/phone_total_offers.py@ 775e15e

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