Skip to content

Commit

Permalink
Remove hard-coded cached directory
Browse files Browse the repository at this point in the history
  • Loading branch information
mattdailis committed Nov 8, 2023
1 parent 621685f commit 66841a6
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion db.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
from pathlib import Path
import json

db_location = "/Users/dailis/.pm/pm.json"
pm_directory = Path.home() / ".pm"
db_location = pm_directory / "pm.json"


empty_db = {
"issues": [],
"prs": [],
"project_items": {
"items": []
}
}


def retrieve():
ensure_pm_directory_exists()
with open(db_location, "r") as f:
return json.load(f)


def store(contents):
ensure_pm_directory_exists()
with open(db_location, "w") as f:
json.dump(contents, f)


def ensure_pm_directory_exists():
pm_directory.mkdir(parents=True, exist_ok=True)
if not db_location.is_file():
print("Creating empty database at" , db_location)
with open(db_location, "w") as f:
json.dump(empty_db, f)

0 comments on commit 66841a6

Please sign in to comment.