Skip to content

Commit

Permalink
use YAML for .counter.dat (ZettelGeist#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
icornelius committed May 24, 2024
1 parent 3337020 commit 1989571
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions zettelgeist/zettel.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import os
import os.path
import json
import shutil

from time import strftime
Expand Down Expand Up @@ -730,17 +729,17 @@ def get_count(counter_path, counter_name):
# Create counter db if not present.
if not os.path.exists(counter_path):
with open(counter_path, 'w') as dbfile:
json.dump({}, dbfile)
yaml.dump({}, dbfile)

# Read count from counter. If non-existent, start at 0.
with open(counter_path, 'r') as dbfile:
db = json.load(dbfile)
db = yaml.load(dbfile, Loader=Loader)
count = db.get(counter_name, -1) + 1

# save count for next invocation
with open(counter_path, 'w') as dbfile:
db[counter_name] = count
json.dump(db, dbfile)
yaml.dump(db, dbfile)
return count

def dict_as_yaml(data):
Expand Down

0 comments on commit 1989571

Please sign in to comment.