rafaldembski commited on
Commit
3b2c8d9
·
verified ·
1 Parent(s): 4f6dc99

Update utils/functions.py

Browse files
Files changed (1) hide show
  1. utils/functions.py +44 -1
utils/functions.py CHANGED
@@ -1,8 +1,12 @@
 
 
1
  import phonenumbers
2
  from phonenumbers import geocoder, carrier
3
  import re
4
  import requests
5
  import os
 
 
6
 
7
  def get_phone_info(phone_number):
8
  """
@@ -104,4 +108,43 @@ Podaj swoją analizę i wnioski zgodnie z powyższymi wytycznymi."""
104
  return f"Błąd API: {response.status_code} - {response.text}", "Błąd analizy.", "Błąd analizy."
105
  except Exception as e:
106
  return f"Błąd połączenia z API: {e}", "Błąd analizy.", "Błąd analizy."
107
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # utils/functions.py
2
+
3
  import phonenumbers
4
  from phonenumbers import geocoder, carrier
5
  import re
6
  import requests
7
  import os
8
+ import json
9
+ from datetime import datetime
10
 
11
  def get_phone_info(phone_number):
12
  """
 
108
  return f"Błąd API: {response.status_code} - {response.text}", "Błąd analizy.", "Błąd analizy."
109
  except Exception as e:
110
  return f"Błąd połączenia z API: {e}", "Błąd analizy.", "Błąd analizy."
111
+
112
+ def init_stats_file():
113
+ """
114
+ Inicjalizuje plik statystyk, jeśli nie istnieje.
115
+ """
116
+ stats_file = 'stats.json'
117
+ if not os.path.exists(stats_file):
118
+ with open(stats_file, 'w') as f:
119
+ json.dump({"total_analyses": 0, "total_frauds_detected": 0}, f)
120
+
121
+ def update_stats(fraud_detected=False):
122
+ """
123
+ Aktualizuje statystyki analizy.
124
+ """
125
+ stats_file = 'stats.json'
126
+ try:
127
+ with open(stats_file, 'r') as f:
128
+ stats = json.load(f)
129
+ except (json.JSONDecodeError, FileNotFoundError):
130
+ stats = {"total_analyses": 0, "total_frauds_detected": 0}
131
+
132
+ stats["total_analyses"] += 1
133
+ if fraud_detected:
134
+ stats["total_frauds_detected"] += 1
135
+
136
+ with open(stats_file, 'w') as f:
137
+ json.dump(stats, f, indent=4)
138
+
139
+ def get_stats():
140
+ """
141
+ Pobiera aktualne statystyki analizy.
142
+ """
143
+ stats_file = 'stats.json'
144
+ try:
145
+ with open(stats_file, 'r') as f:
146
+ stats = json.load(f)
147
+ return stats
148
+ except (json.JSONDecodeError, FileNotFoundError):
149
+ return {"total_analyses": 0, "total_frauds_detected": 0}
150
+ ```