Skip to content

archive

Module for archiving sets of data

Archive ¤

Bases: Set

Archive class. A file-persistable set.

load(file) ¤

Imports the archive from the file.

Arguments¤
  • file: the file name of the archive
Returns¤
  • if the file exists
Source code in spotdl/utils/archive.py
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
def load(self, file: str) -> bool:
    """
    Imports the archive from the file.

    ### Arguments
    - file: the file name of the archive

    ### Returns
    - if the file exists
    """

    if not Path(file).exists():
        return False

    with open(file, "r", encoding="utf-8") as archive:
        self.clear()
        self.update([line.strip() for line in archive])

    return True

save(file) ¤

Exports the current archive to the file.

Arguments¤
  • file: the file name of the archive
Source code in spotdl/utils/archive.py
37
38
39
40
41
42
43
44
45
46
47
48
49
def save(self, file: str) -> bool:
    """
    Exports the current archive to the file.

    ### Arguments
    - file: the file name of the archive
    """

    with open(file, "w", encoding="utf-8") as archive:
        for element in sorted(self):
            archive.write(f"{element}\n")

    return True