Changeset 895cd87 for phonelux_scrappers/phone_total_offers.py
- Timestamp:
- 10/01/22 22:55:27 (21 months ago)
- Branches:
- master
- Children:
- fd5b100
- Parents:
- 48f3030
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
phonelux_scrappers/phone_total_offers.py
r48f3030 r895cd87 1 import json 1 2 2 3 import psycopg2 4 import requests 3 5 import config_read 4 6 import sys … … 7 9 sys.stdout = open(file_path, "w") 8 10 9 # Call to read the configuration file and connect to database10 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 11 18 cur = db_connection.cursor() 19 20 cur.execute('SELECT id, model FROM phones;') 21 phones = cur.fetchall() 12 phones = json.loads(requests.get('http://localhost:8080/phones').text) 22 13 23 14 for phone in phones: 24 cur.execute('SELECT COUNT(*) FROM phone_offers WHERE phone_id='+str(phone[0])+';')25 15 26 total_offers = cur.fetchone()[0] 16 phone_id = str(phone['id']) 17 totaloffers = requests.get('http://localhost:8080/totaloffers/'+str.join('*', phone['model'].split(' '))).text 27 18 28 cur.execute('UPDATE phones SET total_offers='+str(total_offers)+' WHERE id='+str(phone[0])+';') 29 db_connection.commit() 19 print(phone_id+' - '+totaloffers) 30 20 31 32 cur.close() 33 db_connection.close() 21 # UPDATE DATABASE WITH NEW TOTAL OFFERS 22 requests.put('http://localhost:8080/settotaloffers/' + phone_id + '/' + totaloffers)
Note:
See TracChangeset
for help on using the changeset viewer.