diff --git a/tests/test_import.py b/tests/test_import.py index a79d036..3efe1e3 100644 --- a/tests/test_import.py +++ b/tests/test_import.py @@ -33,6 +33,7 @@ def test_create_zip(zip_contents_path): "saved-search.js", "following.js", "follower.js", + "ageinfo.js", } == {f.filename for f in zf.filelist} @@ -77,6 +78,7 @@ def assert_imported_db(db): "archive_account", "archive_app", "archive_following", + "archive_ageinfo", } == set(db.table_names()) assert [{"accountId": "73747798"}, {"accountId": "386025404"}] == list( diff --git a/tests/zip_contents/ageinfo.js b/tests/zip_contents/ageinfo.js new file mode 100644 index 0000000..2b20620 --- /dev/null +++ b/tests/zip_contents/ageinfo.js @@ -0,0 +1,4 @@ +window.YTD.ageinfo.part0 = + { + "ageMeta" : { } + } diff --git a/twitter_to_sqlite/archive.py b/twitter_to_sqlite/archive.py index 1b3f084..c1113d8 100644 --- a/twitter_to_sqlite/archive.py +++ b/twitter_to_sqlite/archive.py @@ -88,6 +88,10 @@ def ad_online_conversions_unattributed(item): @register_each("ageinfo") def ageinfo(item): + # Prevent newer archive formats and/or empty ageinfo files from crashing + if isinstance(item, (str)) or "ageInfo" not in item["ageMeta"]: + return {'ageInfo': ''} + return item["ageMeta"]["ageInfo"]