-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from andredelft/feature/better-perseus-parsing
Better parsing of Perseus XML
- Loading branch information
Showing
5 changed files
with
51 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import requests | ||
from bs4 import BeautifulSoup | ||
from pyCTS import CTS_URN | ||
|
||
|
||
STRIP_TAGS = ["bibl", "label", "note"] | ||
|
||
|
||
def strip_tei_xml(xml: str): | ||
body = BeautifulSoup(xml, "xml").TEI | ||
|
||
if not body: | ||
return | ||
|
||
for el in body(STRIP_TAGS): | ||
el.decompose() | ||
|
||
return body.text.strip() | ||
|
||
|
||
def get_perseus_passage(urn: str): | ||
if not CTS_URN(urn).passage_component: | ||
return | ||
|
||
api_url = f"https://scaife-cts.perseus.org/api/cts?request=GetPassage&urn={urn}" | ||
|
||
try: | ||
r = requests.get(api_url) | ||
except requests.HTTPError: | ||
return | ||
|
||
return strip_tei_xml(r.text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{% load i18n %} | ||
|
||
<blockquote> | ||
{{ lemma.perseus_content|truncatewords:100 }} | ||
({% translate "Bron" %}: <a href="https://scaife.perseus.org/reader/{{ lemma.urn | safe }}" target="_blank"><cite>Perseus Digital Library</cite></a>) | ||
</blockquote> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters