codeboosterstech commited on
Commit
828ca8c
·
verified ·
1 Parent(s): 229ce91

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -18
app.py CHANGED
@@ -39,27 +39,22 @@ def send_news(whatsapp_number: str, city: str):
39
  return f"No news found for {city}."
40
 
41
  # Prepare messages under character limit
42
- messages = []
43
- timestamp = datetime.now().strftime("%Y-%m-%d %H:%M")
44
- current_msg = f"📰 *Top News in {city}* (Fetched: {timestamp})
45
 
46
- "
 
 
 
47
 
48
- for i, article in enumerate(news_data, start=1):
49
- title = article.get("title", "No title")
50
- vk_code = f"VK{i}" # custom short code
51
- line = f"{i}. *{title}* ⚡
52
- {vk_code}
53
-
54
- "
55
-
56
- if len(current_msg) + len(line) > MAX_CHARS:
57
- messages.append(current_msg.strip())
58
- current_msg = line
59
- else:
60
- current_msg += line
61
- if current_msg:
62
  messages.append(current_msg.strip())
 
 
 
 
 
63
 
64
  # Prepare WhatsApp number
65
  TO = whatsapp_number.strip()
 
39
  return f"No news found for {city}."
40
 
41
  # Prepare messages under character limit
42
+ messages = []
43
+ timestamp = datetime.now().strftime("%Y-%m-%d %H:%M")
44
+ current_msg = f"📰 *Top News in {city}* (Fetched: {timestamp})\n\n"
45
 
46
+ for i, article in enumerate(news_data, start=1):
47
+ title = article.get("title", "No title")
48
+ vk_code = f"VK{i}" # custom short code
49
+ line = f"{i}. *{title}* ⚡\n{vk_code}\n\n"
50
 
51
+ if len(current_msg) + len(line) > MAX_CHARS:
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  messages.append(current_msg.strip())
53
+ current_msg = line
54
+ else:
55
+ current_msg += line
56
+ if current_msg:
57
+ messages.append(current_msg.strip())
58
 
59
  # Prepare WhatsApp number
60
  TO = whatsapp_number.strip()