source: phonelux_scrappers/lowest_price_setter.py

Last change on this file was 895cd87, checked in by Marko <Marko@…>, 2 years ago

Refactored code

  • Property mode set to 100644
File size: 689 bytes
Line 
1import json
2import psycopg2
3import requests
4import config_read
5import sys
6
7file_path = 'outputfile.txt'
8sys.stdout = open(file_path, "w")
9
10phones = json.loads(requests.get('http://localhost:8080/phones').text)
11
12for phone in phones:
13 phone_id = str(phone['id'])
14 print(phone['model'])
15
16 offers = list(json.loads(requests.get('http://localhost:8080/phones/offers/' + phone_id).text))
17 offers.sort(key=lambda o: o['price'])
18 lowest_price = str(0)
19 if len(offers) > 0:
20 lowest_price = str(offers[0]['price'])
21 print(lowest_price)
22
23 # UPDATE DATABASE WITH NEW LOWEST PRICE
24 requests.put('http://localhost:8080/setlowestprice/' + phone_id + '/' + lowest_price)
Note: See TracBrowser for help on using the repository browser.