20250118.1737193804
This commit is contained in:
parent
ba81851219
commit
ed1f856b78
17 changed files with 43 additions and 398 deletions
|
@ -19,6 +19,11 @@ from pathlib import Path
|
|||
|
||||
DB_NAME = Path("metadata.db")
|
||||
TZ = 1
|
||||
TOOLS = ("jrnl", "sqlite3")
|
||||
|
||||
for t in TOOLS:
|
||||
if not shutil.which(t):
|
||||
raise FileNotFoundError(f"There is no existing path for '{t}'")
|
||||
|
||||
|
||||
class Config:
|
||||
|
@ -33,6 +38,15 @@ class Config:
|
|||
def validate(cls):
|
||||
if not cls.memo_token or not cls.memo_url:
|
||||
sys.exit("Missing MEMOS_TOKEN or MEMOS_URL environment variables.")
|
||||
elif not cls.openweathermap_api_key:
|
||||
sys.exit("Missing openweather api key")
|
||||
elif ( # TODO need more complex checking
|
||||
not cls.owntracks_creds
|
||||
or not cls.owntracks_url
|
||||
or not cls.geo_user
|
||||
or not cls.geo_device
|
||||
):
|
||||
sys.exit("Missing OwnTracks data")
|
||||
|
||||
|
||||
Config.validate()
|
||||
|
@ -300,7 +314,6 @@ def doctor():
|
|||
if check_diary:
|
||||
dt = datetime.fromtimestamp(m[1], tz=timezone(timedelta(hours=TZ)))
|
||||
diary_datetime = dt.strftime("%Y/%m/%d at %I:%M:%S %p")
|
||||
# print(diary_datetime)
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["jrnl", diary_name, "-on", diary_datetime],
|
||||
|
@ -386,16 +399,17 @@ def export():
|
|||
)
|
||||
|
||||
try:
|
||||
subprocess.run(
|
||||
result = subprocess.run(
|
||||
f'printf "%s %s" "{convert_diary_date(create_time)}" {content} | jrnl {diary_name}',
|
||||
shell=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True,
|
||||
)
|
||||
print(result.stderr)
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"Error writing to journal: {e.stderr}")
|
||||
continue
|
||||
raise
|
||||
|
||||
delete_entity(f"{Config.memo_url}/api/v1/{memo['name']}", headers)
|
||||
|
||||
|
@ -412,12 +426,7 @@ def insert():
|
|||
"Usage: script.py insert <diary_name> [bulk|single (default)] 'content'"
|
||||
)
|
||||
|
||||
# TODO is this really need?
|
||||
# if len(sys.argv) == 5 and sys.argv[3] != "single":
|
||||
# sys.exit("Invalid usage for bulk insert.")
|
||||
|
||||
diary_name = sys.argv[2]
|
||||
# do backup ever!
|
||||
insert_type = (
|
||||
"bulk" if len(sys.argv) > 3 and sys.argv[3] == "bulk" else "single"
|
||||
)
|
||||
|
@ -453,13 +462,14 @@ def insert():
|
|||
print("There is no text")
|
||||
sys.exit(1)
|
||||
try:
|
||||
subprocess.run(
|
||||
result = subprocess.run(
|
||||
f'printf "%s %s" "{convert_diary_date(datenow_timestamp)}" {content} | jrnl {diary_name}',
|
||||
shell=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True,
|
||||
)
|
||||
print(result.stderr)
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"Error inserting single entry: {e.stderr}")
|
||||
raise
|
||||
|
@ -478,13 +488,14 @@ def insert():
|
|||
content = shlex.quote(file.read())
|
||||
if hash != make_hash(temp_file_path):
|
||||
try:
|
||||
subprocess.run(
|
||||
result = subprocess.run(
|
||||
f'printf "%s %s" "{convert_diary_date(datenow_timestamp)}" {content} | jrnl {diary_name}',
|
||||
shell=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True,
|
||||
)
|
||||
print(result.stderr)
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(
|
||||
f"Error during bulk import: {e.stderr}, file: {temp_file_path}"
|
||||
|
@ -505,6 +516,7 @@ def insert():
|
|||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
# I want to know if I'm connected...
|
||||
fetch_data(url="https://google.com", rjson=False, log=False)
|
||||
...
|
||||
except Exception as e:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue