neuralworm commited on
Commit
950536d
·
1 Parent(s): 38a1a88

sort results by book

Browse files
Files changed (1) hide show
  1. app.py +21 -15
app.py CHANGED
@@ -179,36 +179,42 @@ def gematria_search_interface(phrase):
179
  if not matching_phrases:
180
  return "No matching phrases found."
181
 
182
- # Format results for display
 
 
 
 
 
 
 
 
183
  results = []
184
- if not matching_phrases:
185
- return "No matching phrases found."
186
- else:
187
- results.append("<div class='results-container'>")
188
- for words, book, chapter, verse in matching_phrases:
189
  translation = get_translation(words)
190
- book_name_english = book_names.get(book, 'Unknown') # Get book name
191
  link = f"https://www.biblegateway.com/passage/?search={quote_plus(book_name_english)}+{chapter}%3A{verse}"
192
-
193
  results.append(f"""
194
  <div class='result-item'>
195
- <h3>Book: {book_name_english}</h3>
196
  <p>Chapter: {chapter}, Verse: {verse}</p>
197
  <p class='hebrew-phrase'>Hebrew Phrase: {words}</p>
198
  <p>Translation: {translation}</p>
199
  <a href='{link}' target='_blank' class='bible-link'>[See on Bible Gateway]</a>
200
  </div>
201
  """)
202
- results.append("</div>") # Close results-container div
203
 
204
  conn.close()
205
 
206
- # Add CSS styling (within a <style> tag)
207
  style = """
208
  <style>
209
  .results-container {
210
  display: grid;
211
- grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); /* Responsive columns */
212
  gap: 20px;
213
  }
214
 
@@ -220,14 +226,14 @@ def gematria_search_interface(phrase):
220
  }
221
 
222
  .hebrew-phrase {
223
- font-family: 'SBL Hebrew', 'Ezra SIL', serif; /* Use Hebrew fonts */
224
- direction: rtl; /* Right-to-left text direction */
225
  }
226
 
227
  .bible-link {
228
  display: block;
229
  margin-top: 10px;
230
- color: #007bff; /* Blue link color */
231
  text-decoration: none;
232
  }
233
  </style>
 
179
  if not matching_phrases:
180
  return "No matching phrases found."
181
 
182
+ # Sort results by book, chapter, and verse
183
+ sorted_phrases = sorted(matching_phrases, key=lambda x: (x[1], x[2], x[3]))
184
+
185
+ # Group results by book
186
+ results_by_book = defaultdict(list)
187
+ for words, book, chapter, verse in sorted_phrases:
188
+ results_by_book[book].append((words, chapter, verse))
189
+
190
+ # Format results for display with enhanced structure
191
  results = []
192
+ results.append("<div class='results-container'>")
193
+ for book, phrases in results_by_book.items():
194
+ results.append(f"<h4>Book: {book_names.get(book, 'Unknown')}</h4>")
195
+ for words, chapter, verse in phrases:
 
196
  translation = get_translation(words)
197
+ book_name_english = book_names.get(book, 'Unknown')
198
  link = f"https://www.biblegateway.com/passage/?search={quote_plus(book_name_english)}+{chapter}%3A{verse}"
199
+
200
  results.append(f"""
201
  <div class='result-item'>
 
202
  <p>Chapter: {chapter}, Verse: {verse}</p>
203
  <p class='hebrew-phrase'>Hebrew Phrase: {words}</p>
204
  <p>Translation: {translation}</p>
205
  <a href='{link}' target='_blank' class='bible-link'>[See on Bible Gateway]</a>
206
  </div>
207
  """)
208
+ results.append("</div>") # Close results-container div
209
 
210
  conn.close()
211
 
212
+ # Add CSS styling
213
  style = """
214
  <style>
215
  .results-container {
216
  display: grid;
217
+ grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
218
  gap: 20px;
219
  }
220
 
 
226
  }
227
 
228
  .hebrew-phrase {
229
+ font-family: 'SBL Hebrew', 'Ezra SIL', serif;
230
+ direction: rtl;
231
  }
232
 
233
  .bible-link {
234
  display: block;
235
  margin-top: 10px;
236
+ color: #007bff;
237
  text-decoration: none;
238
  }
239
  </style>