posts module now reads config values from config module

This commit is contained in:
asdf 2019-11-27 12:34:01 +11:00
parent 65aa7ed835
commit ffc8814b00
2 changed files with 20 additions and 3 deletions

17
config.py Normal file
View File

@ -0,0 +1,17 @@
"""stores configuration settings for linkulator"""
from pathlib import Path
from glob import glob
class DefaultConfigOptions:
"""data class for configuration options"""
all_data_dirs: glob
data_dir: Path
data_file: Path
CONFIG = DefaultConfigOptions()
CONFIG.all_data_dirs = glob("/home/*/.linkulator/linkulator.data")
CONFIG.data_dir = Path(Path.home() / ".linkulator")
CONFIG.data_file = Path(CONFIG.data_dir / "linkulator.data")

View File

@ -5,6 +5,7 @@ import readline
import os
import getpass
import sys
from config import CONFIG as config
USERNAME = getpass.getuser()
@ -52,12 +53,11 @@ def get_input(item: str, prefill) -> str:
def save_link(link):
filename = "/home/" + USERNAME + "/.linkulator/linkulator.data"
if os.path.exists(filename):
if os.path.exists(config.data_file):
append_write = "a" # append if already exists
else:
append_write = "w+" # make a new file if not
with open(filename, append_write) as file:
with open(config.data_file, append_write) as file:
file.write(
link.timestamp
+ "||"