def new_resources(res_ver): global g_client, g_resmgr, g_last_check app.logger.info("Resource update: %s", g_client.res_ver) g_client.res_ver = res_ver do_check() g_resmgr = resource_mgr.ResourceManager(g_client.res_ver, RESOURCES_DIR, app.logger) g_last_check = time.time()
ctx = cairo.Context(img) handle = Rsvg.Handle().new_from_data(ET.tostring(root)) ctx.scale(2, 2) handle.render_cairo(ctx) im = Image.frombuffer("RGBA", (2 * width, 2 * height), bytes(img.get_data()), "raw", "BGRA", 0, 1) return im if __name__ == "__main__": import apiclient, sys, logging, resource_mgr from info import ProducerInfo logging.basicConfig() log = logging.getLogger("resource") mgr = resource_mgr.ResourceManager(10074500, "./resources/", log) def scale(im, fac): w, h = im.size if fac == 1: return im elif fac > 1: return im.resize((w // fac, h // fac), Image.BICUBIC) elif fac == -1: return im.crop((0, 0, h, h)) elif fac == -2: im = im.resize((w // 2, h // 2), Image.BICUBIC) w, h = im.size new_im = Image.open('twitter_bg.png') new_w, new_h = new_im.size new_im.paste(im, ((new_w - w) // 2, (new_h - h) // 2), im)
SNAPSHOT_DIR = BASE + "data/snap/" RESOURCES_DIR = BASE + "data/resources/" THROTTLE = 2 RES_POLL = 600 LOG_FILE = BASE + "log/info.log" DEF_MAX_AGE = 300 g_client = apiclient.ApiClient(account.user_id, account.viewer_id, account.udid) g_lock = threading.Lock() g_last_fetch = 0 g_last_check = 0 g_resmgr = resource_mgr.ResourceManager(g_client.res_ver, RESOURCES_DIR, app.logger) class RequestFormatter(logging.Formatter): def format(self, record): s = logging.Formatter.format(self, record) try: return '[%s] [%d] [%s] [%s %s] ' % ( self.formatTime(record), account.index, request.remote_addr, request.method, request.path) + s except: return '[%s] [%d] [SYS] ' % (self.formatTime(record), account.index) + s if not app.debug: