def get(self): conn = getDatabaseConnection() #获取游标 db_cursor = conn.cursor() try: db_cursor.execute("SELECT COUNT(*) FROM tbl_numbers;") except Exception as e: print(e) else: result_count = db_cursor.fetchone()[0] finally: conn.close() if _worker: result_data = { "running": _worker.is_alive(), "count": result_count, "product": _worker.product, "city": _worker.city, "cityCode": _worker.cityCode, "province": _worker.province, "provinceCode": _worker.provinceCode, "groupKey": _worker.groupKey, "autoTerminate": _worker.autoTerminate, "history": _worker.history } else: result_data = { "running": False, "count": result_count } self.write_json(result_data)
def getNum(self): conn = getDatabaseConnection() try: r = requests.get("https://m.10010.com/NumApp/NumberCenter/qryNum", params={ "callback": "jsonp_queryMoreNums", "provinceCode": self.provinceCode, "cityCode": self.cityCode, "groupKey": self.groupKey, "searchCategory": "3", "net": "01", "qryType": "02", "goodsNet": "4" }) nums = re.findall(r"\d{11}", r.text) ret = map(lambda num: (num, self.makeTag(num)), nums) cur = conn.cursor() cur.executemany("INSERT OR IGNORE INTO tbl_numbers(number, tag) VALUES(?, ?);", ret) conn.commit() if cur.rowcount > 0: self.history.append((time.strftime("%Y-%m-%d %H:%M:%S"), cur.rowcount)) if len(self.history) == 201: self.history.pop(0) return len(nums), cur.rowcount except: return 0, 0 finally: conn.close()
def empty(): global w if w: if w.is_alive(): return jsonify({}) conn = getDatabaseConnection() cur = conn.cursor() cur.execute("DELETE FROM tbl_numbers;") conn.commit() conn.close() return jsonify({})
def get(self): if _worker: if _worker.is_alive(): result_data = {} conn = getDatabaseConnection() db_cursor = conn.cursor() try: db_cursor.execute("DELETE FROM tbl_numbers;") except Exception as e: print(e) else: conn.commit() result_data = {} finally: conn.close() self.write_json(result_data)
def getNums(): query = [] if request.args.get("filter"): filters = request.args.get("filter").split("|") for f in filters: query.append("tag LIKE '%,{},%'".format(f)) if request.args.get("custom"): query.append("number REGEXP '{}'".format(request.args.get("custom"))) conn = getDatabaseConnection() cur = conn.cursor() if query: cur.execute("SELECT number,tag FROM tbl_numbers WHERE {};".format( " OR ".join(query))) else: cur.execute("SELECT number,tag FROM tbl_numbers;") ret = cur.fetchall() conn.close() ret = list(map(lambda i: {"number": i[0], "tag": i[1].strip(",")}, ret)) return jsonify(ret)
def status(): global w conn = getDatabaseConnection() cur = conn.cursor() cur.execute("SELECT COUNT(*) FROM tbl_numbers;") ret = cur.fetchone()[0] conn.close() if w: return jsonify({ "running": w.is_alive(), "count": ret, "city": w.city, "cityCode": w.cityCode, "province": w.province, "provinceCode": w.provinceCode, "groupKey": w.groupKey, "autoTerminate": w.autoTerminate, "history": w.history }) return jsonify({"running": False, "count": ret})
def get(self): query = [] if self.get_argument("filter", None): filters = self.get_argument("filter").split("|") for f in filters: query.append("tag LIKE '%,{},%'".format(f)) if self.get_argument("custom", None): query.append("number REGEXP '{}'".format(self.get_argument("custom"))) conn = getDatabaseConnection() db_cursor = conn.cursor() try: if query: db_cursor.execute("SELECT number,tag FROM tbl_numbers WHERE {};".format(" OR ".join(query))) else: db_cursor.execute("SELECT number,tag FROM tbl_numbers;") except Exception as e: print(e) else: retsult_count = db_cursor.fetchall() finally: conn.close() result_data = list(map(lambda i: {"number": i[0], "tag": i[1].strip(",")}, retsult_count)) self.write_json(result_data)