rairo commited on
Commit
b7e4bf5
Β·
verified Β·
1 Parent(s): 2ca2fa8

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +5 -17
main.py CHANGED
@@ -645,7 +645,6 @@ def download_story_archive(story_id):
645
  logging.warning(f"❌ Unauthorized access attempt for story {story_id}")
646
  return jsonify({'error': 'Unauthorized'}), 403
647
 
648
- # Extract story details
649
  full_text = story_record.get("full_story", "")
650
  sections = story_record.get("sections", [])
651
  split_sentences = full_text.split('.', 1)
@@ -656,23 +655,20 @@ def download_story_archive(story_id):
656
  zip_buffer = io.BytesIO()
657
  with zipfile.ZipFile(zip_buffer, "w", zipfile.ZIP_DEFLATED) as zipf:
658
 
659
- # ======================
660
- # 1) Generate PDF
661
- # ======================
662
  logging.info(f"πŸ“„ Generating PDF for {story_id}")
663
  pdf = FPDF()
664
  pdf.set_auto_page_break(auto=True, margin=15)
665
  pdf.add_page()
666
  pdf.set_font("Arial", size=12)
667
 
668
- # Add story details
669
  pdf.multi_cell(0, 10, f"Story ID: {story_id}")
670
  pdf.multi_cell(0, 10, f"Title: {title}")
671
  pdf.ln(10)
672
  pdf.multi_cell(0, 10, "Full Story:")
673
  pdf.multi_cell(0, 10, full_text)
674
 
675
- # Add sections with images
676
  bucket = storage.bucket()
677
  for idx, section_obj in enumerate(sections):
678
  section_text = section_obj.get("section_text", "")
@@ -710,9 +706,7 @@ def download_story_archive(story_id):
710
  zipf.writestr(f"{story_id}.pdf", pdf_buffer.read())
711
  logging.info(f"βœ… PDF added to ZIP for {story_id}")
712
 
713
- # ======================
714
- # 2) Generate a TXT file
715
- # ======================
716
  logging.info(f"πŸ“„ Generating TXT for {story_id}")
717
  txt_content = f"Story ID: {story_id}\nTitle: {title}\n\nFull Story:\n\n{full_text}\n\n"
718
  for idx, section_obj in enumerate(sections):
@@ -721,9 +715,7 @@ def download_story_archive(story_id):
721
  zipf.writestr(f"{story_id}.txt", txt_content)
722
  logging.info(f"βœ… TXT added to ZIP for {story_id}")
723
 
724
- # ======================
725
- # 3) Download section images
726
- # ======================
727
  for idx, section_obj in enumerate(sections):
728
  image_url = section_obj.get("image_url", "")
729
  if image_url:
@@ -739,9 +731,7 @@ def download_story_archive(story_id):
739
  except Exception as img_error:
740
  logging.error(f"❌ Error downloading image for section {idx + 1}: {str(img_error)}")
741
 
742
- # ======================
743
- # 4) Download section audios
744
- # ======================
745
  for idx, section_obj in enumerate(sections):
746
  audio_url = section_obj.get("audio_url", "")
747
  if audio_url:
@@ -757,9 +747,7 @@ def download_story_archive(story_id):
757
  except Exception as audio_error:
758
  logging.error(f"❌ Error downloading audio for section {idx + 1}: {str(audio_error)}")
759
 
760
- # ------------------------
761
  # Upload log to Firebase
762
- # ------------------------
763
  log_url = upload_log()
764
  if log_url:
765
  logging.info(f"πŸ“€ Log uploaded: {log_url}")
 
645
  logging.warning(f"❌ Unauthorized access attempt for story {story_id}")
646
  return jsonify({'error': 'Unauthorized'}), 403
647
 
 
648
  full_text = story_record.get("full_story", "")
649
  sections = story_record.get("sections", [])
650
  split_sentences = full_text.split('.', 1)
 
655
  zip_buffer = io.BytesIO()
656
  with zipfile.ZipFile(zip_buffer, "w", zipfile.ZIP_DEFLATED) as zipf:
657
 
658
+ # Generate PDF
 
 
659
  logging.info(f"πŸ“„ Generating PDF for {story_id}")
660
  pdf = FPDF()
661
  pdf.set_auto_page_break(auto=True, margin=15)
662
  pdf.add_page()
663
  pdf.set_font("Arial", size=12)
664
 
 
665
  pdf.multi_cell(0, 10, f"Story ID: {story_id}")
666
  pdf.multi_cell(0, 10, f"Title: {title}")
667
  pdf.ln(10)
668
  pdf.multi_cell(0, 10, "Full Story:")
669
  pdf.multi_cell(0, 10, full_text)
670
 
671
+ # Add sections
672
  bucket = storage.bucket()
673
  for idx, section_obj in enumerate(sections):
674
  section_text = section_obj.get("section_text", "")
 
706
  zipf.writestr(f"{story_id}.pdf", pdf_buffer.read())
707
  logging.info(f"βœ… PDF added to ZIP for {story_id}")
708
 
709
+ # Generate TXT
 
 
710
  logging.info(f"πŸ“„ Generating TXT for {story_id}")
711
  txt_content = f"Story ID: {story_id}\nTitle: {title}\n\nFull Story:\n\n{full_text}\n\n"
712
  for idx, section_obj in enumerate(sections):
 
715
  zipf.writestr(f"{story_id}.txt", txt_content)
716
  logging.info(f"βœ… TXT added to ZIP for {story_id}")
717
 
718
+ # Download section images
 
 
719
  for idx, section_obj in enumerate(sections):
720
  image_url = section_obj.get("image_url", "")
721
  if image_url:
 
731
  except Exception as img_error:
732
  logging.error(f"❌ Error downloading image for section {idx + 1}: {str(img_error)}")
733
 
734
+ # Download section audios
 
 
735
  for idx, section_obj in enumerate(sections):
736
  audio_url = section_obj.get("audio_url", "")
737
  if audio_url:
 
747
  except Exception as audio_error:
748
  logging.error(f"❌ Error downloading audio for section {idx + 1}: {str(audio_error)}")
749
 
 
750
  # Upload log to Firebase
 
751
  log_url = upload_log()
752
  if log_url:
753
  logging.info(f"πŸ“€ Log uploaded: {log_url}")