loadstars fixes

This commit is contained in:
James Turk 2012-06-30 22:13:48 -04:00
parent a65b99d505
commit f698b6da6c

View File

@ -27,7 +27,21 @@ class Command(NoArgsCommand):
name = div.xpath('h2')[0].text_content().strip() name = div.xpath('h2')[0].text_content().strip()
url = div.xpath('a/@href')[0] url = div.xpath('a/@href')[0]
id = url.rsplit('/', 1)[-1] id = url.rsplit('/', 1)[-1]
photo_url = url + div.xpath('a/img/@data-fullsrc')[0] photo_url = 'http://wwe.com' + div.xpath('a/img/@data-fullsrc')[0]
if Star.objects.filter(id=id).count():
star = Star.objects.get(id=id)
if star.name != name:
print('updating {0} name to {1}'.format(star.name, name))
star.name = name
if star.division != division:
print('updating {0} division to {1}'.format(star.name, division))
star.division = division
if star.photo_url != photo_url:
print('updating {0} photo to {1}'.format(star.name.encode('utf8'), photo_url))
star.photo_url = photo_url
star.save()
else:
print('adding {0}'.format(name))
Star.objects.create(id=id, name=name, division=division, Star.objects.create(id=id, name=name, division=division,
photo_url=photo_url) photo_url=photo_url)