better save path

klloe-save_path
manu 8 years ago
parent 438f646a66
commit 9199fa8634

@ -98,7 +98,11 @@ class Shredder(object):
return False
def _save_item(self, item):
with open(os.path.join(self._save_directory, "{}.json".format(item.id)), "w") as fh:
name = item.subreddit_name_prefixed[2:].lower()
path = "{}/{}/{}.json".format(item.author, name, item.id)
if not os.path.exists(os.path.join(self._save_directory, os.path.dirname(path))):
os.makedirs(os.path.join(self._save_directory, os.path.dirname(path)))
with open(os.path.join(self._save_directory, path), "w") as fh:
# This is a temporary replacement for the old .json_dict property:
output = {k: item.__dict__[k] for k in item.__dict__ if not k.startswith("_")}
output["subreddit"] = output["subreddit"].title

Loading…
Cancel
Save