-
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.
- Loading branch information
1 parent
74072da
commit f5bf94f
Showing
3 changed files
with
65 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
tsa/ | ||
.vscode/ | ||
corpus-txt/ | ||
corpus/ | ||
script_data/ | ||
.venv/ | ||
venv/ | ||
books_structure.json | ||
|
||
*.zip | ||
*.tar | ||
*.xz | ||
*.gz | ||
*.pyc |
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,57 @@ | ||
from psycopg2.errors import OperationalError | ||
from pathlib import Path | ||
import csv | ||
import logging | ||
|
||
logging.basicConfig(format='[%(levelname)s]:\t%(message)s', level=logging.INFO) | ||
logger = logging.getLogger(__name__) | ||
logger.setLevel(logging.INFO) | ||
|
||
from web.app.src.dbmanager import BibleDB | ||
|
||
csv_input = Path('./script_data/Шаблон.csv') | ||
new_lang_name = 'Armenian' | ||
translation_id = 1343 | ||
csv_output = Path(f'./script_data/{new_lang_name}_{translation_id}.csv') | ||
book_ids = { | ||
'Мф': 40, # Matthew | ||
'Мк': 41, # Mark | ||
'Лк': 42, # Luke | ||
'Ин': 43, # John | ||
'Деян': 44, # Acts | ||
'Откр': 66 # Revelation | ||
} | ||
|
||
def main(): | ||
try: | ||
db = BibleDB() | ||
except OperationalError as e: | ||
logger.error(e) | ||
logger.error("Cant connect to the database. Is postgres DB up?") | ||
logger.info("Make sure that the database is up") | ||
return | ||
|
||
def get_verse(book, chapter, verse): | ||
return db.get_verse( | ||
(book_ids[book], chapter, verse), | ||
translation_id | ||
) | ||
|
||
with open(csv_input, 'r', newline='') as f_in: | ||
reader = csv.reader(f_in) | ||
|
||
col_names = next(reader) | ||
new_col_id = col_names.index('Ярлык1') | ||
col_names.insert(new_col_id, new_lang_name) | ||
|
||
with open(csv_output, 'w', newline='') as f_out: | ||
writer = csv.writer(f_out) | ||
writer.writerow(col_names) | ||
|
||
for row in reader: | ||
new_row = [ x for x in row ] | ||
new_row.insert(new_col_id, get_verse(row[0], row[1], row[2])) | ||
writer.writerow(new_row) | ||
|
||
if __name__ == '__main__': | ||
main() |
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