def run(self): try: while True: apps = db.query("SELECT * FROM app;") for app in apps: db.update("UPDATE app SET token=%d WHERE id=%d" % (random.randint(1, 99999), app.id)) time.sleep(300) except Exception, e: print Exception, ':', e
def post(self, action): self.set_header('Content-Type', 'text/json') if action == 'add': app_id = int(self.get_argument('app_id', -1)) if app_id == -1: self.write(u'缺少 app_id 参数') return logo_url = self.get_file_uploaded_url('logo_url') if logo_url is None: self.write(json.dumps(dict(flag=False, message='图片上传到七牛失败'))) return sql = "INSERT INTO answer(app_id, logo_url, title, subtitle, content) " \ "VALUES(%d, '%s', '%s', '%s', '%s')" \ % (app_id, MySQLdb.escape_string(logo_url), MySQLdb.escape_string(self.get_body_argument('title')), '', MySQLdb.escape_string(self.get_body_argument('content')),) db.insert(sql) self.write(json.dumps(dict(flag=True, url='/test/admin/answer?app_id=%d' % app_id))) elif action == 'edit': _id = int(self.get_argument('id', 1)) answer = db.get('SELECT * FROM answer WHERE id=%d' % _id) if answer is None: self.write(u'找不到该答案') return logo_url = self.get_file_uploaded_url('logo_url') if logo_url is None: self.write(json.dumps(dict(flag=False, message='图片上传到七牛失败'))) return elif logo_url == "": logo_url = answer.logo_url sql = "UPDATE answer SET logo_url='%s', title='%s', " \ "subtitle='%s', content='%s' WHERE id=%d" \ % (MySQLdb.escape_string(logo_url), MySQLdb.escape_string(self.get_body_argument('title')), "", MySQLdb.escape_string(self.get_body_argument('content')), _id) db.update(sql) self.write(json.dumps(dict(flag=True, url='/test/admin/answer')))
def update_pv(app_id, pv, fake_pv): db.update("UPDATE app SET pv=%d, fake_pv=%d WHERE id=%d" % (pv, fake_pv, app_id))
def post(self, action): self.set_header('Content-Type', 'text/json') if action == 'add': qrcode_url = self.get_file_uploaded_url('qrcode_url') if qrcode_url is None: self.write(json.dumps(dict(flag=False, message='图片上传到七牛失败'))) return bg_url = self.get_file_uploaded_url('bg_url') if bg_url is None: self.write(json.dumps(dict(flag=False, message='图片上传到七牛失败'))) return sql = "INSERT INTO app(name, qrcode_url, bg_url, question, intro, input_label, " \ "answer_prefix, uid, follow_tip, retest_tip, pv, fake_pv, active) " \ "VALUES('%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, '%s', '%s', %d, %d, %d)" \ % (MySQLdb.escape_string(self.get_body_argument('name')), MySQLdb.escape_string(qrcode_url), MySQLdb.escape_string(bg_url), MySQLdb.escape_string(self.get_body_argument('question')), MySQLdb.escape_string(self.get_body_argument('intro')), MySQLdb.escape_string(self.get_body_argument('input_label')), '', 1, MySQLdb.escape_string(self.get_body_argument('follow_tip')), MySQLdb.escape_string(self.get_body_argument('retest_tip')), 0, int(self.get_body_argument('fake_pv')), True) db.insert(sql) self.write(json.dumps(dict(flag=True, url='/test/admin/app'))) elif action == 'edit': app_id = int(self.get_argument('app_id', 1)) app = db.get('SELECT * FROM app WHERE id=%d' % app_id) if app is None: self.write(json.dumps(dict(flag=False, message='未找到该 APP'))) return qrcode_url = self.get_file_uploaded_url('qrcode_url') if qrcode_url is None: self.write(json.dumps(dict(flag=False, message='图片上传到七牛失败'))) return elif qrcode_url == '': qrcode_url = app.qrcode_url bg_url = self.get_file_uploaded_url('bg_url') if bg_url is None: self.write(json.dumps(dict(flag=False, message='图片上传到七牛失败'))) return elif bg_url == '': bg_url = app.bg_url sql = "UPDATE app SET name='%s', qrcode_url='%s', bg_url='%s', " \ "question='%s', intro='%s', input_label='%s', follow_tip='%s', retest_tip='%s', " \ "fake_pv=%d WHERE id=%d" \ % (MySQLdb.escape_string(self.get_body_argument('name')), MySQLdb.escape_string(qrcode_url), MySQLdb.escape_string(bg_url), MySQLdb.escape_string(self.get_body_argument('question')), MySQLdb.escape_string(self.get_body_argument('intro')), MySQLdb.escape_string(self.get_body_argument('input_label')), MySQLdb.escape_string(self.get_body_argument('follow_tip')), MySQLdb.escape_string(self.get_body_argument('retest_tip')), int(self.get_body_argument('fake_pv')), app_id) db.update(sql) self.write(json.dumps(dict(flag=True, url='/test/admin/app')))