Last change
on this file was 47f4eaf, checked in by Marko <Marko@…>, 2 years ago |
Final features implemented
|
-
Property mode
set to
100644
|
File size:
1.0 KB
|
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 | # remove mobitech condition
|
---|
16 | offers = list(filter(lambda offer: offer['image_url'] is not None and 'mobitech' not in offer['image_url']
|
---|
17 | , offers))
|
---|
18 |
|
---|
19 | image_url = None
|
---|
20 |
|
---|
21 | if len(offers) > 1:
|
---|
22 | image_url = offers[1]['image_url']
|
---|
23 |
|
---|
24 | if len(offers) > 0:
|
---|
25 | image_url = offers[0]['image_url']
|
---|
26 |
|
---|
27 | # print('phone :'+str(phone))
|
---|
28 | # print(image_url)
|
---|
29 | # print('------------------------------')
|
---|
30 |
|
---|
31 | phone['image_url'] = image_url
|
---|
32 |
|
---|
33 | # UPDATE DATABASE WITH NEW IMAGE URLS FOR PHONES
|
---|
34 | headers = {'Content-type': 'application/json'}
|
---|
35 | requests.put('http://localhost:8080/setimageurl/' + phone_id, headers=headers, data=phone['image_url']) |
---|
Note:
See
TracBrowser
for help on using the repository browser.