source: phonelux_scrappers/phones_image_setter.py@ 895cd87

Last change on this file since 895cd87 was 895cd87, checked in by Marko <Marko@…>, 21 months ago

Refactored code

  • Property mode set to 100644
File size: 769 bytes
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 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.