PRC142004 commited on
Commit
34c461b
·
verified ·
1 Parent(s): 3936714

Upload 23 files

Browse files
app.py CHANGED
@@ -76,7 +76,10 @@ def run_telegram_bot():
76
  bot_main()
77
 
78
  except Exception as e:
79
- logger.exception(f"[BOT ERROR] {e}")
 
 
 
80
 
81
  def run_app():
82
  """Starts the full platform"""
 
76
  bot_main()
77
 
78
  except Exception as e:
79
+ logger.warning(f"[BOT WARNING] Telegram bot failed to initialize: {type(e).__name__}")
80
+ logger.info(f"[BOT INFO] This is normal if there's no internet/network access")
81
+ logger.info(f"[BOT INFO] REST APIs will continue working without the bot")
82
+ # Don't crash the app - just continue without the bot
83
 
84
  def run_app():
85
  """Starts the full platform"""
dashboard_output.json CHANGED
@@ -1,5 +1,5 @@
1
  {
2
- "generated_at": "2026-03-21T23:08:46.906740",
3
  "farmer_id": "F001",
4
  "farmer_profile": {
5
  "farmer_id": "F001",
@@ -184,39 +184,39 @@
184
  "Sunday",
185
  "Monday"
186
  ],
187
- "ai_recommendations": "Given the weather forecast for the next 9 days in India, here's some brief farming advice:\n\n**Sunday (Day 1):** Prepare the soil for sowing seeds by plowing and leveling the land. This will help loosen the soil and remove any debris.\n\n**Monday (Day 2):** Sow seeds for crops like wheat, gram, or mustard, which are suitable for the Indian climate. Make sure to water the soil gently but thoroughly.\n\n**Tuesday (Day 3):"
188
  },
189
  "pest_intelligence": {
190
  "status": "online",
191
- "report_title": "Wheat Pest Prediction Report for Rabi Season under Moderate Weather Conditions",
192
  "pest_prediction_table": [
193
  {
194
- "pest_name": "Aphids",
195
- "severity": "Low"
196
  },
197
  {
198
- "pest_name": "Armyworm",
199
- "severity": "Moderate"
200
  },
201
  {
202
- "pest_name": "Stem Borer",
203
  "severity": "High"
204
  },
205
  {
206
- "pest_name": "Thrips",
207
- "severity": "Low"
208
  }
209
  ],
210
  "weather_profile": []
211
  },
212
  "water_intelligence": {
213
  "status": "online",
214
- "water_mm": 6.7,
215
  "water_m3_sqm": 0.0067,
216
- "total_water_m3": 67.04,
217
- "irrigation_minutes": 402.23,
218
  "weather": {
219
- "temp": 25.64,
220
  "cond": "SUNNY"
221
  }
222
  },
@@ -242,20 +242,20 @@
242
  },
