# Path: endorsements/models.py
# class Tag(models.Model):
#     name = models.CharField(max_length=50)
#     description = models.TextField(blank=True)
#     is_personal = models.BooleanField(default=True)
#     category = models.ForeignKey(Category, null=True, blank=True)
# 
#     def __unicode__(self):
#         return self.name
# 
#     class Meta:
#         ordering = ['name']
# 
#     def get_mode(self):
#         allow_personal = self.category.allow_personal
#         allow_org = self.category.allow_org
#         if allow_personal and allow_org:
#             return 'none'
#         elif allow_personal:
#             return 'personal'
#         else:
#             return 'organization'
# 
# class Candidate(models.Model):
#     endorser_link = models.OneToOneField(Endorser)
#     name = models.CharField(max_length=50)
#     description = models.TextField()
#     color = models.CharField(max_length=6)
#     rgb = models.CharField(max_length=13)
#     still_running = models.BooleanField(default=False)
#     position = models.OneToOneField('Position', blank=True, null=True)
# 
#     def __unicode__(self):
#         return self.name
# 
# Path: wikipedia/models.py
# class BulkImport(models.Model):
#     slug = models.SlugField(max_length=255)
#     created_at = models.DateTimeField(auto_now_add=True)
#     text = models.TextField()
# 
#     def __unicode__(self):
#         return str(self.created_at)
# 
# class ImportedResult(models.Model):
#     bulk_import = models.ForeignKey(BulkImport)
#     tag = models.ForeignKey(Tag)
#     candidate = models.ForeignKey(Candidate)
#     count = models.PositiveIntegerField(default=0)
#     percent = models.DecimalField(max_digits=4, decimal_places=2)
# 
#     class Meta:
#         unique_together = ('tag', 'candidate')


from datetime import datetime
from BeautifulSoup import BeautifulSoup as BS
from django.core.management.base import BaseCommand, CommandError
from endorsements.models import Tag, Candidate
from wikipedia.models import BulkImport, ImportedResult
import requests
                        (table_cells[11].string or '0').replace(',', '')
                    ),
                    'percent': float(
                        (table_cells[12].string or '0').strip('%')
                    ),
                },
                'Evan McMullin': {
                    'count': int(
                        (table_cells[14].string or '0').replace(',', '')
                    ),
                    'percent': float(
                        (table_cells[15].string or '0').strip('%')
                    ),
                }
            }

            results[state] = stats

        if options['create']:
            print "About to create", len(results)
            bulk_import = BulkImport.objects.create(
                slug=SLUG,
                text=text
            )
            for state, stats in results.iteritems():
                for candidate, candidate_stats in stats.iteritems():
                    print state
                    ImportedResult.objects.create(
                        bulk_import=bulk_import,
                        tag=Tag.objects.get(name=state),

# Path: endorsements/models.py
# class Tag(models.Model):
#     name = models.CharField(max_length=50)
#     description = models.TextField(blank=True)
#     is_personal = models.BooleanField(default=True)
#     category = models.ForeignKey(Category, null=True, blank=True)
# 
#     def __unicode__(self):
#         return self.name
# 
#     class Meta:
#         ordering = ['name']
# 
#     def get_mode(self):
#         allow_personal = self.category.allow_personal
#         allow_org = self.category.allow_org
#         if allow_personal and allow_org:
#             return 'none'
#         elif allow_personal:
#             return 'personal'
#         else:
#             return 'organization'
# 
# class Candidate(models.Model):
#     endorser_link = models.OneToOneField(Endorser)
#     name = models.CharField(max_length=50)
#     description = models.TextField()
#     color = models.CharField(max_length=6)
#     rgb = models.CharField(max_length=13)
#     still_running = models.BooleanField(default=False)
#     position = models.OneToOneField('Position', blank=True, null=True)
# 
#     def __unicode__(self):
#         return self.name
# 
# Path: wikipedia/models.py
# class BulkImport(models.Model):
#     slug = models.SlugField(max_length=255)
#     created_at = models.DateTimeField(auto_now_add=True)
#     text = models.TextField()
# 
#     def __unicode__(self):
#         return str(self.created_at)
# 
# class ImportedResult(models.Model):
#     bulk_import = models.ForeignKey(BulkImport)
#     tag = models.ForeignKey(Tag)
#     candidate = models.ForeignKey(Candidate)
#     count = models.PositiveIntegerField(default=0)
#     percent = models.DecimalField(max_digits=4, decimal_places=2)
# 
#     class Meta:
#         unique_together = ('tag', 'candidate')


# Path: wikipedia/management/commands/importresults.py
from datetime import datetime
from BeautifulSoup import BeautifulSoup as BS
from django.core.management.base import BaseCommand, CommandError
from endorsements.models import Tag, Candidate
from wikipedia.models import BulkImport, ImportedResult
import requests

                        (table_cells[11].string or '0').replace(',', '')
                    ),
                    'percent': float(
                        (table_cells[12].string or '0').strip('%')
                    ),
                },
                'Evan McMullin': {
                    'count': int(
                        (table_cells[14].string or '0').replace(',', '')
                    ),
                    'percent': float(
                        (table_cells[15].string or '0').strip('%')
                    ),
                }
            }

            results[state] = stats

        if options['create']:
            print "About to create", len(results)
            bulk_import = BulkImport.objects.create(
                slug=SLUG,
                text=text
            )
            for state, stats in results.iteritems():
                for candidate, candidate_stats in stats.iteritems():
                    print state
                    ImportedResult.objects.create(
                        bulk_import=bulk_import,
                        tag=Tag.objects.get(name=state),

                        candidate=Candidate.objects.get(name=candidate),