Repository: getnikola/nikola

Issue:
Wordpress import: could not convert string to float
### Environment

**Python Version:** 3.8

**Nikola Version:** Nikola v8.1.3

**Operating System:** Mac OS Big Sur

### Description:

I'm trying to import wordpress blog, but the following error occurs:

```
[2021-03-31 17:58:02] INFO: import_wordpress: Downloading https://xxxxxxxxxxxx/wp-content/uploads/2011/11/1.jpg => new_site/files/bg/wp-content/uploads/2011/11/1.jpg
Traceback (most recent call last):
  File "/Users/xxxxx/Library/Python/3.8/lib/python/site-packages/doit/doit_cmd.py", line 190, in run
    return command.parse_execute(args)
  File "/Users/xxxxx/Library/Python/3.8/lib/python/site-packages/doit/cmd_base.py", line 150, in parse_execute
    return self.execute(params, args)
  File "/Users/xxxxx/Library/Python/3.8/lib/python/site-packages/nikola/plugin_categories.py", line 148, in execute
    return self._execute(options, args)
  File "/Users/xxxxx/Library/Python/3.8/lib/python/site-packages/nikola/plugins/command/import_wordpress.py", line 387, in _execute
    self.import_posts(channel)
  File "/Users/xxxxx/Library/Python/3.8/lib/python/site-packages/nikola/plugins/command/import_wordpress.py", line 1138, in import_posts
    self.process_item_if_attachment(item)
  File "/Users/xxxxx/Library/Python/3.8/lib/python/site-packages/nikola/plugins/command/import_wordpress.py", line 1101, in process_item_if_attachment
    data = self.import_attachment(item, wordpress_namespace)
  File "/Users/xxxxx/Library/Python/3.8/lib/python/site-packages/nikola/plugins/command/import_wordpress.py", line 606, in import_attachment
    add('created_timestamp', b'created_timestamp', is_float=True, ignore_zero=True)
  File "/Users/xxxxx/Library/Python/3.8/lib/python/site-packages/nikola/plugins/command/import_wordpress.py", line 593, in add
    value = float(value)
ValueError: could not convert string to float: ''
```



Discussion:
We'll need the export file from your blog to debug this. You can limit it to a snippet (only things related to the file mentioned in the error, plus a few more lines of context just in case.
Here is the relevant snippet [snippet.txt](https://github.com/getnikola/nikola/files/6237793/snippet.txt)


Resolving patch:
diff --git a/nikola/plugins/command/import_wordpress.py b/nikola/plugins/command/import_wordpress.py
--- a/nikola/plugins/command/import_wordpress.py
+++ b/nikola/plugins/command/import_wordpress.py
@@ -582,6 +582,11 @@ def import_attachment(self, item, wordpress_namespace):
                         def add(our_key, wp_key, is_int=False, ignore_zero=False, is_float=False):
                             if wp_key in image_meta:
                                 value = image_meta[wp_key]
+                                if value in ("", b"") and (is_int or is_float):
+                                    if ignore_zero:
+                                        return
+                                    else:
+                                        dst_meta[our_key] = 0
                                 if is_int:
                                     value = int(value)
                                     if ignore_zero and value == 0:


Test patch:
diff --git a/tests/data/wordpress_import/wordpress_export_example.xml b/tests/data/wordpress_import/wordpress_export_example.xml
--- a/tests/data/wordpress_import/wordpress_export_example.xml
+++ b/tests/data/wordpress_import/wordpress_export_example.xml
@@ -53,7 +53,7 @@
         </wp:postmeta>
         <wp:postmeta>
             <wp:meta_key>_wp_attachment_metadata</wp:meta_key>
-            <wp:meta_value><![CDATA[a:6:{s:5:"width";s:3:"300";s:6:"height";s:3:"299";s:14:"hwstring_small";s:22:"height='96' width='96'";s:4:"file";s:38:"2008/07/arzt_und_pfusch-sick-cover.png";s:5:"sizes";a:1:{s:9:"thumbnail";a:3:{s:4:"file";s:38:"arzt_und_pfusch-sick-cover-150x150.png";s:5:"width";s:3:"150";s:6:"height";s:3:"150";}}s:10:"image_meta";a:10:{s:8:"aperture";s:1:"0";s:6:"credit";s:0:"";s:6:"camera";s:0:"";s:7:"caption";s:0:"";s:17:"created_timestamp";s:1:"0";s:9:"copyright";s:0:"";s:12:"focal_length";s:1:"0";s:3:"iso";s:1:"0";s:13:"shutter_speed";s:1:"0";s:5:"title";s:0:"";}}]]></wp:meta_value>
+            <wp:meta_value><![CDATA[a:6:{s:5:"width";s:3:"300";s:6:"height";s:3:"299";s:14:"hwstring_small";s:22:"height='96' width='96'";s:4:"file";s:38:"2008/07/arzt_und_pfusch-sick-cover.png";s:5:"sizes";a:1:{s:9:"thumbnail";a:3:{s:4:"file";s:38:"arzt_und_pfusch-sick-cover-150x150.png";s:5:"width";s:3:"150";s:6:"height";s:3:"150";}}s:10:"image_meta";a:10:{s:8:"aperture";s:1:"0";s:6:"credit";s:0:"";s:6:"camera";s:0:"";s:7:"caption";s:0:"";s:17:"created_timestamp";s:0:"";s:9:"copyright";s:0:"";s:12:"focal_length";s:1:"0";s:3:"iso";s:1:"0";s:13:"shutter_speed";s:1:"0";s:5:"title";s:0:"";}}]]></wp:meta_value>
         </wp:postmeta>
     </item>