Skip to content

Commit 130c01f

Browse files
Added automatic title detection
1 parent 37faaec commit 130c01f

3 files changed

Lines changed: 32 additions & 3 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.env
2+
config.json
23
venv/
34
.idea/
45
dist/

client.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import json
22
import sys
3+
from datetime import datetime
34

45
import requests
56
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout, QLabel, QLineEdit, \
67
QPushButton, QFileDialog, QMessageBox
8+
from convertdate import hebrew
9+
from titlecase import titlecase
710

811
SERVER_URL_CONFIG_KEY = 'SERVER_URL'
912
FILE_FILTER = "Divrei Torah (*.pdf)"
@@ -22,6 +25,29 @@ def __init__(self, file_path, main_window):
2225

2326
self.title_entry = QLineEdit()
2427

28+
# filename either "Kaarah_forty_four.pdf" or "Pinchas_dvar_Torah_2023.pdf"
29+
# title either "Volume Forty-Four" or "Pinchas 5783"
30+
filename = self.file_label.text()
31+
if filename.startswith("Kaarah"):
32+
volume = filename.replace('_-_', '').removeprefix('Kaarah_').removeprefix('Kaarah').removesuffix(
33+
'.pdf').replace('_', '-')
34+
title = f"Volume {volume}"
35+
else:
36+
now = datetime.now()
37+
year = now.year
38+
month = now.month
39+
day = now.day
40+
41+
filename = filename.replace("_-_", "").removesuffix(".pdf").replace("_dvar_Torah_", "").replace(
42+
"_dvar_Torah", "").replace("-", "").replace("_", " - ")
43+
44+
if str(year) in filename:
45+
title = filename.replace(str(year), "") + " " + str(hebrew.from_gregorian(year, month, day)[0])
46+
else:
47+
title = filename[:-4]
48+
49+
self.title_entry.setText(titlecase(title))
50+
2551
self.remove_button = QPushButton("Remove")
2652
self.remove_button.clicked.connect(self.remove_self)
2753

@@ -147,7 +173,7 @@ def get_data_payload(self):
147173
if not title:
148174
QMessageBox.warning(self, "Warning", "Please enter a title for all files")
149175
return {}
150-
data[f'title_{i + 1}'] = title
176+
data[f'title_{i + 1}'] = titlecase(title)
151177
return data
152178

153179

requirements.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@ beautifulsoup4
33
requests
44
Werkzeug
55
PyQt5
6-
GitPython
7-
python-dotenv
6+
GitPython==3.1.32
7+
python-dotenv
8+
titlecase
9+
convertdate

0 commit comments

Comments
 (0)