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 | |
---|
1 | import json
|
---|
2 | import psycopg2
|
---|
3 | import requests
|
---|
4 | import config_read
|
---|
5 | import sys
|
---|
6 |
|
---|
7 | file_path = 'outputfile.txt'
|
---|
8 | sys.stdout = open(file_path, "w")
|
---|
9 |
|
---|
10 | phones = json.loads(requests.get('http://localhost:8080/phones').text)
|
---|
11 |
|
---|
12 | for 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.