Skip to content

Commit

Permalink
added links
Browse files Browse the repository at this point in the history
  • Loading branch information
lobsam committed Dec 24, 2024
1 parent a929870 commit d0c5ea6
Show file tree
Hide file tree
Showing 14 changed files with 1,228 additions and 43 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jsonpickle
14 changes: 7 additions & 7 deletions src/pecha_uploader/category/upload.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import json
import urllib
from typing import List
from urllib.error import HTTPError
from urllib.parse import urlencode
from urllib.request import Request, urlopen

from pecha_uploader.config import PECHA_API_KEY, baseURL, headers

Expand All @@ -28,19 +29,18 @@ def post_category(en_category_list: List[str], bo_category_list: List[str]):
input_json = json.dumps(category)
values = {"json": input_json, "apikey": PECHA_API_KEY}

data = urllib.parse.urlencode(values)
data = urlencode(values)
binary_data = data.encode("ascii")
req = urllib.request.Request(url, binary_data, headers=headers)
req = Request(url, binary_data, headers=headers)

try:
response = urllib.request.urlopen(req)
response = urlopen(req)
res = response.read().decode("utf-8")
print("categories response: ", res)
if "error" not in res:
return {"status": True}
elif "already exists" in res:
return {"status": True}
return {"status": False, "error": res}
return {"status": True, "error": res}
except HTTPError as e:
print("Error code: ", e)
print("Error code: ", e, list(map(lambda x: x["name"], en_category_list))[-1])
return {"status": False, "error": e}
17 changes: 9 additions & 8 deletions src/pecha_uploader/index/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pecha_uploader.config import PECHA_API_KEY, baseURL, headers


def post_index(index: str, category_list: List[str], nodes: Dict):
def post_index(index_str: str, category_list: List[str], nodes: Dict):
""" "
Post index value for article settings.
`index`: str, article title,
Expand All @@ -18,7 +18,9 @@ def post_index(index: str, category_list: List[str], nodes: Dict):
"primary": True (You must have a primary title for each language)
}
"""
url = baseURL + "api/v2/raw/index/" + urllib.parse.quote(index.replace(" ", "_"))
url = (
baseURL + "api/v2/raw/index/" + urllib.parse.quote(index_str.replace(" ", "_"))
)

# "titles" : titleLIST,
# "key" : index,
Expand All @@ -29,18 +31,19 @@ def post_index(index: str, category_list: List[str], nodes: Dict):
# "addressTypes" : ["Integer", "Integer"],

index = {"title": "", "categories": [], "schema": {}}
index["title"] = index
index["title"] = index_str
index["categories"] = list(map(lambda x: x["name"], category_list))
index["schema"] = nodes

# if text is commentary
if "base_text_mapping" in category_list[-1].keys():
index["base_text_titles"] = category_list[-1]["base_text_titles"]
index["base_text_mapping"] = category_list[-1]["base_text_mapping"]
index["collective_title"] = index
index["collective_title"] = index_str
index["dependence"] = category_list[-1]["link"]

input_json = json.dumps(index, indent=4, ensure_ascii=False)

