openfree commited on
Commit
6f36768
Β·
verified Β·
1 Parent(s): 965f9f4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -42
app.py CHANGED
@@ -793,10 +793,11 @@ Provide specific, practical improvements."""
793
  sentences = actual_content.split('.')
794
  hook = sentences[-2] + '.' if len(sentences) > 1 else sentences[-1]
795
 
796
- # Save episode with title
 
797
  WebNovelDatabase.save_episode(
798
  self.current_session_id, episode_num,
799
- actual_content, hook
800
  )
801
 
802
  # Add to accumulated content with title
@@ -836,24 +837,14 @@ def export_to_txt(episodes: List[Dict], genre: str, title: str = "") -> str:
836
  ep_num = ep.get('episode_number', 0)
837
  ep_content = ep.get('content', '')
838
 
839
- # Extract title if exists in content
840
- lines = ep_content.strip().split('\n')
841
- if lines and (f"{ep_num}ν™”." in lines[0] or f"Episode {ep_num}." in lines[0]):
842
- content += f"\n{lines[0]}\n"
843
- content += f"{'-' * 40}\n\n"
844
- actual_content = '\n'.join(lines[2:] if len(lines) > 2 and lines[1].strip() == "" else lines[1:])
845
- content += actual_content
846
- else:
847
- content += f"\n{ep_num}ν™”\n"
848
- content += f"{'-' * 40}\n\n"
849
- content += ep_content
850
-
851
- content += f"\n\n{'=' * 50}\n"
852
 
853
  return content
854
 
855
  def export_to_docx(episodes: List[Dict], genre: str, title: str = "") -> bytes:
856
- """Export web novel to DOCX format"""
857
  if not DOCX_AVAILABLE:
858
  raise Exception("python-docx is not installed")
859
 
@@ -868,29 +859,37 @@ def export_to_docx(episodes: List[Dict], genre: str, title: str = "") -> bytes:
868
  doc.add_page_break()
869
 
870
  # Episodes
871
- for ep in episodes:
872
  ep_num = ep.get('episode_number', 0)
873
  ep_content = ep.get('content', '')
874
 
875
- # Extract title if exists
876
  lines = ep_content.strip().split('\n')
877
- if lines and (f"{ep_num}ν™”." in lines[0] or f"Episode {ep_num}." in lines[0]):
878
- doc.add_heading(lines[0], 1)
879
- actual_content = '\n'.join(lines[2:] if len(lines) > 2 and lines[1].strip() == "" else lines[1:])
880
- else:
881
- doc.add_heading(f"{ep_num}ν™”", 1)
882
- actual_content = ep_content
883
 
884
- # Add content paragraphs
885
- for paragraph in actual_content.split('\n'):
886
- if paragraph.strip():
887
- doc.add_paragraph(paragraph.strip())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
888
 
889
- if ep_num < len(episodes):
 
890
  doc.add_page_break()
891
 
892
  # Save to bytes
893
- import io
894
  bytes_io = io.BytesIO()
895
  doc.save(bytes_io)
896
  bytes_io.seek(0)
@@ -1428,24 +1427,20 @@ def format_webnovel_display(episodes: List[Dict], genre: str) -> str:
1428
  formatted += "---\n\n"
1429
 
1430
  # Episodes
1431
- for ep in episodes:
1432
  ep_num = ep.get('episode_number', 0)
1433
  content = ep.get('content', '')
1434
 
1435
- # Check if content already has episode title
1436
- lines = content.strip().split('\n')
1437
- if lines and (f"{ep_num}ν™”." in lines[0] or f"Episode {ep_num}." in lines[0]):
1438
- # Use the existing title
1439
- formatted += f"## {lines[0]}\n\n"
1440
- # Use the rest as content
1441
  actual_content = '\n'.join(lines[2:] if len(lines) > 2 and lines[1].strip() == "" else lines[1:])
1442
  formatted += f"{actual_content}\n\n"
1443
- else:
1444
- # No title found, use default
1445
- formatted += f"## 제{ep_num}ν™”\n\n"
1446
- formatted += f"{content}\n\n"
1447
 
1448
- if ep_num < len(episodes): # Not last episode
1449
  formatted += "➑️ *λ‹€μŒ 화에 계속...*\n\n"
1450
 
1451
  formatted += "---\n\n"
 
793
  sentences = actual_content.split('.')
794
  hook = sentences[-2] + '.' if len(sentences) > 1 else sentences[-1]
795
 
796
+ # Save episode with full content including title
797
+ full_episode_content = f"{episode_title}\n\n{actual_content}"
798
  WebNovelDatabase.save_episode(
799
  self.current_session_id, episode_num,
800
+ full_episode_content, hook
801
  )
802
 
803
  # Add to accumulated content with title
 
837
  ep_num = ep.get('episode_number', 0)
838
  ep_content = ep.get('content', '')
839
 
840
+ # Content already includes title, so just add it
841
+ content += f"\n{ep_content}\n"
842
+ content += f"\n{'=' * 50}\n"
 
 
 
 
 
 
 
 
 
 
843
 
844
  return content
845
 
846
  def export_to_docx(episodes: List[Dict], genre: str, title: str = "") -> bytes:
847
+ """Export web novel to DOCX format - matches screen display exactly"""
848
  if not DOCX_AVAILABLE:
849
  raise Exception("python-docx is not installed")
850
 
 
859
  doc.add_page_break()
860
 
861
  # Episodes
862
+ for idx, ep in enumerate(episodes):
863
  ep_num = ep.get('episode_number', 0)
864
  ep_content = ep.get('content', '')
865
 
866
+ # Split content into lines
867
  lines = ep_content.strip().split('\n')
 
 
 
 
 
 
868
 
869
+ # First line should be the title (e.g., "1ν™”. 제λͺ©")
870
+ if lines:
871
+ # Add episode title as heading
872
+ doc.add_heading(lines[0], 1)
873
+
874
+ # Add the rest of the content
875
+ content_lines = lines[1:] if len(lines) > 1 else []
876
+
877
+ # Skip empty lines at the beginning
878
+ while content_lines and not content_lines[0].strip():
879
+ content_lines.pop(0)
880
+
881
+ # Add content paragraphs
882
+ for line in content_lines:
883
+ if line.strip(): # Only add non-empty lines
884
+ doc.add_paragraph(line.strip())
885
+ elif len(doc.paragraphs) > 0: # Add spacing between paragraphs
886
+ doc.add_paragraph()
887
 
888
+ # Add page break except for the last episode
889
+ if idx < len(episodes) - 1:
890
  doc.add_page_break()
891
 
892
  # Save to bytes
 
893
  bytes_io = io.BytesIO()
894
  doc.save(bytes_io)
895
  bytes_io.seek(0)
 
1427
  formatted += "---\n\n"
1428
 
1429
  # Episodes
1430
+ for idx, ep in enumerate(episodes):
1431
  ep_num = ep.get('episode_number', 0)
1432
  content = ep.get('content', '')
1433
 
1434
+ # Content already includes the title, so display as is
1435
+ formatted += f"## {content.split(chr(10))[0] if content else f'{ep_num}ν™”'}\n\n"
1436
+
1437
+ # Get the actual content (skip title and empty line)
1438
+ lines = content.split('\n')
1439
+ if len(lines) > 1:
1440
  actual_content = '\n'.join(lines[2:] if len(lines) > 2 and lines[1].strip() == "" else lines[1:])
1441
  formatted += f"{actual_content}\n\n"
 
 
 
 
1442
 
1443
+ if idx < len(episodes) - 1: # Not last episode
1444
  formatted += "➑️ *λ‹€μŒ 화에 계속...*\n\n"
1445
 
1446
  formatted += "---\n\n"