GoogleCalc commited on
Commit
1ade8fe
Β·
verified Β·
1 Parent(s): 6b843a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -120
app.py CHANGED
@@ -554,50 +554,24 @@ def get_analytics_summary():
554
  # SHARE LINKS GENERATOR
555
  # ============================================================
556
 
557
- def get_share_links(birds, breed, weeks, days, total_days, bag_size, total_bags, rounded_bags,
558
- starter_bags, finisher_bags, total_cost, price_per_bag,
559
- currency_symbol, expected_weight, flock_weight, app_url="https://howmuchfeed.com"):
560
  """Generate share links for WhatsApp, Email, Facebook, Twitter."""
561
 
562
- # Build share message (NO EMOJIS for WhatsApp compatibility)
563
- message = f"""{app_url} - Results
564
-
565
- >> QUICK ANSWER:
566
- Exact feed needed: {total_bags:.1f} bags of {bag_size} kg feed
567
- Approximately {rounded_bags} bags needed
568
- to raise {birds:,} broilers to {weeks} weeks{f" + {days} days" if days > 0 else ""} ({total_days} days)
569
-
570
- >> FEED BREAKDOWN:
571
- Starter: {starter_bags:.1f} bags
572
- Finisher: {finisher_bags:.1f} bags
573
- TOTAL: {rounded_bags} bags
574
-
575
- >> FEED COST:
576
- {currency_symbol}{total_cost:,.0f}
577
- ({rounded_bags} bags x {currency_symbol}{price_per_bag:,.0f} per bag)
578
-
579
- >> EXPECTED PERFORMANCE:
580
- Body weight per bird: {expected_weight:.3f} kg
581
-
582
- Click and share to calculate your Poultry feed needs:
583
- {app_url}"""
584
 
585
- # URL encode
586
- encoded = urllib.parse.quote(message)
587
-
588
- # Share links
589
  links = {
590
  "whatsapp": f"https://wa.me/?text={encoded}",
591
- "email": f"mailto:?subject=How Much Feed? - Results&body={encoded}",
592
- "facebook": f"https://www.facebook.com/sharer/sharer.php?u={urllib.parse.quote(app_url)}&quote={urllib.parse.quote(message[:500])}",
593
- "twitter": f"https://twitter.com/intent/tweet?text={urllib.parse.quote(message[:280])}",
594
  }
595
 
596
  return links
597
 
598
 
599
  # ============================================================
600
- # FEED CALCULATION - WITH BOXED NUMBERS
601
  # ============================================================
602
 
603
  def calculate_feed(birds, weeks, days, bag_size, price_per_bag, email, country_code, breed, request: gr.Request):
