Last change
on this file since 47f4eaf was 895cd87, checked in by Marko <Marko@…>, 2 years ago |
Refactored code
|
-
Property mode
set to
100644
|
File size:
689 bytes
|
Rev | Line | |
---|
[895cd87] | 1 | import json
|
---|
[527b93f] | 2 | import psycopg2
|
---|
[895cd87] | 3 | import requests
|
---|
[527b93f] | 4 | import config_read
|
---|
| 5 | import sys
|
---|
| 6 |
|
---|
| 7 | file_path = 'outputfile.txt'
|
---|
| 8 | sys.stdout = open(file_path, "w")
|
---|
| 9 |
|
---|
[895cd87] | 10 | phones = json.loads(requests.get('http://localhost:8080/phones').text)
|
---|
[527b93f] | 11 |
|
---|
| 12 | for 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.