def log(obj, *tags): file_name, function_name = get_file_scope() data = { "tags": tags, "object": obj, "file": file_name, "function": function_name, "time": time.time() } just.append(data, LOG_FILE)
def test_txt_append(): fname = "testobj.txt" obj = "bla" just.append(obj, "testobj.txt") try: assert [x for x in just.iread(fname)] == [obj] just.append(obj, "testobj.txt") assert [x for x in just.iread(fname)] == [obj, obj] finally: os.remove(fname)
def add_text(): url = request.json["url"] print("url", url) if any([y in url for y in blocklist]): print("blocked", [y for y in blocklist if y in url]) return jsonify({}) html = request.json["html"] html = lxml.html.tostring(lxml.html.fromstring(html.encode("utf8"))) tree = make_tree(html, url) html = lxml.html.tostring(tree).decode("utf8") slugged_url = slug_url(url) t1 = time.time() # meta_path = BASE_PATH / "meta/v1/{}_{}.json".format(t1, slugged_url) # try: # article = parse_article(html, url) # metadata = article.to_dict(keys=ARTICLE_KEYS_TO_KEEP, skip_if_empty=True) # except Exception as e: # metadata = {"error": str(e)} # metadata["creation_time"] = t1 # metadata["slugged_url"] = slugged_url # with open(meta_path, "w") as f: # json.dump(metadata, f, indent=4) # just.write(metadata, meta_path) html_path = BASE_PATH + "html/{}_{}.html.gz".format(t1, slugged_url) print("html_path", html_path) just.write(html, html_path) obj = {"path": str(html_path), "url": url, "time": str(time.time())} print("META_PATH", META_PATH) just.append(obj, META_PATH) last.append(html) last_urls.append(url) print("saved", url) return jsonify({"urls": list(last_urls)})
def record(data_name, data_path="~/tracktrack/"): path = just.make_path(data_path + data_name + "/") offset = len(just.glob(path + "/im*.png")) for image, it, mouse_pos in yield_images(): cv2.imwrite(path + "/im_{}.png".format(it + offset), image) just.append(mouse_pos, path + "/positions.jsonl")
def add_video_watch(): just.append(request.json, VIDEO_PATH) print("video watched") return ""