Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support SARIT, add स्कन्दपुराणम् #89

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ db_seed_all:
python -m ambuda.seed.lookup.role
python -m ambuda.seed.lookup.page_status
python -m ambuda.seed.texts.gretil
python -m ambuda.seed.texts.sarit
python -m ambuda.seed.texts.ramayana
python -m ambuda.seed.texts.mahabharata
python -m ambuda.seed.dcs
Expand Down
1 change: 1 addition & 0 deletions ambuda/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"saundaranandam",
"hamsadutam",
],
"purana": ["skandapuranam"],
"anye": [
"bodhicaryavatara",
],
Expand Down
23 changes: 12 additions & 11 deletions ambuda/seed/texts/gretil.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Spec:


REPO = "https://github.com/ambuda-org/gretil.git"
BRANCH = "main"
PROJECT_DIR = Path(__file__).resolve().parents[3]
DATA_DIR = PROJECT_DIR / "data" / "ambuda-gretil"
#: Slug to use for texts that have only one section.
Expand Down Expand Up @@ -57,15 +58,15 @@ class Spec:
}


def fetch_latest_data():
def fetch_latest_data(repo: str, branch: str, data_dir: str):
"""Fetch the latest data from our GitHub repo."""
if not DATA_DIR.exists():
subprocess.run(f"mkdir -p {DATA_DIR}", shell=True)
subprocess.run(f"git clone --branch=main {REPO} {DATA_DIR}", shell=True)
if not data_dir.exists():
subprocess.run(f"mkdir -p {data_dir}", shell=True)
subprocess.run(f"git clone --branch={branch} {repo} {data_dir}", shell=True)

subprocess.call("git fetch origin", shell=True, cwd=DATA_DIR)
subprocess.call("git checkout main", shell=True, cwd=DATA_DIR)
subprocess.call("git reset --hard origin/main", shell=True, cwd=DATA_DIR)
subprocess.call("git fetch origin", shell=True, cwd=data_dir)
subprocess.call(f"git checkout {branch}", shell=True, cwd=data_dir)
subprocess.call(f"git reset --hard origin/{branch}", shell=True, cwd=data_dir)


@dataclass
Expand Down Expand Up @@ -191,9 +192,9 @@ def parse_tei_document(xml: ET.Element) -> Document:
return Document(header=header_blob, sections=sections)


def add_document(engine, spec: Spec):
def add_document(engine, data_dir: str, spec: Spec):
log(f"Writing text: {spec.slug}")
document_path = DATA_DIR / "1_sanskr" / "tei" / spec.filename
document_path = data_dir / spec.filename

delete_existing_text(engine, spec.slug)
with Session(engine) as session:
Expand Down Expand Up @@ -227,13 +228,13 @@ def add_document(engine, spec: Spec):

def run():
log("Downloading the latest data ...")
fetch_latest_data()
fetch_latest_data(REPO, BRANCH, DATA_DIR)

log("Initializing database ...")
engine = create_db()

for spec in ALLOW:
add_document(engine, spec)
add_document(engine, DATA_DIR / "1_sanskr" / "tei", spec)
log("Done.")


Expand Down
28 changes: 28 additions & 0 deletions ambuda/seed/texts/sarit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""Parse Sanskrit texts from SARIT.

"""
from ambuda.seed.texts.gretil import *


REPO = "https://github.com/sarit/SARIT-corpus.git"
BRANCH = "master"
PROJECT_DIR = Path(__file__).resolve().parents[3]
DATA_DIR = PROJECT_DIR / "data" / "ambuda-sarit"

ALLOW = [Spec("skandapuranam", "skandapurANam", "skandapurana.xml")]


def run():
log("Downloading the latest data ...")
fetch_latest_data(REPO, BRANCH, DATA_DIR)

log("Initializing database ...")
engine = create_db()

for spec in ALLOW:
add_document(engine, DATA_DIR, spec)
log("Done.")


if __name__ == "__main__":
run()
1 change: 1 addition & 0 deletions ambuda/templates/texts/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ <h1>Texts</h1>

{{ text_list('itihasa', 'itihAsAH') }}
{{ text_list('kavya', 'kAvyAni') }}
{{ text_list('purana', 'purANAni') }}
{{ text_list('anye', 'anye granthAH') }}

{% endblock %}
1 change: 1 addition & 0 deletions ambuda/views/reader/texts.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"bhattikavyam",
"shatakatrayam",
"shishupalavadham",
"skandapuranam",
}


Expand Down