aboutsummaryrefslogtreecommitdiff
path: root/utils.py
blob: 58188b1bf2b760dce775c5d0bd2cd2b19ffe8282 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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')