243
  {
244
  "type": "PEST_ALERT",
245
- "id": "PEST_STEM_BORER",
246
  "severity": "HIGH",
247
- "title": "\ud83d\udc1b STEM BORER ALERT",
248
- "message": "High Stem Borer infestation risk detected (50% confidence).",
249
  "action": "PEST_MANAGEMENT",
250
  "details": {
251
- "pest": "Stem Borer",
252
  "risk_level": "HIGH",
253
  "confidence": 50,
254
- "favorable_temp": "25.05\u00b0C is FAVORABLE for Stem Borer",
255
  "humidity_level": "Current: 60% - Moderate risk"
256
  },
257
  "action_items": [
258
- "\ud83d\udd0d Scout fields immediately for Stem Borer symptoms",
259
  "\ud83e\uddea Start bioagent/chemical control within 48 hours",
260
  "\ud83d\udcf8 Document infestation level (% affected plants)",
261
  "\ud83d\udcde Contact agricultural extension for spray recommendations",
@@ -282,7 +282,7 @@
282
  "message": "High irrigation need. Implement water-saving techniques.",
283
  "action": "CONSERVATION_MEASURE",
284
  "details": {
285
- "current_irrigation_time": 402,
286
  "potential_savings": "30-40%"
287
  },
288
  "action_items": [
 
1
  {
2
+ "generated_at": "2026-03-21T23:10:46.701397",
3
  "farmer_id": "F001",
4
  "farmer_profile": {
5
  "farmer_id": "F001",
 
184
  "Sunday",
185
  "Monday"
186
  ],
187
+ "ai_recommendations": "Based on the given weather pattern (assuming 'Sunday' to 'Saturday' as a week of sunny weather and the next 'Sunday' and 'Monday' as a continuation of sunny weather), here are some general farming tips for India:\n\n**Sunny Weather (Sunday to Saturday)**\n\n1. **Irrigation**: Water your crops in the early morning or evening to minimize evaporation.\n2. **Crop monitoring**: Regularly inspect your crops for signs of stress, pests, or diseases.\n3"
188
  },
189
  "pest_intelligence": {
190
  "status": "online",
191
+ "report_title": "Rabi Season Wheat Crop Pest Report",
192
  "pest_prediction_table": [
193
  {
194
+ "pest_name": "Aphid",
195
+ "severity": "Moderate"
196
  },
197
  {
198
+ "pest_name": "Thrips",
199
+ "severity": "Low"
200
  },
201
  {
202
+ "pest_name": "Armyworm",
203
  "severity": "High"
204
  },
205
  {
206
+ "pest_name": "Powdery mildew",
207
+ "severity": "Moderate"
208
  }
209
  ],
210
  "weather_profile": []
211
  },
212
  "water_intelligence": {
213
  "status": "online",
214
+ "water_mm": 6.65,
215
  "water_m3_sqm": 0.0067,
216
+ "total_water_m3": 66.53,
217
+ "irrigation_minutes": 399.19,
218
  "weather": {
219
+ "temp": 25.08,
220
  "cond": "SUNNY"
221
  }
222
  },
 
242
  },
243
  {
244
  "type": "PEST_ALERT",
245
+ "id": "PEST_ARMYWORM",
246
  "severity": "HIGH",
247
+ "title": "\ud83d\udc1b ARMYWORM ALERT",
248
+ "message": "High Armyworm infestation risk detected (50% confidence).",
249
  "action": "PEST_MANAGEMENT",
250
  "details": {
251
+ "pest": "Armyworm",
252
  "risk_level": "HIGH",
253
  "confidence": 50,
254
+ "favorable_temp": "25.05\u00b0C is FAVORABLE for Armyworm",
255
  "humidity_level": "Current: 60% - Moderate risk"
256
  },
257
  "action_items": [
258
+ "\ud83d\udd0d Scout fields immediately for Armyworm symptoms",
259
  "\ud83e\uddea Start bioagent/chemical control within 48 hours",
260
  "\ud83d\udcf8 Document infestation level (% affected plants)",
261
  "\ud83d\udcde Contact agricultural extension for spray recommendations",
 
282
  "message": "High irrigation need. Implement water-saving techniques.",
283
  "action": "CONSERVATION_MEASURE",
284
  "details": {
285
+ "current_irrigation_time": 399,
286
  "potential_savings": "30-40%"
287
  },
288
  "action_items": [
data/alerts_history.json ADDED
The diff for this file is too large to render. See raw diff
 
data/farmers.json ADDED
@@ -0,0 +1 @@
 
 
1
+ []
data/subscriptions.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "farmer_id": "F001",
4
+ "telegram_chat_id": "5397241102",
5
+ "subscribed_at": "2026-03-21T23:07:40.942865",
6
+ "active": true
7
+ }
8
+ ]
telegram_bot.py CHANGED
@@ -660,15 +660,32 @@ def main():
660
  loop = asyncio.new_event_loop()
661
  asyncio.set_event_loop(loop)
662
 
663
- loop.run_until_complete(app.initialize())
664
- loop.run_until_complete(app.start())
665
- logger.info("🤖 Bot polling started (non-signal mode)")
666
- try:
667
- loop.run_until_complete(app.updater.start_polling(allowed_updates=["message", "callback_query"]))
668
- except KeyboardInterrupt:
669
- pass
670
- finally:
671
- loop.run_until_complete(app.stop())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
672
  else:
673
  raise
674
 
 
660
  loop = asyncio.new_event_loop()
661
  asyncio.set_event_loop(loop)
662
 
663
+ retry_count = 0
664
+ max_retries = 3 # Reduced from 5 to 3 for faster feedback
665
+ while retry_count < max_retries:
666
+ try:
667
+ loop.run_until_complete(app.initialize())
668
+ loop.run_until_complete(app.start())
669
+ logger.info("🤖 Bot polling started (non-signal mode)")
670
+ try:
671
+ loop.run_until_complete(app.updater.start_polling(allowed_updates=["message", "callback_query"]))
672
+ except KeyboardInterrupt:
673
+ pass
674
+ finally:
675
+ loop.run_until_complete(app.stop())
676
+ break
677
+ except Exception as init_error:
678
+ retry_count += 1
679
+ if retry_count >= max_retries:
680
+ error_type = type(init_error).__name__
681
+ logger.error(f"Bot initialization failed ({error_type})")
682
+ logger.info("This is expected if there's no internet/network access.")
683
+ logger.info("REST APIs will continue working without the Telegram bot.")
684
+ raise # Re-raise so app.py can catch it
685
+ wait_time = min(2 ** retry_count, 16) # Exponential backoff
686
+ logger.warning(f"⚠️ Bot init failed (attempt {retry_count}/{max_retries}), retrying in {wait_time}s...")
687
+ import time
688
+ time.sleep(wait_time)
689
  else:
690
  raise
691