diff --git a/fowl/game/management/commands/loadstars.py b/fowl/game/management/commands/loadstars.py index 178d081..70102e0 100644 --- a/fowl/game/management/commands/loadstars.py +++ b/fowl/game/management/commands/loadstars.py @@ -27,7 +27,21 @@ class Command(NoArgsCommand): name = div.xpath('h2')[0].text_content().strip() url = div.xpath('a/@href')[0] 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] - Star.objects.create(id=id, name=name, division=division, - photo_url=photo_url) + 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, + photo_url=photo_url)