danicor commited on
Commit
a205bb7
·
verified ·
1 Parent(s): 87bcea8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -13
app.py CHANGED
@@ -30,6 +30,8 @@ os.environ["TRANSFORMERS_CACHE"] = "/tmp/huggingface"
30
  cache_dir = "/tmp/huggingface"
31
  os.makedirs(cache_dir, mode=0o777, exist_ok=True)
32
 
 
 
33
 
34
  # نگاشت زبان‌ها
35
  LANGUAGE_MAP = {
@@ -523,16 +525,20 @@ def notify_wordpress_completion_and_charge(request_id: str, character_count: int
523
  target_lang: str):
524
  """Enhanced WordPress notification with multiple URL attempts"""
525
  try:
526
- # Get WordPress URL from settings or environment
527
  wordpress_base_url = os.getenv("WORDPRESS_NOTIFICATION_URL")
 
 
528
  if not wordpress_base_url:
529
- wordpress_base_url = "http://localhost" # Default fallback
530
-
531
- wordpress_urls = [
532
- f"{wordpress_base_url}/wp-json/mlt/v1/notification",
533
- "http://localhost/wp-json/mlt/v1/notification",
534
- "http://127.0.0.1/wp-json/mlt/v1/notification"
535
- ]
 
 
536
 
537
  payload = {
538
  'request_id': request_id,
@@ -544,12 +550,18 @@ def notify_wordpress_completion_and_charge(request_id: str, character_count: int
544
  'status': 'completed'
545
  }
546
 
547
- for wordpress_url in wordpress_urls:
548
- if not wordpress_url:
549
  continue
550
 
 
 
 
 
 
 
551
  try:
552
- response = requests.post(wordpress_url, json=payload, timeout=10)
553
 
554
  if response.status_code == 200:
555
  # Mark as auto charged
@@ -558,10 +570,10 @@ def notify_wordpress_completion_and_charge(request_id: str, character_count: int
558
  print(f"WordPress notification successful for request {request_id}")
559
  return True
560
  else:
561
- print(f"WordPress notification failed: {response.status_code} - {wordpress_url}")
562
 
563
  except requests.exceptions.RequestException as e:
564
- print(f"WordPress notification error for {wordpress_url}: {str(e)}")
565
  continue
566
 
567
  print(f"All WordPress notification attempts failed for request {request_id}")
 
30
  cache_dir = "/tmp/huggingface"
31
  os.makedirs(cache_dir, mode=0o777, exist_ok=True)
32
 
33
+ # Set WordPress notification URL from environment or default
34
+ WORDPRESS_BASE_URL = os.getenv("WORDPRESS_NOTIFICATION_URL", "http://localhost")
35
 
36
  # نگاشت زبان‌ها
37
  LANGUAGE_MAP = {
 
525
  target_lang: str):
526
  """Enhanced WordPress notification with multiple URL attempts"""
527
  try:
528
+ # Get WordPress URL from environment or settings
529
  wordpress_base_url = os.getenv("WORDPRESS_NOTIFICATION_URL")
530
+
531
+ # If no environment variable, try to get from settings or use default
532
  if not wordpress_base_url:
533
+ # Try common WordPress URLs - replace with your actual WordPress URL
534
+ wordpress_urls = [
535
+ "https://your-wordpress-site.com", # Replace with your actual WordPress URL
536
+ "http://your-wordpress-site.com", # Replace with your actual WordPress URL
537
+ "http://localhost:8080", # If using different port
538
+ "http://localhost" # Last resort
539
+ ]
540
+ else:
541
+ wordpress_urls = [wordpress_base_url]
542
 
543
  payload = {
544
  'request_id': request_id,
 
550
  'status': 'completed'
551
  }
552
 
553
+ for base_url in wordpress_urls:
554
+ if not base_url:
555
  continue
556
 
557
+ # Ensure URL ends with notification endpoint
558
+ if not base_url.endswith('/wp-json/mlt/v1/notification'):
559
+ notification_url = base_url.rstrip('/') + '/wp-json/mlt/v1/notification'
560
+ else:
561
+ notification_url = base_url
562
+
563
  try:
564
+ response = requests.post(notification_url, json=payload, timeout=10)
565
 
566
  if response.status_code == 200:
567
  # Mark as auto charged
 
570
  print(f"WordPress notification successful for request {request_id}")
571
  return True
572
  else:
573
+ print(f"WordPress notification failed: {response.status_code} - {notification_url}")
574
 
575
  except requests.exceptions.RequestException as e:
576
+ print(f"WordPress notification error for {notification_url}: {str(e)}")
577
  continue
578
 
579
  print(f"All WordPress notification attempts failed for request {request_id}")