def grab_pages(url): responce = requests.get(url, timeout=10) if not responce: raise ValueError({"msg": "Can`t grab pages, responce is emty!", "code": 101}) dom = BeautifulSoup(responce.content, "lxml") if not dom: raise ValueError({"msg": "Can`t grab pages, dom is emty!", "code": 101}) script = dom.findAll("script") # print(script) match = re.findall(r"rm_h.init\([ ]?(\[\[.*\]\]),", "{}".format(dom.findAll("script")), re.I) if not match: raise ValueError({"msg": "Can`t grab pages, regex result is emty!", "code": 101}) pages = match[0].replace('\'', '\"') # -------------------------------------------------------------------------- def formaturl(obj): if not re.search(r"censored", obj[2], re.I): return "{}{}{}".format(obj[1], obj[0], obj[2]) return list(filter(bool, map(formaturl, json.loads(pages))))
def on_message(self, message): print("WS: on_message", self, message) print(self.collect_process_list()) data = json.loads(message) if data["action"] in ["process-list"]: self.msg({"type": "plist", "data": self.collect_process_list()})
def search(self): data = self.get_argument("data", None) if not data: self.write({"status": "error", "msg": "data is emty!"}) return if not json.isjson(data): self.write({"status": "error", "msg": "data is not json!"}) return data = json.loads(data) data["genres"]["include"] = list(filter(int, data["genres"]["include"])) data["genres"]["exclude"] = list(filter(int, data["genres"]["exclude"])) arr = [*data["genres"]["include"], *data["genres"]["exclude"]] query = Base.source("sql/search.sql") query = query.format(",".join("?" * len(data["genres"]["include"])), ",".join("?" * len(data["genres"]["exclude"]))) result = [] with self.db.connect() as connection: c = connection.cursor() result = c.execute(query, arr).fetchall() if data["text"]: result = list( filter( lambda x: re.search(data["text"], x["search"], re.I), result)) for row in result: row.update({ "title": (row["name"] or row["english"] or row["original"]) }) del row["search"] self.write({"request": data, "result": result})
def to_python(self, value): return json.loads(value) if isinstance(value, str) else value
) TYPES.update(renderers) class Undefined(jinja2.Undefined): def operate(self, *args, **kwargs): return self.__class__() __add__ = __radd__ = __mul__ = __rmul__ = __div__ = __rdiv__ = \ __truediv__ = __rtruediv__ = __floordiv__ = __rfloordiv__ = __mod__ = \ __rmod__ = __pos__ = __neg__ = __call__ = __getitem__ = __lt__ = \ __le__ = __gt__ = __ge__ = __int__ = __float__ = __complex__ = __pow__ = \ __rpow__ = __getattr__ = operate environment = jinja2.Environment( undefined=Undefined, extensions=['jinja2.ext.i18n']) environment.filters['json'] = lambda v: isinstance(v, str) and loads(v) or v def __append_headers(request, response, meta, body = ''): response.body = body.replace('<break>', '\\n') response.content_type = 'application/%s' % meta['type'] if settings.get('crossdomain'): response.set_header('Access-Control-Allow-Credentials', settings['crossdomain'].get('credentials') and 'true' or 'false' ) response.set_header('Access-Control-Allow-Headers', ','.join( settings['crossdomain'].get('headers') or [] )) response.set_header('Access-Control-Allow-Origin',