@@ -669,14 +643,9 @@ def calculate_feed(birds, weeks, days, bag_size, price_per_bag, email, country_c
669
  breed_color = breed_info["color"]
670
 
671
  # Generate share links
672
- share_links = get_share_links(
673
- birds, breed, weeks, days, total_days, bag_size,
674
- total_bags, rounded_bags,
675
- starter_bags, finisher_bags, total_cost, price_per_bag,
676
- currency_symbol, expected_weight, flock_weight
677
- )
678
 
679
- # Output HTML with BOXED NUMBERS
680
  starter_bags_display = f"{starter_bags:.1f}"
681
  finisher_bags_display = f"{finisher_bags:.1f}"
682
 
@@ -685,116 +654,88 @@ def calculate_feed(birds, weeks, days, bag_size, price_per_bag, email, country_c
685
  age_text += f" + {days} day{'s' if days != 1 else ''}"
686
 
687
  html = f"""
688
- <div style="font-size: 17px; line-height: 1.8; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;">
689
 
690
- <div style="background: #f0fdf4; padding: 18px 22px; border-radius: 14px; border-left: 6px solid #22c55e; margin-bottom: 20px;">
691
- <div style="font-size: 13px; color: #16a34a; font-weight: 700; text-transform: uppercase; letter-spacing: 0.8px; margin-bottom: 8px;">Quick Answer</div>
692
-
693
- <!-- EXACT FEED - Boxed -->
694
  <div style="font-size: 20px; font-weight: 700; color: #166534;">
695
- Exact feed needed:
696
- <span style="display: inline-block; background: #166534; color: white; border-radius: 12px; padding: 4px 18px; font-size: 30px; font-weight: 900; box-shadow: 0 2px 8px rgba(22, 101, 52, 0.3);">
697
- {total_bags:.1f}
698
- </span>
699
- bags of {bag_size:g} kg feed
700
  </div>
701
-
702
- <!-- APPROXIMATE BAGS - Boxed -->
703
- <div style="font-size: 20px; font-weight: 700; color: #1e40af; margin-top: 6px;">
704
- Approximately:
705
- <span style="display: inline-block; background: #1e40af; color: white; border-radius: 12px; padding: 4px 18px; font-size: 26px; font-weight: 800; box-shadow: 0 2px 8px rgba(30, 64, 175, 0.3);">
706
- {rounded_bags}
707
- </span>
708
- bags to purchase (rounded up)
709
  </div>
710
-
711
- <!-- BIRD COUNT - Boxed -->
712
- <div style="color: #374151; font-size: 16px; margin-top: 8px;">
713
- To raise
714
- <span style="display: inline-block; background: #fef3c7; border: 2px solid #f59e0b; border-radius: 10px; padding: 2px 14px; font-size: 18px; font-weight: 700; color: #92400e;">
715
- {birds:,}
716
- </span>
717
- {breed} broilers to
718
- <span style="display: inline-block; background: #fce4ec; border: 2px solid #ef4444; border-radius: 10px; padding: 2px 14px; font-size: 18px; font-weight: 700; color: #991b1b;">
719
- {age_text} ({total_days} days)
720
- </span>
721
  </div>
722
-
723
- <div style="margin-top: 8px; font-size: 13px;">
724
- <span style="background: {breed_color}; color: white; padding: 3px 12px; border-radius: 14px; font-weight: 600;">{breed}</span>
725
- <span style="background: #6b7280; color: white; padding: 3px 12px; border-radius: 14px; font-weight: 600; margin-left: 8px;">{country_name}</span>
726
  </div>
727
  </div>
728
 
 
729
  <div style="margin-bottom: 16px;">
730
- <div style="font-size: 13px; color: #6b7280; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;">Feed Breakdown</div>
731
- <table style="width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 16px;">
732
  <tr style="border-bottom: 1px solid #e5e7eb;">
733
- <td style="padding: 10px 4px;"><strong>Starter</strong></td>
734
- <td style="padding: 10px 4px; text-align: right;">{starter_kg:,.1f} kg</td>
735
- <td style="padding: 10px 4px; text-align: right; font-weight: 700; font-size: 18px; color: #1e293b;">{starter_bags_display} bags</td>
736
  </tr>
737
  <tr style="border-bottom: 1px solid #e5e7eb;">
738
- <td style="padding: 10px 4px;"><strong>Finisher</strong></td>
739
- <td style="padding: 10px 4px; text-align: right;">{finisher_kg:,.1f} kg</td>
740
- <td style="padding: 10px 4px; text-align: right; font-weight: 700; font-size: 18px; color: #1e293b;">{finisher_bags_display} bags</td>
741
  </tr>
742
  <tr>
743
- <td style="padding: 10px 4px; font-weight: 700;">TOTAL</td>
744
- <td style="padding: 10px 4px; text-align: right; font-weight: 700;">{total_feed_kg:,.1f} kg</td>
745
- <td style="padding: 10px 4px; text-align: right; font-weight: 700; font-size: 18px; color: #166534;">{total_bags:.1f}</td>
746
  </tr>
747
  </table>
748
  </div>
749
 
750
- <div style="margin-bottom: 16px; background: #eff6ff; padding: 14px 18px; border-radius: 10px; border-left: 4px solid #3b82f6;">
751
- <div style="font-size: 13px; color: #6b7280; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;">Feed Cost</div>
752
- <div style="font-size: 32px; font-weight: 900; color: white;">
753
- <span style="display: inline-block; background: #1e40af; color: white; border-radius: 12px; padding: 6px 22px; box-shadow: 0 2px 10px rgba(30, 64, 175, 0.3);">
754
- {currency_symbol}{total_cost:,.0f}
755
- </span>
 
756
  </div>
757
- <div style="color: #6b7280; font-size: 14px; margin-top: 4px;">
758
- Approximately {rounded_bags} bags x {currency_symbol}{price_per_bag:,.0f} per bag
759
  </div>
760
  </div>
761
 
762
- <div style="border-top: 1px solid #e5e7eb; padding-top: 14px;">
763
- <div style="font-size: 13px; color: #6b7280; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;">Expected Performance</div>
764
- <table style="width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 16px;">
765
- <tr style="border-bottom: 1px solid #e5e7eb;">
766
- <td style="padding: 8px 4px;">Body weight per bird</td>
767
- <td style="padding: 8px 4px; text-align: right; font-weight: 700; font-size: 18px;">
768
- <span style="display: inline-block; background: #f1f5f9; border: 1px solid #cbd5e1; border-radius: 8px; padding: 2px 14px;">
769
- {expected_weight:.3f} kg
770
- </span>
771
- </td>
772
- </tr>
773
- <tr>
774
- <td style="padding: 8px 4px;">Flock live weight</td>
775
- <td style="padding: 8px 4px; text-align: right; font-weight: 700; font-size: 18px;">
776
- <span style="display: inline-block; background: #f1f5f9; border: 1px solid #cbd5e1; border-radius: 8px; padding: 2px 14px;">
777
- {flock_weight:,.1f} kg
778
- </span>
779
- </td>
780
- </tr>
781
- </table>
782
  </div>
783
 
784
- <div style="margin-top: 16px; border-top: 1px solid #e5e7eb; padding-top: 14px;">
785
- <div style="font-size: 13px; color: #6b7280; font-weight: 600; margin-bottom: 8px;">Share Results:</div>
 
786
  <div style="display: flex; gap: 10px; flex-wrap: wrap;">
787
  <a href="{share_links['whatsapp']}" target="_blank" style="text-decoration: none;">
788
- <button style="background: #25D366; color: white; padding: 8px 16px; border: none; border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 600;">WhatsApp</button>
789
  </a>
790
  <a href="{share_links['email']}" target="_blank" style="text-decoration: none;">
791
- <button style="background: #ea4335; color: white; padding: 8px 16px; border: none; border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 600;">Email</button>
792
  </a>
793
  <a href="{share_links['facebook']}" target="_blank" style="text-decoration: none;">
794
- <button style="background: #1877f2; color: white; padding: 8px 16px; border: none; border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 600;">Facebook</button>
795
  </a>
796
  <a href="{share_links['twitter']}" target="_blank" style="text-decoration: none;">
797
- <button style="background: #000000; color: white; padding: 8px 16px; border: none; border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 600;">Twitter/X</button>
798
  </a>
799
  </div>
800
  </div>
@@ -1033,10 +974,9 @@ body { background: #f6f8f4; }
1033
  .answer-box {
1034
  background: white;
1035
  border-radius: 16px;
1036
- padding: 16px 20px;
1037
  border: 1px solid #e5e7eb;
1038
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
1039
- min-height: 400px;
1040
  }
1041
 
1042
  .email-box {
 
554
  # SHARE LINKS GENERATOR
555
  # ============================================================
556
 
557
+ def get_share_links(app_url="https://howmuchfeed.com"):
 
 
558
  """Generate share links for WhatsApp, Email, Facebook, Twitter."""
559
 
560
+ share_text = f"πŸ” Calculate your poultry feed needs at {app_url}"
561
+ encoded = urllib.parse.quote(share_text)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
562
 
 
 
 
 
563
  links = {
564
  "whatsapp": f"https://wa.me/?text={encoded}",
565
+ "email": f"mailto:?subject=How Much Feed? - Poultry Feed Calculator&body={encoded}",
566
+ "facebook": f"https://www.facebook.com/sharer/sharer.php?u={urllib.parse.quote(app_url)}",
567
+ "twitter": f"https://twitter.com/intent/tweet?text={encoded}",
568
  }
569
 
570
  return links
571
 
572
 
573
  # ============================================================
574
+ # FEED CALCULATION - CLEAN INTERFACE
575
  # ============================================================
576
 
577
  def calculate_feed(birds, weeks, days, bag_size, price_per_bag, email, country_code, breed, request: gr.Request):
 
643
  breed_color = breed_info["color"]
644
 
645
  # Generate share links
646
+ share_links = get_share_links()
 
 
 
 
 
647
 
648
+ # Output HTML - CLEAN INTERFACE
649
  starter_bags_display = f"{starter_bags:.1f}"
650
  finisher_bags_display = f"{finisher_bags:.1f}"
651
 
 
654
  age_text += f" + {days} day{'s' if days != 1 else ''}"
655
 
656
  html = f"""
657
+ <div style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; font-size: 16px; line-height: 1.6; color: #1a1a1a;">
658
 
659
+ <!-- Quick Answer -->
660
+ <div style="background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 12px; padding: 20px 24px; margin-bottom: 20px;">
661
+ <div style="font-size: 13px; font-weight: 700; color: #16a34a; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px;">Here Is Your Result</div>
 
662
  <div style="font-size: 20px; font-weight: 700; color: #166534;">
663
+ You need <span style="background: #166534; color: white; border-radius: 8px; padding: 2px 14px; font-size: 24px;">{total_bags:.1f}</span> bags of {bag_size} kg poultry feed<br>
664
+ to raise <strong>{birds:,}</strong> {breed} broilers from day-old to <strong>{age_text} ({total_days} days)</strong>
 
 
 
665
  </div>
666
+ <div style="margin-top: 8px; font-size: 18px; font-weight: 700; color: #1e40af;">
667
+ Buy <span style="background: #1e40af; color: white; border-radius: 8px; padding: 2px 14px; font-size: 22px;">{rounded_bags}</span> bags to make sure you have enough feed.
 
 
 
 
 
 
668
  </div>
669
+ <div style="margin-top: 8px; display: flex; gap: 16px; flex-wrap: wrap; font-size: 14px; color: #4b5563;">
670
+ <span>πŸ” Birds: <strong>{birds:,} broilers</strong></span>
671
+ <span>πŸ“… Age: <strong>{age_text} ({total_days} days)</strong></span>
672
+ <span>🏷️ Breed: <strong>{breed}</strong></span>
 
 
 
 
 
 
 
673
  </div>
674
+ <div style="margin-top: 8px; display: flex; gap: 8px; font-size: 13px;">
675
+ <span style="background: {breed_color}; color: white; padding: 2px 12px; border-radius: 12px; font-weight: 600;">{breed}</span>
676
+ <span style="background: #6b7280; color: white; padding: 2px 12px; border-radius: 12px; font-weight: 600;">{country_name}</span>
 
677
  </div>
678
  </div>
679
 
680
+ <!-- Feed Breakdown -->
681
  <div style="margin-bottom: 16px;">
682
+ <div style="font-size: 14px; font-weight: 700; color: #6b7280; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px;">Feed Breakdown</div>
683
+ <table style="width: 100%; border-collapse: collapse; font-size: 15px;">
684
  <tr style="border-bottom: 1px solid #e5e7eb;">
685
+ <td style="padding: 8px 4px;"><strong>Starter (0 – 4 weeks)</strong></td>
686
+ <td style="padding: 8px 4px; text-align: right;">{starter_kg:,.1f} kg</td>
687
+ <td style="padding: 8px 4px; text-align: right; font-weight: 700; color: #1e293b;">{starter_bags_display} bags</td>
688
  </tr>
689
  <tr style="border-bottom: 1px solid #e5e7eb;">
690
+ <td style="padding: 8px 4px;"><strong>Finisher (4 – 8 weeks)</strong></td>
691
+ <td style="padding: 8px 4px; text-align: right;">{finisher_kg:,.1f} kg</td>
692
+ <td style="padding: 8px 4px; text-align: right; font-weight: 700; color: #1e293b;">{finisher_bags_display} bags</td>
693
  </tr>
694
  <tr>
695
+ <td style="padding: 8px 4px; font-weight: 700;">TOTAL</td>
696
+ <td style="padding: 8px 4px; text-align: right; font-weight: 700;">{total_feed_kg:,.1f} kg</td>
697
+ <td style="padding: 8px 4px; text-align: right; font-weight: 700; font-size: 18px; color: #166534;">{total_bags:.1f} bags</td>
698
  </tr>
699
  </table>
700
  </div>
701
 
702
+ <!-- Feed Cost -->
703
+ <div style="background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 12px; padding: 16px 20px; margin-bottom: 16px;">
704
+ <div style="font-size: 14px; font-weight: 700; color: #6b7280; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px;">Feed Cost Estimate</div>
705
+ <div style="display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;">
706
+ <span style="font-size: 16px; color: #4b5563;">Approximately</span>
707
+ <span style="background: #1e40af; color: white; border-radius: 8px; padding: 2px 16px; font-size: 20px; font-weight: 700;">{rounded_bags} bags</span>
708
+ <span style="font-size: 16px; color: #4b5563;">Γ— {currency_symbol}{price_per_bag:,.0f} per bag</span>
709
  </div>
710
+ <div style="font-size: 28px; font-weight: 800; color: #1e40af; margin-top: 4px;">
711
+ {currency_symbol}{total_cost:,.0f}
712
  </div>
713
  </div>
714
 
715
+ <!-- Expected Performance -->
716
+ <div style="border-top: 1px solid #e5e7eb; padding-top: 14px; margin-bottom: 16px;">
717
+ <div style="font-size: 14px; font-weight: 700; color: #6b7280; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px;">Expected Performance</div>
718
+ <div style="display: flex; gap: 24px; flex-wrap: wrap; font-size: 15px;">
719
+ <div>Body weight per bird: <span style="font-weight: 700; font-size: 17px;">{expected_weight:.3f} kg</span></div>
720
+ <div>Flock live weight: <span style="font-weight: 700; font-size: 17px;">{flock_weight:,.1f} kg</span></div>
721
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
722
  </div>
723
 
724
+ <!-- Share Results -->
725
+ <div style="border-top: 1px solid #e5e7eb; padding-top: 14px;">
726
+ <div style="font-size: 14px; font-weight: 700; color: #6b7280; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px;">Share Results</div>
727
  <div style="display: flex; gap: 10px; flex-wrap: wrap;">
728
  <a href="{share_links['whatsapp']}" target="_blank" style="text-decoration: none;">
729
+ <button style="background: #25D366; color: white; padding: 8px 18px; border: none; border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 600;">WhatsApp</button>
730
  </a>
731
  <a href="{share_links['email']}" target="_blank" style="text-decoration: none;">
732
+ <button style="background: #ea4335; color: white; padding: 8px 18px; border: none; border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 600;">Email</button>
733
  </a>
734
  <a href="{share_links['facebook']}" target="_blank" style="text-decoration: none;">
735
+ <button style="background: #1877f2; color: white; padding: 8px 18px; border: none; border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 600;">Facebook</button>
736
  </a>
737
  <a href="{share_links['twitter']}" target="_blank" style="text-decoration: none;">
738
+ <button style="background: #000000; color: white; padding: 8px 18px; border: none; border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 600;">Twitter/X</button>
739
  </a>
740
  </div>
741
  </div>
 
974
  .answer-box {
975
  background: white;
976
  border-radius: 16px;
977
+ padding: 20px 24px;
978
  border: 1px solid #e5e7eb;
979
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
 
980
  }
981
 
982
  .email-box {