...
import xml.etree.ElementTree as ET
import requests
from users.models import Profile
def xml_parse(self):
prof_list = Profile.objects.all()
for prof in prof_list:
if prof.xml_ky is not None:
url = xml_ky
response = request.get(url)
with open('xml/%s' % self.id + '/feed.xml', 'wb') as file:
file.write(response.content)
tree = ET.parse('xml/%s' % self.id + '/feed.xml')
root = tree.getroot()
for props in root.iter('property'):
listing, created = Listing.object.create(
title = props.find('type').text + ' ' + props.find('town').text,
address = props.find('location_detail').text,
city = props.find('town').text,
state = props.find('province').text,
zipcode = props.find('zipcode').text,
loc = props.find('location'),
longitude = loc.find('longitude').text,
latitude = loc.find('latitude').text,
desc = props.find('desc'),
description = desc.find('en').text,
price = props.find('price').text,
bedrooms = props.find('beds').text,
bathrooms = props.find('baths').text,
garage = props.find('garage').text,
area = props.find('surface_area'),
sqmt = area.find('built').text,
energy_rate = props.find('energy_rate').text,
realtor = self.request.user,
img = props.find('images'),
image = img.get('id=1'),
image_url = image.find('url').text,
photo_main_url = image_url,
video_url = props.find('video_url').text,
virtual_tour = props.find('virtual_tour').text,
)
if created:
return listing.save()
If you could help me and point me in the right direction it would be great.
Thanks and sorry for the black background!