11import json
22import sys
3+ from datetime import datetime
34
45import requests
56from 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
811SERVER_URL_CONFIG_KEY = 'SERVER_URL'
912FILE_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
0 commit comments