Are you able to provide an example url or xml file. That would help to
figure out why no listings are created.


On Thu., 13 Jun. 2019, 9:04 am Ewen Le Bihan, <[email protected]>
wrote:

> Hi, where does prof.xml_ky comes from ?
>
> Le mercredi 12 juin 2019 18:22:01 UTC+2, Nuno Vieira a écrit :
>>
>> Hi there.
>>
>> I´m having some problems on parsing a real estate xml to database.
>> The user profile have url field to import properties automatically from
>> xml feed (url). The user can insert mannually or automatically, if the user
>> insert the url feed then it should be able to get the objects and save them
>> to mysql database automatically.
>> The function is not working and i do not know why, gives no error but
>> don´t populate the database.
>>
>> Models.py:
>> class Listing(models.Model):
>> '''Create table listing in db '''
>> realtor = models.ForeignKey(User, on_delete=models.CASCADE)
>> title = models.CharField(max_length=200)
>> address = models.CharField(max_length=200)
>> city = models.CharField(max_length=100)
>> state = models.CharField(max_length=100)
>> zipcode = models.CharField(max_length=20)
>> longitude = models.DecimalField(max_digits=9, decimal_places=6,default=0)
>> latitude = models.DecimalField(max_digits=9, decimal_places=6, default=0)
>> description = models.TextField(blank=True)
>> price = models.IntegerField()
>> bedrooms = models.IntegerField()
>> bathrooms = models.DecimalField(max_digits=2, decimal_places=1)
>> garage = models.IntegerField(default=0)
>> sqmt = models.IntegerField(blank=True)
>> lot_size = models.DecimalField(max_digits=5, decimal_places=1,blank=True)
>> On_Processing = 'On Processing'
>> AMais = 'A+'
>> A = 'A'
>> B = 'B'
>> BMenos = 'B-'
>> C = 'C'
>> D = 'D'
>> E = 'E'
>> F = 'F'
>> ENERGY_RATE_CHOICES = [
>> (On_Processing, 'On Processing'),
>> (AMais, 'A+'),
>> (A, 'A'),
>> (B, 'B'),
>> (BMenos, 'B-'),
>> (C, 'C'),
>> (D, 'D'),
>> (E, 'E'),
>> (F, 'F'),
>> ]
>> energy_rate = models.CharField(
>> max_length=12,
>> choices=ENERGY_RATE_CHOICES,
>> default=On_Processing,
>> )
>> photo_main = models.ImageField(upload_to='photos/%Y/%m/%d/', default=
>> 'default.jpg')
>> photo_main_url = models.URLField(blank = True)
>> is_published = models.BooleanField(default=True)
>> list_date = models.DateTimeField(default=datetime.now, blank=True)
>> video_url = models.CharField(max_length=100, blank=True)
>> virtual_tour = models.URLField(blank=True)
>> visit_num = models.PositiveIntegerField(default=0)
>>
>> def __str__(self):
>> return self.title
>>
>> def get_absolute_url(self):
>> return reverse('listing-detail', kwargs={'pk': self.pk})
>>
>> Function on xml_parse.py:
>> ...
>> 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!
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/20aa727c-d1e8-4d5f-a17d-ac17947ba5f3%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/20aa727c-d1e8-4d5f-a17d-ac17947ba5f3%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAAOisOJ1myL8AfgsmhV35oG_srKzrEm8v%2BeO6L7GOFteokOJgA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to