diff options
author | André Glüpker <git@wgmd.de> | 2017-10-01 14:50:19 +0200 |
---|---|---|
committer | André Glüpker <git@wgmd.de> | 2017-10-01 14:50:19 +0200 |
commit | 1585395e7e530665c565b88fea15cbea68d3a88d (patch) | |
tree | 204033b68d01e27036a68d625f4474f3254880c2 /Caching.py | |
download | steam-1585395e7e530665c565b88fea15cbea68d3a88d.tar.gz steam-1585395e7e530665c565b88fea15cbea68d3a88d.tar.bz2 steam-1585395e7e530665c565b88fea15cbea68d3a88d.zip |
Initial public release
Diffstat (limited to 'Caching.py')
-rw-r--r-- | Caching.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/Caching.py b/Caching.py new file mode 100644 index 0000000..a048af2 --- /dev/null +++ b/Caching.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 + +import os +import time +THIS_DIR = os.path.dirname(os.path.abspath(__file__)) +CACHE_DIR = os.path.join(THIS_DIR, 'cache') + +class Caching(): + + def readCache(profile, steamid, timetolife): + filepath = os.path.join(CACHE_DIR, profile) + filename = str(steamid)+'.tmp' + complete = os.path.join(filepath, filename) + try: + fileinfo = os.stat(complete) + except FileNotFoundError: + return False + if fileinfo.st_mtime < (time.time() - timetolife): + return False + + with open(complete, 'rt') as cachefile: + content = cachefile.read() + + return content + + def writeCache(profile, steamid, content): + filepath = os.path.join(CACHE_DIR, profile) + filename = str(steamid)+'.tmp' + complete = os.path.join(filepath, filename) + try: + os.makedirs(filepath, exist_ok=True) + with open(complete, 'wt') as cachefile: + cachefile.write(content) + except: + print('Could not create cache file/dir.') + return False + return True + +if __name__ == "__main__": + # TODO(andre): Maybe run tests here? + print('This is a module.') |