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
RevLine 
[895cd87]1import json
[e5b84dc]2import requests
[895cd87]3import classes.phone
[e5b84dc]4import sys
5
[895cd87]6
[e5b84dc]7file_path = 'outputfile.txt'
8sys.stdout = open(file_path, "w")
9
[895cd87]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))
[e5b84dc]14
[895cd87]15 offers = list(filter(lambda offer: offer['image_url'] is not None, offers))
[e5b84dc]16
[895cd87]17 image_url = None
[e5b84dc]18
[895cd87]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.