source: phonelux_scrappers/phones_image_setter.py

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