aboutsummaryrefslogtreecommitdiff
path: root/utils.py
blob: 972e92f2a001f4b43b6d3c674e0940f3987bc7cf (plain)
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
26
import sys
import logging
from pathlib import Path


def read_file(filename):
    lines = []
    filename = Path(filename)

    if filename.is_dir():
        logging.fatal(f'{filename} is a folder instead of a file!')
        sys.exit(1)
    elif not filename.is_file():
        filename.touch()
    with open(filename) as filehandler:
        for line in filehandler.readlines():
            lines.append(line.strip())

    return lines

def write_file(filename, data):
    with open(filename, 'a') as filehandler:
        filehandler.write(data+'\n')

class NoExtractorException(Exception):
    pass