akamhy / waybackpy

Wayback Machine API interface & a command-line tool
https://pypi.org/project/waybackpy/
MIT License
453 stars 32 forks source link

CLI: --json returns invalid json #86

Closed notevenaperson closed 3 years ago

notevenaperson commented 3 years ago
$ waybackpy --url "https://en.wikipedia.org/wiki/JSON#Syntax" --json
{'archived_snapshots': {'closest': {'timestamp': '20210121111134', 'url': 'http://web.archive.org/web/20210121111134/https://en.wikipedia.org/wiki/JSON', 'status': '200', 'available': True}}, 'url': 'https://en.wikipedia.org/wiki/JSON#Syntax'}
#attempt to parse the json output
$ waybackpy --url "https://en.wikipedia.org/wiki/JSON#Syntax" --json | jq 
parse error: Invalid numeric literal at line 1, column 22

While the equivalent query using curl [1] outputs valid json

$ curl "http://archive.org/wayback/available?url=https://en.wikipedia.org/wiki/JSON#Syntax"
{"archived_snapshots": {"closest": {"timestamp": "20210121111134", "url": "http://web.archive.org/web/20210121111134/https://en.wikipedia.org/wiki/JSON", "status": "200", "available": true}}, "url": "https://en.wikipedia.org/wiki/JSON"}
#attempt to parse the json output
curl "http://archive.org/wayback/available?url=https://en.wikipedia.org/wiki/JSON#Syntax" | jq
[works as expected]

It seems waybackpy's json is invalid because:

Just to exemplify, it becomes valid if I manually fix the two points above:

$ waybackpy --url "https://en.wikipedia.org/wiki/JSON#Syntax" --json | tr "'" "\"" | sed -e 's/True/true/g' | jq
[works as expected]
akamhy commented 3 years ago

fixed in https://github.com/akamhy/waybackpy/commit/edc2f63d9365b5558f8425d41453cf6f95f901f1

Thanks for reporting!