-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Instead of downloading pregenerated backup ZIPs (which now require a …
…manual login they previously didn't), generate the backups, keeping the exact same ZIP layout, from the Todoist API, which still works correctly.
- Loading branch information
Showing
29 changed files
with
253 additions
and
433 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,35 @@ | ||
#!/usr/bin/python3 | ||
""" Class to download Todoist backup ZIPs using the Todoist API """ | ||
import zipfile | ||
import io | ||
import datetime | ||
from .utils import sanitize_file_name | ||
|
||
class TodoistBackupDownloader: | ||
""" Class to download Todoist backup ZIPs using the Todoist API """ | ||
__ZIP_FLAG_BITS_UTF8 = 0x800 | ||
|
||
def __init__(self, tracer, urldownloader): | ||
def __init__(self, tracer, todoist_api): | ||
self.__tracer = tracer | ||
self.__urldownloader = urldownloader | ||
self.__todoist_api = todoist_api | ||
|
||
def download(self, backup, vfs): | ||
""" Downloads the specified backup to the specified folder """ | ||
self.__tracer.trace("Downloading backup with version '{}'".format(backup.version)) | ||
def download(self, vfs): | ||
""" Generates a Todoist backup and saves it to the given VFS """ | ||
self.__tracer.trace("Generating backup from current Todoist status") | ||
|
||
# Sanitize the file name for platforms such as Windows, | ||
# which don't accept some characters in file names, such as a colon (:) | ||
vfs.set_path_hint(sanitize_file_name("TodoistBackup_" + backup.version)) | ||
backup_version = datetime.datetime.utcnow().replace(microsecond=0).isoformat(' ') | ||
vfs.set_path_hint(sanitize_file_name("TodoistBackup_" + backup_version)) | ||
|
||
# Download the file | ||
if vfs.existed(): | ||
self.__tracer.trace("File already downloaded... skipping") | ||
return | ||
|
||
self.__tracer.trace("Downloading from {}...".format( | ||
backup.url)) | ||
raw_zip_bytes = self.__urldownloader.get(backup.url) | ||
with zipfile.ZipFile(io.BytesIO(raw_zip_bytes), "r") as zipf: | ||
for info in zipf.infolist(): | ||
# Todoist backup ZIPs may contain filenames encoded in UTF-8, but they will not | ||
# actually have the UTF-8 filename flag set in the ZIP file. | ||
# This causes some ZIP parsers, such as Python's own parser, to consider the | ||
# file names in the legacy CP-437 format. | ||
# To fix this, let's re-encode the filenames in CP-437 to get the original | ||
# bytes back, then properly decode them to UTF-8. | ||
if info.flag_bits & self.__ZIP_FLAG_BITS_UTF8: | ||
encoding_file_name = info.filename | ||
else: | ||
encoding_file_name = info.filename.encode('cp437').decode("utf-8") | ||
self.__tracer.trace("Downloading project list from todoist API...") | ||
projects = self.__todoist_api.get_projects() | ||
|
||
vfs.write_file(encoding_file_name, zipf.read(info.filename)) | ||
for project in projects: | ||
export_csv_file_name = "{} [{}].csv".format( | ||
sanitize_file_name(project.name), project.identifier) | ||
export_csv_file_content = self.__todoist_api.export_project_as_csv(project) | ||
vfs.write_file(export_csv_file_name, export_csv_file_content) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
todoist_full_offline_backup/tests/integration_files/expected/BackupList.txt
This file was deleted.
Oops, something went wrong.
Binary file added
BIN
+3.24 KB
todoist_full_offline_backup/tests/integration_files/expected/TodoistBackupNoAttach.zip
Binary file not shown.
File renamed without changes.
Binary file renamed
BIN
+6.06 KB
...pected/TodoistBackup_2018-03-25 10_12.zip → ...tion_files/sources/Project_2181147709.csv
Binary file not shown.
1 change: 1 addition & 0 deletions
1
todoist_full_offline_backup/tests/integration_files/sources/Project_2181147711.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
TYPE,CONTENT,PRIORITY,INDENT,AUTHOR,RESPONSIBLE,DATE,DATE_LANG,TIMEZONE |
1 change: 1 addition & 0 deletions
1
todoist_full_offline_backup/tests/integration_files/sources/Project_2181147712.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
TYPE,CONTENT,PRIORITY,INDENT,AUTHOR,RESPONSIBLE,DATE,DATE_LANG,TIMEZONE |
1 change: 1 addition & 0 deletions
1
todoist_full_offline_backup/tests/integration_files/sources/Project_2181147713.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
TYPE,CONTENT,PRIORITY,INDENT,AUTHOR,RESPONSIBLE,DATE,DATE_LANG,TIMEZONE |
1 change: 1 addition & 0 deletions
1
todoist_full_offline_backup/tests/integration_files/sources/Project_2181147714.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
TYPE,CONTENT,PRIORITY,INDENT,AUTHOR,RESPONSIBLE,DATE,DATE_LANG,TIMEZONE |
1 change: 1 addition & 0 deletions
1
todoist_full_offline_backup/tests/integration_files/sources/Project_2181147715.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
TYPE,CONTENT,PRIORITY,INDENT,AUTHOR,RESPONSIBLE,DATE,DATE_LANG,TIMEZONE |
4 changes: 4 additions & 0 deletions
4
todoist_full_offline_backup/tests/integration_files/sources/Project_2181147955.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
TYPE,CONTENT,PRIORITY,INDENT,AUTHOR,RESPONSIBLE,DATE,DATE_LANG,TIMEZONE | ||
task,this task has a 🐛 in its name!!!,4,1,test_integration_test (16542905),,,en,Europe/Madrid | ||
note," [[file {""file_size"":28,""file_type"":""text\/plain"",""file_name"":""bug.txt"",""upload_state"":""completed"",""file_url"":""https:\/\/d1x0mwiac2rqwt.cloudfront.net\/g75-kL8pwVYNObSczLnVXe4FIyJd8YQL6b8yCilGyix09bMdJmxbtrGMW9jIeIwJ\/by\/16542905\/as\/bug.txt"",""resource_type"":""file""}]]",,,test_integration_test (16542905),,,, | ||
,,,,,,,, |
Binary file removed
BIN
-6.06 KB
..._full_offline_backup/tests/integration_files/sources/d786b8464e642890cd575bdefc87dcda.zip
Binary file not shown.
Binary file removed
BIN
-6.17 KB
..._full_offline_backup/tests/integration_files/sources/f9610a4296c5deaf536de3fc9bfd113a.zip
Binary file not shown.
1 change: 0 additions & 1 deletion
1
todoist_full_offline_backup/tests/integration_files/sources/get_backups.json
This file was deleted.
Oops, something went wrong.
91 changes: 91 additions & 0 deletions
91
todoist_full_offline_backup/tests/integration_files/sources/project_list.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
{ | ||
"projects" : [ | ||
{ | ||
"is_archived" : 0, | ||
"color" : 7, | ||
"shared" : false, | ||
"inbox_project" : true, | ||
"id" : 2181147955, | ||
"collapsed" : 0, | ||
"item_order" : 0, | ||
"name" : "🦋 butterflies list", | ||
"is_deleted" : 0, | ||
"indent" : 1 | ||
}, | ||
{ | ||
"is_archived" : 0, | ||
"color" : 7, | ||
"shared" : false, | ||
"inbox_project" : true, | ||
"id" : 2181147714, | ||
"collapsed" : 0, | ||
"item_order" : 0, | ||
"name" : "Errands", | ||
"is_deleted" : 0, | ||
"indent" : 1 | ||
}, | ||
{ | ||
"is_archived" : 0, | ||
"color" : 7, | ||
"shared" : false, | ||
"inbox_project" : true, | ||
"id" : 2181147709, | ||
"collapsed" : 0, | ||
"item_order" : 0, | ||
"name" : "Inbox", | ||
"is_deleted" : 0, | ||
"indent" : 1 | ||
}, | ||
{ | ||
"is_archived" : 0, | ||
"color" : 7, | ||
"shared" : false, | ||
"inbox_project" : true, | ||
"id" : 2181147715, | ||
"collapsed" : 0, | ||
"item_order" : 0, | ||
"name" : "Movies to watch", | ||
"is_deleted" : 0, | ||
"indent" : 1 | ||
}, | ||
{ | ||
"is_archived" : 0, | ||
"color" : 7, | ||
"shared" : false, | ||
"inbox_project" : true, | ||
"id" : 2181147711, | ||
"collapsed" : 0, | ||
"item_order" : 0, | ||
"name" : "Personal", | ||
"is_deleted" : 0, | ||
"indent" : 1 | ||
}, | ||
{ | ||
"is_archived" : 0, | ||
"color" : 7, | ||
"shared" : false, | ||
"inbox_project" : true, | ||
"id" : 2181147712, | ||
"collapsed" : 0, | ||
"item_order" : 0, | ||
"name" : "Shopping", | ||
"is_deleted" : 0, | ||
"indent" : 1 | ||
}, | ||
{ | ||
"is_archived" : 0, | ||
"color" : 7, | ||
"shared" : false, | ||
"inbox_project" : true, | ||
"id" : 2181147713, | ||
"collapsed" : 0, | ||
"item_order" : 0, | ||
"name" : "Work", | ||
"is_deleted" : 0, | ||
"indent" : 1 | ||
} | ||
], | ||
"full_sync" : true, | ||
"temp_id_mapping" : {}, | ||
"sync_token" : "aLGJg_2qwBE_kE3j9_Gn6uoKQtvQeyjm7UEz_aVwF8KdriDxw7e_InFZK61h" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.