old_contents: import logging
  
  from bs4 import BeautifulSoup
  from django.conf import settings
  from django.core.management import BaseCommand
  import requests
  
  # TODO: Implement models.
  # from days.apps.days.models import Event
  
  
  logger = logging.getLogger(__name__)
  url = 'https://en.wikipedia.org/wiki/May_21'
  
  class Command(BaseCommand):
      help = 'Scrape historical events from Wikipedia.'
  
      def add_arguments(self, parser):
          parser.add_argument(
              '-c', '--commit',
              action='store_true',
              dest='commit',
              default=False,
              help='Save event data to the database.'
          )
  
      def handle(self, *args, **options):
          commit = options.get('commit')
  
          response = requests.get(url)
          soup = BeautifulSoup(response.text, 'html.parser')
          uls = soup.find_all('ul')
          events_section = uls[1]
  
          events = []
          for event in events_section.children:
              if event != '\n':
                  # http://www.fileformat.info/info/unicode/char/2013/index.htm
                  events.append(event.text.split(' – '))
  
          logger.info('Scraped %d events', len(events))
  
new_contents: import datetime
  import logging
  
  from bs4 import BeautifulSoup
  from django.conf import settings
  from django.core.management.base import BaseCommand
  from django.db import transaction
  from django.utils import timezone
  import requests
  
  from days.apps.days.models import Event
  
  
  logger = logging.getLogger(__name__)
  
  
  class ForcedRollback(Exception):
      pass
  
  
  class Command(BaseCommand):
      help = 'Scrape historical events from Wikipedia.'
      url = 'https://en.wikipedia.org/wiki'
  
      def add_arguments(self, parser):
          parser.add_argument(
              '-t', '--target',
              action='store',
              dest='target',
              default=None,
              help=(
                  'Month and day for which to scrape events, specified as a %%m-%%d formatted string. '
                  'Defaults to the current date (UTC).'
              )
          )
  
          parser.add_argument(
              '-c', '--commit',
              action='store_true',
              dest='commit',
              default=False,
              help='Save event data to the database. By default, no data is saved.'
          )
  
      def handle(self, *args, **options):
          target = options.get('target')
          commit = options.get('commit')
  
          if target:
              target = datetime.datetime.strptime(target, '%m-%d').date()
          else:
              target = timezone.now().date()
  
          url = '{base_url}/{month_day}'.format(
              base_url=self.url,
              month_day=target.strftime('%B_%-d')
          )
  
          response = requests.get(url)
          soup = BeautifulSoup(response.text, 'html.parser')
          uls = soup.find_all('ul')
          events = uls[1]
  
          try:
              with transaction.atomic():
                  count = 0
                  for event in events.children:
                      if event != '\n':
                          year, description = event.text.split(' – ')
  
                          if any(c.isalpha() for c in year):
                              # TODO: Figure out how to handle BC years. DateField and BooleanField combo?
                              logger.debug('Found a year containing letters: [%s]. Ignoring event.', year)
                              continue
  
                          date = datetime.date(int(year), target.month, target.day)
                          Event.objects.create(date=date, description=description)
  
                          count += 1
  
                  logger.info('Scraped %d events', count)
  
                  if not commit:
                      raise ForcedRollback(
                          'No data has been saved. To save data, pass the -c or --commit flags.'
                      )
          except ForcedRollback as e:
              logger.info(e)
  
subject: Use Event model to store scraped events