File size: 687 Bytes
651b002
 
 
 
 
 
 
 
 
 
303cbb8
651b002
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from zipfile import ZipFile
import os
from pathlib import Path


# Extract the collection file or deck file to get the .anki21 database.
def extract(file, prefix):
    proj_dir = Path(f'projects/{prefix}_{file.orig_name.replace(".", "_").replace("@", "_")}')
    with ZipFile(file, 'r') as zip_ref:
        zip_ref.extractall(proj_dir)
        # print(f"Extracted {file.orig_name} successfully!")
    return proj_dir

def cleanup(proj_dir: Path, files):
    """
    Delete all files in prefix that dont have filenames in files
    :param proj_dir:
    :param files:
    :return:
    """
    for file in proj_dir.glob('*'):
        if file.name not in files:
            os.remove(file)