Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CacheLastSync(object):
- def __init__(self, save_to:typing.Optional[str]=None):
- prefix = tempfile.gettempdir()
- if not save_to:
- save_to = os.path.join(prefix, fn + ".last_sync_ts")
- self.save_to = save_to
- def get(self) -> int:
- if os.path.exists(self.save_to):
- with open(self.save_to) as f:
- try:
- return int(f.read().strip())
- except:
- msg = "parse last_sync_ts failed"
- logger.exception(msg)
- return -1
- def set(self, value:typing.Optional[int]=None):
- if not value:
- value = str(int(time.time()))
- with open(self.save_to, "w") as f:
- f.write(str(value))
- value = CacheLastSync().get()
- if value > 0:
- data_get["since"] = value*1000
- CacheLastSync().set(value=now)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement