SHARE
TWEET

Untitled

a guest Aug 19th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class CacheLastSync(object):
  2.  
  3.     def __init__(self, save_to:typing.Optional[str]=None):
  4.         prefix = tempfile.gettempdir()
  5.         if not save_to:
  6.             save_to = os.path.join(prefix, fn + ".last_sync_ts")
  7.         self.save_to = save_to
  8.  
  9.     def get(self) -> int:
  10.  
  11.         if os.path.exists(self.save_to):
  12.             with open(self.save_to) as f:
  13.                 try:
  14.                     return int(f.read().strip())
  15.                 except:
  16.                     msg = "parse last_sync_ts failed"
  17.                     logger.exception(msg)
  18.         return -1
  19.  
  20.     def set(self, value:typing.Optional[int]=None):
  21.         if not value:
  22.             value = str(int(time.time()))
  23.         with open(self.save_to, "w") as f:
  24.             f.write(str(value))
  25.  
  26.  
  27.  
  28.     value = CacheLastSync().get()
  29.     if value > 0:
  30.         data_get["since"] = value*1000
  31.  
  32.  
  33.     CacheLastSync().set(value=now)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top