forked from cmccabe/linkulator2
posts module now reads config values from config module
This commit is contained in:
parent
65aa7ed835
commit
ffc8814b00
17
config.py
Normal file
17
config.py
Normal 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")
|
6
posts.py
6
posts.py
|
@ -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
|
||||
+ "||"
|
||||
|
|
Loading…
Reference in New Issue
Block a user