def tradingviewx(transport): ##{ buffer = ByteBuffer() xhr = next(transport) while True: try: data = xhr.raw.read(XHR_READ_SIZE) except Exception: xhr = next(transport) continue buffer.write(data) line = buffer.read_until(b"\r\n", consume=True) if not line: continue if line == ": -1": continue if line.startswith("data: "): line = line[6:] try: pkg = jsload(line) except Exception: continue channel = pkg.get("text", {}).get("channel") if channel != "chat_bitcoin": continue content = pkg.get("text").get("content") login = content.get('username') msg = content.get("text", "").encode("utf-8", errors="replace") meta = content.get("meta", {}) url = meta.get("url", "").encode("utf-8", errors="replace") if url: msg = "{}\n{:<19}{}{}{}".format(msg, "", COLOR_10, url, COLOR_0) if not msg: continue yield (login, msg)
def tradingviewx(transport):##{ buffer = ByteBuffer() xhr = next(transport) while True: try: data = xhr.raw.read(XHR_READ_SIZE) except Exception: xhr = next(transport) continue buffer.write(data) line = buffer.read_until(b"\r\n", consume=True) if not line: continue if line == ": -1": continue if line.startswith("data: "): line = line[6:] try: pkg = jsload(line) except Exception: continue channel = pkg.get("text", {}).get("channel") if channel != "chat_bitcoin": continue content = pkg.get("text").get("content") login = content.get('username') msg = content.get("text", "").encode("utf-8", errors="replace") meta = content.get("meta", {}) url = meta.get("url", "").encode("utf-8", errors="replace") if url: msg = "{}\n{:<19}{}{}{}".format(msg, "", COLOR_10, url, COLOR_0) if not msg: continue yield(login, msg)