1
0
Fork 0
mirror of synced 2024-06-01 10:09:49 +12:00

Fix Pinboard JSON duplicate timestamps error

If the JSON exported by Pinboard contains duplicate timestamps, Python
returns a TypeError exception:

`TypeError: argument of type 'float' is not iterable`

This is because `time.mktime()` returns a floating point number.
Encasing `time.mktime()` in `str()` fixes the data type not being
iterable.

`time.mktime()` has also been encased in `int()` to remove the
unnecessary decimal value (`.0`) that gets returned for each time value,
and to keep the script consistent with the other export functions.
This commit is contained in:
Brian Hardisty 2017-07-01 03:53:19 -07:00
parent 2b0e0f746e
commit 71159bdcaa
No known key found for this signature in database
GPG key ID: D38A5C417347AD45

View file

@ -114,8 +114,8 @@ def parse_json_export(json_file):
'url': erg['href'],
'domain': erg['href'].replace('http://', '').replace('https://', '').split('/')[0],
'base_url': erg['href'].replace('https://', '').replace('http://', '').split('?')[0],
'time': datetime.fromtimestamp(time.mktime(time.strptime(erg['time'].split(',')[0], '%Y-%m-%dT%H:%M:%SZ'))),
'timestamp': time.mktime(time.strptime(erg['time'].split(',')[0], '%Y-%m-%dT%H:%M:%SZ')),
'time': datetime.fromtimestamp(int(time.mktime(time.strptime(erg['time'].split(',')[0], '%Y-%m-%dT%H:%M:%SZ')))),
'timestamp': str(int(time.mktime(time.strptime(erg['time'].split(',')[0], '%Y-%m-%dT%H:%M:%SZ')))),
'tags': erg['tags'],
'title': erg['description'].replace(' — Readability', ''),
}