initial commit of project
This commit is contained in:
23
crawl_recipes/tools/write_text.py
Normal file
23
crawl_recipes/tools/write_text.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
def write_text(input_text, file_path, option="Exit"):
|
||||
""" Write text to disk checking options if it exists """
|
||||
|
||||
if not os.path.exists(file_path):
|
||||
with open(file_path, 'w') as f:
|
||||
f.write(input_text.decode("utf-8"))
|
||||
|
||||
else:
|
||||
|
||||
if option == "Exit":
|
||||
print("Write file error: This file already exists.\n %s \nExiting..." %(file_path))
|
||||
sys.exit(1)
|
||||
|
||||
elif option == "Append":
|
||||
with open(file_path, 'a') as f:
|
||||
f.write(input_text)
|
||||
|
||||
elif option == "Overwrite":
|
||||
with open(file_path, 'w') as f:
|
||||
f.write(input_text)
|
||||
Reference in New Issue
Block a user