Riy777 commited on
Commit
129f2aa
·
verified ·
1 Parent(s): 65a61ae

Update r2.py

Browse files
Files changed (1) hide show
  1. r2.py +41 -1
r2.py CHANGED
@@ -1,4 +1,4 @@
1
- # r2.py
2
  import os, traceback, json, time
3
  from datetime import datetime, timedelta
4
  import asyncio
@@ -333,5 +333,45 @@ class R2Service:
333
  except Exception as e:
334
  print(f"❌ Failed to get monitored trades: {e}")
335
  return []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
336
 
337
  print("✅ Enhanced R2 Service Loaded - Comprehensive Logging System with Candidates Support")
 
1
+ # r2.py (محدث)
2
  import os, traceback, json, time
3
  from datetime import datetime, timedelta
4
  import asyncio
 
333
  except Exception as e:
334
  print(f"❌ Failed to get monitored trades: {e}")
335
  return []
336
+
337
+ #
338
+ # 🔴 دالة جديدة: لحفظ سجل تدقيق التحليل
339
+ #
340
+ async def save_analysis_audit_log_async(self, audit_data):
341
+ """حفظ سجل تدقيق دورة التحليل (يحتفظ بآخر 50 دورة)"""
342
+ try:
343
+ key = "analysis_audit_log.json"
344
+
345
+ # 1. جلب السجل الحالي (إن وجد)
346
+ try:
347
+ response = self.s3_client.get_object(Bucket=BUCKET_NAME, Key=key)
348
+ existing_log_data = json.loads(response['Body'].read())
349
+ if isinstance(existing_log_data, list):
350
+ history = existing_log_data
351
+ else:
352
+ history = [] # بدء سجل جديد إذا كان التنسيق غير صالح
353
+ except ClientError as e:
354
+ if e.response['Error']['Code'] == 'NoSuchKey':
355
+ history = [] # ملف جديد
356
+ else:
357
+ raise
358
+
359
+ # 2. إضافة الدورة الحالية
360
+ history.append(audit_data)
361
+
362
+ # 3. الحفاظ على آخر 50 سجل فقط
363
+ if len(history) > 50:
364
+ history = history[-50:]
365
+
366
+ # 4. حفظ الملف المحدث
367
+ data_json = json.dumps(history, indent=2, ensure_ascii=False).encode('utf-8')
368
+ self.s3_client.put_object(
369
+ Bucket=BUCKET_NAME, Key=key, Body=data_json, ContentType="application/json"
370
+ )
371
+ print(f"📊 تم حفظ سجل تدقيق التحليل بنجاح في R2 (إجمالي {len(history)} سجلات)")
372
+
373
+ except Exception as e:
374
+ print(f"❌ فشل حفظ سجل تدقيق التحليل في R2: {e}")
375
+
376
 
377
  print("✅ Enhanced R2 Service Loaded - Comprehensive Logging System with Candidates Support")