Skip to content

Commit

Permalink
Merge pull request #142 from MrIbrahem/update
Browse files Browse the repository at this point in the history
improve sort studies files
  • Loading branch information
MrIbrahem authored Jun 19, 2024
2 parents 91e2026 + 7fa756f commit 840f49b
Show file tree
Hide file tree
Showing 43 changed files with 5,686 additions and 1,942 deletions.
25 changes: 0 additions & 25 deletions fix_mass/fix_sets/bots/done.py

This file was deleted.

53 changes: 34 additions & 19 deletions fix_mass/fix_sets/bots/get_img_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,51 @@
# import sys
import re
import json

# import os
from pathlib import Path

from newapi import printe
from newapi.ncc_page import NEW_API
from fix_mass.fix_sets.jsons_dirs import get_study_dir, jsons_dir

api_new = NEW_API("www", family="nccommons")
api_new.Login_to_wiki()

Dir = Path(__file__).parent.parent

st_dic_infos = Dir / "jsons/studies_files_infos"

# st_dic_infos = jsons_dir / "studies_files_infos"

def dump_st(data, file):

def dump_st(data, study_id):
# ---
study_id_dir = get_study_dir(study_id)
# ---
file = study_id_dir / "img_info.json"
# ---
with open(file, "w", encoding="utf-8") as f:
json.dump(data, f, ensure_ascii=False, indent=2)
printe.output(f"<<green>> write {len(data)} to file: {file}")


def get_cach_img_info(study_id):
# ---
# file = st_dic_infos / f"{study_id}_s_id.json"
# ---
study_id_dir = get_study_dir(study_id)
# ---
file = study_id_dir / "img_info.json"
# ---
if file.exists():
printe.output(f"<<green>> get_cach_img_info: {file} exists")
with open(file, encoding="utf-8") as f:
return json.load(f)
# ---
return False

def gt_img_info(titles, id_to_url=None):
# ---
if not id_to_url:
id_to_url = {}
# ---
# ---
titles = [titles] if not isinstance(titles, list) else titles
# ---
titles = [x for x in titles if x]
Expand Down Expand Up @@ -117,7 +135,7 @@ def gt_img_info(titles, id_to_url=None):
# ---
revisions = revisions[0]["content"]
# match * Image ID: 58331091 in revisions.split("\n")
ma = re.search(r"Image ID: (\d+)", revisions)
ma = re.search(r"Image ID: (\d+)", revisions, re.IGNORECASE)
if ma:
info[title]["img_id"] = ma.group(1)
info[title]["img_url"] = id_to_url.get(str(ma.group(1)), "")
Expand All @@ -131,34 +149,31 @@ def gt_img_info(titles, id_to_url=None):

def one_img_info(title, study_id, json_data):
# ---
file = st_dic_infos / f"{study_id}_s_id.json"
# ---
if file.exists():
printe.output(f"<<green>> one_img_info: {file} exists")
with open(file, encoding="utf-8") as f:
return json.load(f)
cach = get_cach_img_info(study_id)
if cach:
return cach
# ---
id_to_url = {}
# ---
for x in json_data:
for _, image in enumerate(x["images"], start=1):
for image in x["images"]:
id_to_url[str(image["id"])] = image["public_filename"]
# ---
info = gt_img_info(title, id_to_url)
# ---
# printe.output(json.dumps(pages, indent=2))
# ---
dump_st(info, file)
dump_st(info, study_id)
# ---
return info


def test():
title = ["File:1st metatarsal head fracture (Radiopaedia 99187-120594 Frontal 1).png", "File:Appendicitis (CT angiogram) (Radiopaedia 154713-134732 This comic explains the pathophysiology of appendicitis. 02).jpg"]
title = [
"File:1st metatarsal head fracture (Radiopaedia 99187-120594 Frontal 1).png",
"File:Appendicitis (CT angiogram) (Radiopaedia 154713-134732 This comic explains the pathophysiology of appendicitis. 02).jpg",
]
info = gt_img_info(title)
# ---
print(json.dumps(info, indent=2))
# ---


if __name__ == "__main__":
Expand Down
4 changes: 3 additions & 1 deletion fix_mass/fix_sets/bots/has_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
if not studies_has_url_dir.exists():
studies_has_url_dir.mkdir()

already_has_url = [ x.replace(".h", "") for x in os.listdir(studies_has_url_dir) ]
already_has_url = [x.replace(".h", "") for x in os.listdir(studies_has_url_dir)]


def find_has_url(study_id):
file = studies_has_url_dir / f"{study_id}.h"
if file.exists():
return True
return False


def has_url_append(study_id):
file = studies_has_url_dir / f"{study_id}.h"
if not file.exists():
Expand Down
100 changes: 0 additions & 100 deletions fix_mass/fix_sets/bots/mv_files.py

This file was deleted.

114 changes: 0 additions & 114 deletions fix_mass/fix_sets/bots/set_text.py

This file was deleted.

Loading

0 comments on commit 840f49b

Please sign in to comment.