prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  ValueError while import blog posts from Blogger 
  Hi, when I run the Blogger importer: 
  
  ```
  $ python manage.py import_blogger --mezzanine-user=.. --blogger-id=XXX
  ```
  
  A ValueError is raised:
  
  ``` python
  Traceback (most recent call last):
    File "manage.py", line 15, in <module>
      execute_from_command_line(sys.argv)
    File "/.../django/core/management/__init__.py", line 354, in execute_from_command_line
      utility.execute()
    File "/.../django/core/management/__init__.py", line 346, in execute
      self.fetch_command(subcommand).run_from_argv(self.argv)
    File "/.../django/core/management/base.py", line 394, in run_from_argv
      self.execute(*args, **cmd_options)
    File "/.../django/core/management/base.py", line 445, in execute
      output = self.handle(*args, **options)
    File "/.../mezzanine/blog/management/base.py", line 168, in handle
      self.handle_import(options)
    File "/.../mezzanine/blog/management/commands/import_blogger.py", line 59, in handle_import
      "%Y-%m-%dT%H:%M:%S.%f") - timedelta(seconds=timezone)
    File "/.../python2.7/_strptime.py", line 325, in _strptime
      (data_string, format))
  ValueError: time data '2015-11-26T16:21:0' does not match format '%Y-%m-%dT%H:%M:%S.%f'
  ```
  
  A possible way of fixing this is to change mezzanine/blog/management/commands/import_blogger.py
  
  ``` python
  try:
      published_date = datetime.strptime(entry.published.text[:-6],
              "%Y-%m-%dT%H:%M:%S.%f") - timedelta(seconds=timezone)
  except ValueError:
      published_date = datetime.strptime(entry.published.text[:-6],
              "%Y-%m-%dT%H:%M:%S") - timedelta(seconds=timezone)
  ```
  
  and
  
  ``` python
  try:
      comment_date = datetime.strptime(comment.published.text[:-6],
          "%Y-%m-%dT%H:%M:%S.%f") - timedelta(seconds=timezone)
  except ValueError:
      comment_date = datetime.strptime(comment.published.text[:-6],
          "%Y-%m-%dT%H:%M:%S") - timedelta(seconds=timezone)
  ```
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `mezzanine/blog/management/commands/import_blogger.py`
  Content:
  ```
  1 from __future__ import unicode_literals
  2 
  3 from datetime import datetime, timedelta
  4 from optparse import make_option
  5 from time import timezone
  6 import re
  7 
  8 from django.core.management.base import CommandError
  9 
  10 from mezzanine.blog.management.base import BaseImporterCommand
  11 
  12 
  13 # TODO: update this to use v3 of the blogger API.
  14 class Command(BaseImporterCommand):
  15     """
  16     Implements a Blogger importer. Takes a Blogger ID in order to be able to
  17     determine which blog it should point to and harvest the XML from.
  18     """
  19 
  20     option_list = BaseImporterCommand.option_list + (
  21         make_option("-b", "--blogger-id", dest="blog_id",
  22             help="Blogger Blog ID from blogger dashboard"),
  23     )
  24 
  25     def handle_import(self, options):
  26         """
  27         Gets posts from Blogger.
  28         """
  29 
  30         blog_id = options.get("blog_id")
  31         if blog_id is None:
  32             raise CommandError("Usage is import_blogger %s" % self.args)
  33 
  34         try:
  35             from gdata import service
  36         except ImportError:
  37             raise CommandError("Could not import the gdata library.")
  38 
  39         blogger = service.GDataService()
  40         blogger.service = "blogger"
  41         blogger.server = "www.blogger.com"
  42 
  43         start_index = 1
  44         processed_posts = []
  45         new_posts = 1
  46 
  47         while new_posts:
  48             new_posts = 0
  49 
  50             query = service.Query()
  51             query.feed = "/feeds/%s/posts/full" % blog_id
  52             query.max_results = 500
  53             query.start_index = start_index
  54 
  55             try:
  56                 feed = blogger.Get(query.ToUri())
  57             except service.RequestError as err:
  58                 message = "There was a service error. The response was: " \
  59                     "%(status)s %(reason)s - %(body)s" % err.message
  60                 raise CommandError(message, blogger.server + query.feed,
  61                                    err.message["status"])
  62 
  63             for (i, entry) in enumerate(feed.entry):
  64                 # this basically gets the unique post ID from the URL to itself
  65                 # and pulls the ID off the end.
  66                 post_id = entry.GetSelfLink().href.split("/")[-1]
  67 
  68                 # Skip duplicate posts. Important for the last query.
  69                 if post_id in processed_posts:
  70                     continue
  71 
  72                 title = entry.title.text
  73                 content = entry.content.text
  74                 # this strips off the time zone info off the end as we want UTC
  75                 clean_date = entry.published.text[:re.search(r"\.\d{3}",
  76                     entry.published.text).end()]
  77                 published_date = datetime.strptime(clean_date,
  78                         "%Y-%m-%dT%H:%M:%S.%f") - timedelta(seconds=timezone)
  79 
  80                 # TODO - issues with content not generating correct <P> tags
  81 
  82                 tags = [tag.term for tag in entry.category]
  83                 post = self.add_post(title=title, content=content,
  84                                      pub_date=published_date, tags=tags)
  85 
  86                 # get the comments from the post feed and then add them to
  87                 # the post details
  88                 comment_url = "/feeds/%s/%s/comments/full?max-results=1000"
  89                 comments = blogger.Get(comment_url % (blog_id, post_id))
  90 
  91                 for comment in comments.entry:
  92                     email = comment.author[0].email.text
  93                     author_name = comment.author[0].name.text
  94                     # Strip off the time zone info off the end as we want UTC
  95                     clean_date = comment.published.text[:re.search(r"\.\d{3}",
  96                         comment.published.text).end()]
  97                     comment_date = datetime.strptime(clean_date,
  98                         "%Y-%m-%dT%H:%M:%S.%f") - timedelta(seconds=timezone)
  99                     website = ""
  100                     if comment.author[0].uri:
  101                         website = comment.author[0].uri.text
  102                     body = comment.content.text
  103 
  104                     # add the comment as a dict to the end of the comments list
  105                     self.add_comment(post=post, name=author_name, email=email,
  106                                      body=body, website=website,
  107                                      pub_date=comment_date)
  108 
  109                 processed_posts.append(post_id)
  110                 new_posts += 1
  111 
  112             start_index += 500
  113
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/mezzanine/blog/management/commands/import_blogger.py b/mezzanine/blog/management/commands/import_blogger.py
  --- a/mezzanine/blog/management/commands/import_blogger.py
  +++ b/mezzanine/blog/management/commands/import_blogger.py
  @@ -74,8 +74,8 @@
                   # this strips off the time zone info off the end as we want UTC
                   clean_date = entry.published.text[:re.search(r"\.\d{3}",
                       entry.published.text).end()]
  -                published_date = datetime.strptime(clean_date,
  -                        "%Y-%m-%dT%H:%M:%S.%f") - timedelta(seconds=timezone)
  +
  +                published_date = self.parse_datetime(clean_date)
   
                   # TODO - issues with content not generating correct <P> tags
   
  @@ -94,8 +94,9 @@
                       # Strip off the time zone info off the end as we want UTC
                       clean_date = comment.published.text[:re.search(r"\.\d{3}",
                           comment.published.text).end()]
  -                    comment_date = datetime.strptime(clean_date,
  -                        "%Y-%m-%dT%H:%M:%S.%f") - timedelta(seconds=timezone)
  +
  +                    comment_date = self.parse_datetime(clean_date)
  +
                       website = ""
                       if comment.author[0].uri:
                           website = comment.author[0].uri.text
  @@ -110,3 +111,14 @@
                   new_posts += 1
   
               start_index += 500
  +
  +    def parse_datetime(self, datetime_string):
  +        try:
  +            parsed_datetime = datetime.strptime(datetime_string,
  +                                                "%Y-%m-%dT%H:%M:%S.%f")
  +        except ValueError:
  +            parsed_datetime = datetime.strptime(datetime_string,
  +                                                "%Y-%m-%dT%H:%M:%S")
  +
  +        parsed_datetime -= timedelta(seconds=timezone)
  +        return parsed_datetime
  
verification_info: {"golden_diff": "diff --git a/mezzanine/blog/management/commands/import_blogger.py b/mezzanine/blog/management/commands/import_blogger.py\n--- a/mezzanine/blog/management/commands/import_blogger.py\n+++ b/mezzanine/blog/management/commands/import_blogger.py\n@@ -74,8 +74,8 @@\n                 # this strips off the time zone info off the end as we want UTC\n                 clean_date = entry.published.text[:re.search(r\"\\.\\d{3}\",\n                     entry.published.text).end()]\n-                published_date = datetime.strptime(clean_date,\n-                        \"%Y-%m-%dT%H:%M:%S.%f\") - timedelta(seconds=timezone)\n+\n+                published_date = self.parse_datetime(clean_date)\n \n                 # TODO - issues with content not generating correct <P> tags\n \n@@ -94,8 +94,9 @@\n                     # Strip off the time zone info off the end as we want UTC\n                     clean_date = comment.published.text[:re.search(r\"\\.\\d{3}\",\n                         comment.published.text).end()]\n-                    comment_date = datetime.strptime(clean_date,\n-                        \"%Y-%m-%dT%H:%M:%S.%f\") - timedelta(seconds=timezone)\n+\n+                    comment_date = self.parse_datetime(clean_date)\n+\n                     website = \"\"\n                     if comment.author[0].uri:\n                         website = comment.author[0].uri.text\n@@ -110,3 +111,14 @@\n                 new_posts += 1\n \n             start_index += 500\n+\n+    def parse_datetime(self, datetime_string):\n+        try:\n+            parsed_datetime = datetime.strptime(datetime_string,\n+                                                \"%Y-%m-%dT%H:%M:%S.%f\")\n+        except ValueError:\n+            parsed_datetime = datetime.strptime(datetime_string,\n+                                                \"%Y-%m-%dT%H:%M:%S\")\n+\n+        parsed_datetime -= timedelta(seconds=timezone)\n+        return parsed_datetime\n", "issue": "ValueError while import blog posts from Blogger \nHi, when I run the Blogger importer: \n\n```\n$ python manage.py import_blogger --mezzanine-user=.. --blogger-id=XXX\n```\n\nA ValueError is raised:\n\n``` python\nTraceback (most recent call last):\n  File \"manage.py\", line 15, in <module>\n    execute_from_command_line(sys.argv)\n  File \"/.../django/core/management/__init__.py\", line 354, in execute_from_command_line\n    utility.execute()\n  File \"/.../django/core/management/__init__.py\", line 346, in execute\n    self.fetch_command(subcommand).run_from_argv(self.argv)\n  File \"/.../django/core/management/base.py\", line 394, in run_from_argv\n    self.execute(*args, **cmd_options)\n  File \"/.../django/core/management/base.py\", line 445, in execute\n    output = self.handle(*args, **options)\n  File \"/.../mezzanine/blog/management/base.py\", line 168, in handle\n    self.handle_import(options)\n  File \"/.../mezzanine/blog/management/commands/import_blogger.py\", line 59, in handle_import\n    \"%Y-%m-%dT%H:%M:%S.%f\") - timedelta(seconds=timezone)\n  File \"/.../python2.7/_strptime.py\", line 325, in _strptime\n    (data_string, format))\nValueError: time data '2015-11-26T16:21:0' does not match format '%Y-%m-%dT%H:%M:%S.%f'\n```\n\nA possible way of fixing this is to change mezzanine/blog/management/commands/import_blogger.py\n\n``` python\ntry:\n    published_date = datetime.strptime(entry.published.text[:-6],\n            \"%Y-%m-%dT%H:%M:%S.%f\") - timedelta(seconds=timezone)\nexcept ValueError:\n    published_date = datetime.strptime(entry.published.text[:-6],\n            \"%Y-%m-%dT%H:%M:%S\") - timedelta(seconds=timezone)\n```\n\nand\n\n``` python\ntry:\n    comment_date = datetime.strptime(comment.published.text[:-6],\n        \"%Y-%m-%dT%H:%M:%S.%f\") - timedelta(seconds=timezone)\nexcept ValueError:\n    comment_date = datetime.strptime(comment.published.text[:-6],\n        \"%Y-%m-%dT%H:%M:%S\") - timedelta(seconds=timezone)\n```\n\n", "before_files": [{"content": "from __future__ import unicode_literals\n\nfrom datetime import datetime, timedelta\nfrom optparse import make_option\nfrom time import timezone\nimport re\n\nfrom django.core.management.base import CommandError\n\nfrom mezzanine.blog.management.base import BaseImporterCommand\n\n\n# TODO: update this to use v3 of the blogger API.\nclass Command(BaseImporterCommand):\n    \"\"\"\n    Implements a Blogger importer. Takes a Blogger ID in order to be able to\n    determine which blog it should point to and harvest the XML from.\n    \"\"\"\n\n    option_list = BaseImporterCommand.option_list + (\n        make_option(\"-b\", \"--blogger-id\", dest=\"blog_id\",\n            help=\"Blogger Blog ID from blogger dashboard\"),\n    )\n\n    def handle_import(self, options):\n        \"\"\"\n        Gets posts from Blogger.\n        \"\"\"\n\n        blog_id = options.get(\"blog_id\")\n        if blog_id is None:\n            raise CommandError(\"Usage is import_blogger %s\" % self.args)\n\n        try:\n            from gdata import service\n        except ImportError:\n            raise CommandError(\"Could not import the gdata library.\")\n\n        blogger = service.GDataService()\n        blogger.service = \"blogger\"\n        blogger.server = \"www.blogger.com\"\n\n        start_index = 1\n        processed_posts = []\n        new_posts = 1\n\n        while new_posts:\n            new_posts = 0\n\n            query = service.Query()\n            query.feed = \"/feeds/%s/posts/full\" % blog_id\n            query.max_results = 500\n            query.start_index = start_index\n\n            try:\n                feed = blogger.Get(query.ToUri())\n            except service.RequestError as err:\n                message = \"There was a service error. The response was: \" \\\n                    \"%(status)s %(reason)s - %(body)s\" % err.message\n                raise CommandError(message, blogger.server + query.feed,\n                                   err.message[\"status\"])\n\n            for (i, entry) in enumerate(feed.entry):\n                # this basically gets the unique post ID from the URL to itself\n                # and pulls the ID off the end.\n                post_id = entry.GetSelfLink().href.split(\"/\")[-1]\n\n                # Skip duplicate posts. Important for the last query.\n                if post_id in processed_posts:\n                    continue\n\n                title = entry.title.text\n                content = entry.content.text\n                # this strips off the time zone info off the end as we want UTC\n                clean_date = entry.published.text[:re.search(r\"\\.\\d{3}\",\n                    entry.published.text).end()]\n                published_date = datetime.strptime(clean_date,\n                        \"%Y-%m-%dT%H:%M:%S.%f\") - timedelta(seconds=timezone)\n\n                # TODO - issues with content not generating correct <P> tags\n\n                tags = [tag.term for tag in entry.category]\n                post = self.add_post(title=title, content=content,\n                                     pub_date=published_date, tags=tags)\n\n                # get the comments from the post feed and then add them to\n                # the post details\n                comment_url = \"/feeds/%s/%s/comments/full?max-results=1000\"\n                comments = blogger.Get(comment_url % (blog_id, post_id))\n\n                for comment in comments.entry:\n                    email = comment.author[0].email.text\n                    author_name = comment.author[0].name.text\n                    # Strip off the time zone info off the end as we want UTC\n                    clean_date = comment.published.text[:re.search(r\"\\.\\d{3}\",\n                        comment.published.text).end()]\n                    comment_date = datetime.strptime(clean_date,\n                        \"%Y-%m-%dT%H:%M:%S.%f\") - timedelta(seconds=timezone)\n                    website = \"\"\n                    if comment.author[0].uri:\n                        website = comment.author[0].uri.text\n                    body = comment.content.text\n\n                    # add the comment as a dict to the end of the comments list\n                    self.add_comment(post=post, name=author_name, email=email,\n                                     body=body, website=website,\n                                     pub_date=comment_date)\n\n                processed_posts.append(post_id)\n                new_posts += 1\n\n            start_index += 500\n", "path": "mezzanine/blog/management/commands/import_blogger.py"}], "after_files": [{"content": "from __future__ import unicode_literals\n\nfrom datetime import datetime, timedelta\nfrom optparse import make_option\nfrom time import timezone\nimport re\n\nfrom django.core.management.base import CommandError\n\nfrom mezzanine.blog.management.base import BaseImporterCommand\n\n\n# TODO: update this to use v3 of the blogger API.\nclass Command(BaseImporterCommand):\n    \"\"\"\n    Implements a Blogger importer. Takes a Blogger ID in order to be able to\n    determine which blog it should point to and harvest the XML from.\n    \"\"\"\n\n    option_list = BaseImporterCommand.option_list + (\n        make_option(\"-b\", \"--blogger-id\", dest=\"blog_id\",\n            help=\"Blogger Blog ID from blogger dashboard\"),\n    )\n\n    def handle_import(self, options):\n        \"\"\"\n        Gets posts from Blogger.\n        \"\"\"\n\n        blog_id = options.get(\"blog_id\")\n        if blog_id is None:\n            raise CommandError(\"Usage is import_blogger %s\" % self.args)\n\n        try:\n            from gdata import service\n        except ImportError:\n            raise CommandError(\"Could not import the gdata library.\")\n\n        blogger = service.GDataService()\n        blogger.service = \"blogger\"\n        blogger.server = \"www.blogger.com\"\n\n        start_index = 1\n        processed_posts = []\n        new_posts = 1\n\n        while new_posts:\n            new_posts = 0\n\n            query = service.Query()\n            query.feed = \"/feeds/%s/posts/full\" % blog_id\n            query.max_results = 500\n            query.start_index = start_index\n\n            try:\n                feed = blogger.Get(query.ToUri())\n            except service.RequestError as err:\n                message = \"There was a service error. The response was: \" \\\n                    \"%(status)s %(reason)s - %(body)s\" % err.message\n                raise CommandError(message, blogger.server + query.feed,\n                                   err.message[\"status\"])\n\n            for (i, entry) in enumerate(feed.entry):\n                # this basically gets the unique post ID from the URL to itself\n                # and pulls the ID off the end.\n                post_id = entry.GetSelfLink().href.split(\"/\")[-1]\n\n                # Skip duplicate posts. Important for the last query.\n                if post_id in processed_posts:\n                    continue\n\n                title = entry.title.text\n                content = entry.content.text\n                # this strips off the time zone info off the end as we want UTC\n                clean_date = entry.published.text[:re.search(r\"\\.\\d{3}\",\n                    entry.published.text).end()]\n\n                published_date = self.parse_datetime(clean_date)\n\n                # TODO - issues with content not generating correct <P> tags\n\n                tags = [tag.term for tag in entry.category]\n                post = self.add_post(title=title, content=content,\n                                     pub_date=published_date, tags=tags)\n\n                # get the comments from the post feed and then add them to\n                # the post details\n                comment_url = \"/feeds/%s/%s/comments/full?max-results=1000\"\n                comments = blogger.Get(comment_url % (blog_id, post_id))\n\n                for comment in comments.entry:\n                    email = comment.author[0].email.text\n                    author_name = comment.author[0].name.text\n                    # Strip off the time zone info off the end as we want UTC\n                    clean_date = comment.published.text[:re.search(r\"\\.\\d{3}\",\n                        comment.published.text).end()]\n\n                    comment_date = self.parse_datetime(clean_date)\n\n                    website = \"\"\n                    if comment.author[0].uri:\n                        website = comment.author[0].uri.text\n                    body = comment.content.text\n\n                    # add the comment as a dict to the end of the comments list\n                    self.add_comment(post=post, name=author_name, email=email,\n                                     body=body, website=website,\n                                     pub_date=comment_date)\n\n                processed_posts.append(post_id)\n                new_posts += 1\n\n            start_index += 500\n\n    def parse_datetime(self, datetime_string):\n        try:\n            parsed_datetime = datetime.strptime(datetime_string,\n                                                \"%Y-%m-%dT%H:%M:%S.%f\")\n        except ValueError:\n            parsed_datetime = datetime.strptime(datetime_string,\n                                                \"%Y-%m-%dT%H:%M:%S\")\n\n        parsed_datetime -= timedelta(seconds=timezone)\n        return parsed_datetime\n", "path": "mezzanine/blog/management/commands/import_blogger.py"}]}