Repository: stephenmcd/mezzanine

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)
```



Discussion:

Resolving patch:
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 @@ def handle_import(self, options):
                 # 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 @@ def handle_import(self, options):
                     # 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 @@ def handle_import(self, options):
                 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


Test patch: