# -*- coding: utf-8 -*- import os import __init__ as model def putRawData(filepath, data): try: dir = os.path.dirname(filepath) if not os.path.exists(dir): os.makedirs(dir) with open(filepath, 'wb') as f: f.write(data) except Exception, e: #todo: raise error properly for this model raise e # private info, warn, error = model.logging('[FileResourceModel]')
def toDict(self): return { 'url': self.url, 'path': self.path, 'expire_timestamp': self.expire_timestamp, 'expire_string': self.expire_string, } def _calc_exp(self, expire): if expire: sec = int( t.time() + expire ) return ( sec, t.strftime("%Y-%m-%dT%H:%M:%SZ", t.gmtime(sec)) )# rfc3339 else: return ( 0, '' ) # private info, warn, error = model.logging('[LinkProjectionModel]') class Model(): def __init__(self, conn): self._conn = conn def find(self, url): query = 'SELECT * FROM link_projection WHERE url=?' result = self._conn.execute(query, [url]) return result.fetchone() def exist(self, url): return self.find(url) is not None def put(self, record): if self.exist(record.url):