source: phonelux_scrappers/lowest_price_setter.py@ 895cd87

Last change on this file since 895cd87 was 895cd87, checked in by Marko <Marko@…>, 21 months ago

Refactored code

  • Property mode set to 100644
File size: 689 bytes
RevLine 
[895cd87]1import json
[527b93f]2import psycopg2
[895cd87]3import requests
[527b93f]4import config_read
5import sys
6
7file_path = 'outputfile.txt'
8sys.stdout = open(file_path, "w")
9
[895cd87]10phones = json.loads(requests.get('http://localhost:8080/phones').text)
[527b93f]11
12for phone in phones:
[895cd87]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.