def deleteAll(): if request.method == "POST": json_dict = request.get_json() token = json_dict["token"] r = myRedis() r.lrem("token", token, 0) return "OK" else: return "ERROR"
def delete(): if request.method == "POST": json_dict = request.get_json() token = json_dict["token"] index = json_dict["index"] r = myRedis() r.lset(token, index, "del") r.lrem(token, "del", 0) return "OK" else: return "ERROR"
def fetch(): if request.method == "POST": json_dict = request.get_json() token = json_dict["token"] r = myRedis() r.lrem(token, "del", 0) datas = r.lrange(token, 0, -1) results = {"list": []} for data in datas: results["list"].append(json.loads(data)) return jsonify(results) else: return "ERROR"
def add(): if request.method == "POST": json_dict = request.get_json() token = json_dict["token"] content = { "title": json_dict["title"], "lowPrice": json_dict.get("lowPrice", None), "highPrice": json_dict.get("highPrice", None), "shops": json_dict["shops"], "date": json_dict["date"] } r = myRedis() r.lpush(token, json.dumps(content)) return "OK" else: return "ERROR"
def update(): if request.method == "POST": json_dict = request.get_json() token = json_dict["token"] index = json_dict["index"] content = { "title": json_dict["title"], "lowPrice": json_dict["lowPrice"], "highPrice": json_dict["highPrice"], "shops": json_dict["shops"], "date": json_dict["date"] } r = myRedis() r.lset(token, index, json.dumps(content)) return "OK" else: return "ERROR"
def echo(): kwargs = {} kwargs["thing"] = "LINE" kwargs["code"] = request.args.get("code") kwargs["state"] = request.args.get("state") url = "https://notify-bot.line.me/oauth/token" data = { "grant_type": "authorization_code", "code": kwargs["code"], # "redirect_uri":"http://192.168.43.37:9999/echo", "redirect_uri": "http://localhost:9999/echo", "client_id": "u8q2t2XzFHd6TLHuZ2ejai", "client_secret": "54wq40T8HYKFbkNuvcwjhDBYcQmwiaxX2nD35AJtg73" } res = requests.post(url, data) resJson = res.json() print(resJson["status"]) kwargs["token"] = resJson["access_token"] r = myRedis() r.lpush("token", kwargs["token"]) return render_template("flask.html", **kwargs)
def main(): r = myRedis() tokens = r.lrange("token", 0, -1) for token in tokens: contents = r.lrange(token, 0, -1) for index, content in enumerate(contents): notifyStr = "" data = json.loads(content) params = { "q": data["title"], "pl": data["lowPrice"], "ph": data["highPrice"], "sort": "p", "page": 1 } shops = data["shops"] for shop in shops: params["pr[]"] = shop notifyStr += getResult("https://feebee.com.tw/all/", **params) if len(notifyStr) != 0: titleStr = "\n" + data["title"] + ":" + str( data["lowPrice"]) + "~" + str(data["highPrice"]) + "\n" response = gogoNotify(token, titleStr, notifyStr) print(response) print(token) if json.loads(response)["status"] != 200: r.lrem("token", token, 0) r.delete(token) continue else: r.lset(token, index, "del") r.lrem(token, "del", 0)
def verify(): if request.method == "GET": notVerifyToken = request.args.get("token") print(notVerifyToken) code = sendNotify(notVerifyToken) print(code) if code == 200: r = myRedis() r.lpush("token", notVerifyToken) return "OK" elif code == 401: return "NG" elif code == 878787: return "Unicode" else: return "ERROR" return "ERROR" else: print("f**k") return "ERROR"
shopsList = { "ybid": Shop("Yahoo!奇摩拍賣", "tw.bid.yahoo.com"), "shopee": Shop("蝦皮拍賣", "shopee.tw"), "ruten": Shop("露天拍賣", "www.ruten.com.tw"), "kingstone": Shop("金石堂網路書店", "www.kingstone.com.tw/"), "books": Shop("博客來", "www.books.com.tw"), "taaze": Shop("TAAZE讀冊生活", "www.taaze.tw"), "24hpchome": Shop("PChome24h購物", "24h.pchome.com.tw"), "ybuy": Shop("Yahoo奇摩購物中心", "tw.buy.yahoo.com"), "pchome": Shop("PChome線上購物", "mall.pchome.com.tw"), "gohappy": Shop("friDay購物", "shopping.friday.tw"), "udn": Shop("udn買東西購物中心", "shopping.udn.com"), "momoshop": Shop("momo購物網", "www.momoshop.com.tw") } queue = Queue() r = myRedis() def gogoParser(queue): while queue.empty() is False: params = queue.get() print(threading.current_thread()) url = "https://feebee.com.tw/all/" ansStr = "" for shop in params["pr[]"]: rule = params.copy() rule["pr[]"] = shop rule["token"] = None rule["index"] = None if rule["pl"] == 0: