Last change
on this file since fd5b100 was 895cd87, checked in by Marko <Marko@…>, 2 years ago |
Refactored code
|
-
Property mode
set to
100644
|
File size:
769 bytes
|
Line | |
---|
1 | import json
|
---|
2 | import requests
|
---|
3 | import classes.phone
|
---|
4 | import sys
|
---|
5 |
|
---|
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 | for phone in phones:
|
---|
12 | phone_id = str(phone['id'])
|
---|
13 | offers = list(json.loads(requests.get('http://localhost:8080/phones/offers/' + phone_id).text))
|
---|
14 |
|
---|
15 | offers = list(filter(lambda offer: offer['image_url'] is not None, offers))
|
---|
16 |
|
---|
17 | image_url = None
|
---|
18 |
|
---|
19 | if len(offers) > 0:
|
---|
20 | image_url = offers[0]['image_url']
|
---|
21 |
|
---|
22 | phone['image_url'] = image_url
|
---|
23 |
|
---|
24 | # UPDATE DATABASE WITH NEW IMAGE URLS FOR PHONES
|
---|
25 | headers = {'Content-type': 'application/json'}
|
---|
26 | requests.put('http://localhost:8080/setimageurl/' + phone_id, headers=headers, data=phone['image_url']) |
---|
Note:
See
TracBrowser
for help on using the repository browser.