values = {
"json": input_json,
"apikey": PECHA_API_KEY,
Expand All @@ -51,11 +54,9 @@ def post_index(index: str, category_list: List[str], nodes: Dict):
try:
response = urllib.request.urlopen(req)
res = response.read().decode("utf-8")
print(res)
if "error" in res and "already exists." not in res:
return {"status": False, "error": res}
return {"status": True}
except HTTPError as e:
print("Error code: ", e.code)
print(e.read())
return {"status": False, "error": e}
print("Error code: ", e.code, e.read())
return {"status": False, "error": e.read()}
162 changes: 162 additions & 0 deletions src/pecha_uploader/jsondata/texts/baseText/Prayer_of_Kuntuzangpo.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"source": {
"categories": [
{
"name": "anotation styling test",
"enDesc": "",
"enShortDesc": ""
}
],
"books": [
{
"title": "anotation styling test",
"language": "en",
"versionSource": " ",
"completestatus": "in_progress",
"content": [],
"direction": "ltr"
}
]
},
"target": {
"categories": [
{
"name": "དཔེ་དེབ་འདིས་ཁྱེད་ལ་ཚོད་ལྟ་ཞིག་བྱེད་རྒྱུ་རེད།",
"heDesc": "",
"heShortDesc": ""
}
],
"books": [
{
"title": "དཔེ་དེབ་འདིས་ཁྱེད་ལ་ཚོད་ལྟ་ཞིག་བྱེད་རྒྱུ་རེད།",
"language": "bo",
"versionSource": " ",
"completestatus": "in_progress",
"content": [
[
"<sapche>དང་པོ་</sapche>{ཀུན་གྱི་གཞི་ནི་}སོགས་ཚིག་རྐང་བདུན་གྱིས་འཆད་དེ།<sup>*</sup> <i class='footnote'><b>བདུན་གྱིས་འཆད་དེ</b> The text inside the footnote</i>",
"སྒྲ་ཐལ་འགྱུར་ཆེན་པོའི་རྒྱུད་ལས། <br> (འཁོར་བའི་ཐོག་མ་གནས་འདི་གང་། <br> སེམས་ཅན་འཁྲུལ་པ་ཅི་ལས་བྱུང་། ། <br> རང་གི་ཡེ་ཤེས་གནས་ལུགས་གང། །) <br> ཞེས་གསུངས་པ་ལྟར་",
"འཁྲུལ་གྲོལ་{ཀུན༵་}{གྱི༵་}ཐོག་མའི་སྤྱི་གཞི། ཀུན་གཞི་མ་ཡི་ཀློང་ཆེན། ལྷུན་གྲུབ་མ་ཡི་སྟོང་ར། མིང་མ་ཐོག་པའི་སྤྱི་ས། འཁོར་འདས་གཉིས་ཀྱི་བར་མ་དོ་ཞེས་མིང་དུ་མས་བསྙད་པའི་{གཞི༵འི་}ངོ་བོའི་གནས་ཚུལ་ཉིད་{ནི༵}། ",
"མུ་ཏིག་ཕྲེང་བ་ལས། <br> (གནས་ལུགས་བསམ་གྱིས་མི་ཁྱབ་ཀྱང་། ། <br> ཡེ་ཤེས་རྣམ་པ་གསུམ་ཡིན་ནོ། ། <br> འཁྲུལ་གཞི་རྣམ་པ་མང་ལགས་ཀྱང་། ། <br> ལྷུན་གྲུབ་དང་ནི་ཐུགས་རྗེའོ། །) <br> ཞེས་པ་ལྟར་གྱི་",
"<sapche>སྤྱི་གཞི་དེའི་གནས་ཚུལ་གཏན་ལ་དབབ་པ་ལ། སྐྱོན་ཅན་གྱི་འདོད་པ་དྲུག་དང་། སྐྱོན་མེད་ཀྱི་འདོད་པ་གཅིག་སྟེ་གཉིས་སོ། །</sapche>"
]
],
"direction": "ltr"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{
"source": {
"categories": [
{
"name": "The Buddha Teachings",
"enDesc": "",
"enShortDesc": ""
},
{
"name": "Vajra Cutter",
"enDesc": "",
"enShortDesc": ""
},
{
"name": "Commentaries",
"enDesc": "",
"enShortDesc": ""
},
{
"name": "Vajra Cutter Commentary Book",
"enDesc": "",
"enShortDesc": "",
"base_text_titles": [
"Vajra Cutter Book"
],
"base_text_mapping": "many_to_one",
"link": "Commentary"
}
],
"books": [
{
"title": "Vajra Cutter Commentary Book",
"language": "en",
"versionSource": "https://library.bdrc.io/show/bdr:WA1KG12670?tabs=bdr:MW3JT13747,bdr:W3JT13747",
"direction": "ltr",
"completestatus": "done",
"content": {
"Vajra Cutter Commentary Book":{
"data":[],
"Commentary on the Structure of the Sutra": {
"data": [],
"The Unbroken Lineage of Buddha's Teachings": {
"data": []
}
},
"Explanation of the Meaning of Words": {
"data": [],
"The Unbroken Lineage of Buddha's Teachings": {
"data": []
}
}}
}
}
]
},
"target": {
"categories": [
{
"name": "སངས་རྒྱས་ཀྱི་བཀའ་།",
"heDesc": "",
"heShortDesc": ""
},
{
"name": "རྡོ་རྗེ་གཅོད་པ།",
"heDesc": "",
"heShortDesc": ""
},
{
"name": "འགྲེལ་པ།",
"heDesc": "",
"heShortDesc": ""
},
{
"name": "རྡོ་རྗེ་གཅོད་པ་འགྲེལ་པ་དེབ།",
"heDesc": "",
"heShortDesc": "",
"base_text_titles": [
"Vajra Cutter Book"
],
"base_text_mapping": "many_to_one",
"link": "Commentary"
}
],
"books": [
{
"title": "རྡོ་རྗེ་གཅོད་པ་འགྲེལ་པ་དེབ།",
"language": "bo",
"versionSource": "https://library.bdrc.io/show/bdr:WA1KG12670?tabs=bdr:MW3JT13747,bdr:W3JT13747",
"direction": "ltr",
"completestatus": "done",
"content": {
"རྡོ་རྗེ་གཅོད་པ་འགྲེལ་པ་དེབ།":{
"data":[],
"མདོའི་ལུས་ཀྱི་འགྲེལ་པ།": {
"data": [],
"སངས་རྒྱས་ཀྱི་གདུང་རྒྱུན་མི་འཆད་པ་བསྟན་པ།": {
"data": [
"<1><1>རྒྱ་གར་སྐད་དུ། །ཨཱརྱ་བྷ་ག་བ་ཏཱི་པྲཛྙཱ་པཱ་ར་མི་ཏཱ་བཛྲ་ཙྪེ་དི་ཀཱ་ཡཱཿསཔྟ་དཱརྠ་ཊཱི་ཀཱ།"
]
}
},
"ཚིག་གི་དོན་བཤད་པ།": {
"data": [],
"སངས་རྒྱས་ཀྱི་གདུང་རྒྱུན་མི་འཆད་པ་བསྟན་པ།": {
"data": [
"ཚིག་གི་དོན་བཤད་པ།\nསངས་རྒྱས་ཀྱི་གདུང་རྒྱུན་མི་འཆད་པ་བསྟན་པ།",
"མཚུངས་མེད་སངས་རྒྱས་ཆོས་རྣམས་སྐྱེད་མཛད་ལ། །\nགང་ཞིག་ཆོས་དབྱིངས་གསོ་བའི་མ་མ་སྟེ། །\nདབྱེ་དཀའི་རྡོ་རྗེ་གཞན་དོན་གྲུབ་གང་ཡིན། །\nགང་ཞིག་བཟུང་བས་འཕགས་ཀུན་སྐྱེད་པའམ་ཡིན། །"
]
}
}
}
}
}
]
}
}
Loading

0 comments on commit d0c5ea6

Please sign in to comment.