diff options
author | neodarz <neodarz@neodarz.net> | 2020-08-15 14:07:15 +0200 |
---|---|---|
committer | neodarz <neodarz@neodarz.net> | 2020-08-15 14:07:15 +0200 |
commit | c4fb7fda5b1b6bb22db1f517f71cf393f68c6a9b (patch) | |
tree | 746b1c9e7d5b2f49e338706fec9f9c0d74f9f7c3 /utils.py | |
download | music_downloader-c4fb7fda5b1b6bb22db1f517f71cf393f68c6a9b.tar.xz music_downloader-c4fb7fda5b1b6bb22db1f517f71cf393f68c6a9b.zip |
Initial commit
Diffstat (limited to 'utils.py')
-rw-r--r-- | utils.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/utils.py b/utils.py new file mode 100644 index 0000000..2736206 --- /dev/null +++ b/utils.py @@ -0,0 +1,21 @@ +import sys +import logging + + +def read_file(filename): + lines = [] + + 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') |