diff options
author | Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 2020-04-15 07:22:50 +0200 |
---|---|---|
committer | Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 2020-09-10 14:59:55 +0200 |
commit | 0366c773d8a5a5791ff2fec34c680c3a1717cb83 (patch) | |
tree | 582d929815ce296e8cbcb6ebba2df2c167d40cda /data/wikidata/cache.py | |
parent | dc6b73a4c72b0d4ea3a5c1baa6c00fde39e6bad8 (diff) | |
download | vendor_replicant-scripts-0366c773d8a5a5791ff2fec34c680c3a1717cb83.tar.gz vendor_replicant-scripts-0366c773d8a5a5791ff2fec34c680c3a1717cb83.tar.bz2 vendor_replicant-scripts-0366c773d8a5a5791ff2fec34c680c3a1717cb83.zip |
WIP: add cache
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
Diffstat (limited to 'data/wikidata/cache.py')
-rw-r--r-- | data/wikidata/cache.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/data/wikidata/cache.py b/data/wikidata/cache.py new file mode 100644 index 0000000..90e2d7a --- /dev/null +++ b/data/wikidata/cache.py @@ -0,0 +1,45 @@ +#!/bin/env python +# Copyright (C) 2020 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +import json +import os +import sys + +class Cache: + def __init__(self): + file_valid = False + + self.path = os.path.dirname(sys.argv[0]) + os.sep + 'cache.json' + + if os.path.exists(self.path): + self.file = open(self.path, 'r') + big_string = self.file.read() + self.json = json.loads(big_string) + file_valid = True + + if not file_valid: + self.file = open(self.path, 'w') + def close(self): + self.file.close() + def load(self): + return self.json + def store(self, data): + json_str = str(json.dumps(data)) + self.file.write(json_str) + def __str__(self): + pass + def __repr__(self): + pass |