Spaces:
Sleeping
Sleeping
hf-actions
commited on
Commit
·
5de9f75
1
Parent(s):
0020de5
feat: log FB token remaining_days on validation
Browse files
app.py
CHANGED
|
@@ -194,18 +194,19 @@ if __name__ == "__main__":
|
|
| 194 |
logger.exception("Failed to write token validation failure to log.txt")
|
| 195 |
ok = False
|
| 196 |
else:
|
| 197 |
-
# determine expiry classification if available
|
| 198 |
expires_at = debug_info.get("expires_at")
|
|
|
|
| 199 |
if expires_at:
|
| 200 |
try:
|
| 201 |
expires_at = int(expires_at)
|
| 202 |
import time as _time
|
| 203 |
delta = expires_at - int(_time.time())
|
| 204 |
-
|
| 205 |
-
if
|
| 206 |
-
token_type = f"long-lived (~{
|
| 207 |
else:
|
| 208 |
-
token_type = f"short-lived (~{
|
| 209 |
except Exception:
|
| 210 |
token_type = "unknown-expiry"
|
| 211 |
else:
|
|
@@ -213,7 +214,11 @@ if __name__ == "__main__":
|
|
| 213 |
logger.info("Facebook token looks valid (%s)", token_type)
|
| 214 |
try:
|
| 215 |
with open("log.txt", "a", encoding="utf-8") as lf:
|
| 216 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
except Exception:
|
| 218 |
logger.exception("Failed to write token validation ok to log.txt")
|
| 219 |
except Exception as e:
|
|
|
|
| 194 |
logger.exception("Failed to write token validation failure to log.txt")
|
| 195 |
ok = False
|
| 196 |
else:
|
| 197 |
+
# determine expiry classification if available and log remaining days
|
| 198 |
expires_at = debug_info.get("expires_at")
|
| 199 |
+
remaining_days = None
|
| 200 |
if expires_at:
|
| 201 |
try:
|
| 202 |
expires_at = int(expires_at)
|
| 203 |
import time as _time
|
| 204 |
delta = expires_at - int(_time.time())
|
| 205 |
+
remaining_days = max(0, delta // 86400)
|
| 206 |
+
if remaining_days >= 30:
|
| 207 |
+
token_type = f"long-lived (~{remaining_days} days)"
|
| 208 |
else:
|
| 209 |
+
token_type = f"short-lived (~{remaining_days} days)"
|
| 210 |
except Exception:
|
| 211 |
token_type = "unknown-expiry"
|
| 212 |
else:
|
|
|
|
| 214 |
logger.info("Facebook token looks valid (%s)", token_type)
|
| 215 |
try:
|
| 216 |
with open("log.txt", "a", encoding="utf-8") as lf:
|
| 217 |
+
entry = f"[{__import__('time').strftime('%Y-%m-%d %H:%M:%S')}] FB_TOKEN_VALIDATION_OK type={token_type}"
|
| 218 |
+
if remaining_days is not None:
|
| 219 |
+
entry += f" remaining_days={remaining_days}"
|
| 220 |
+
entry += "\n"
|
| 221 |
+
lf.write(entry)
|
| 222 |
except Exception:
|
| 223 |
logger.exception("Failed to write token validation ok to log.txt")
|
| 224 |
except Exception as e:
|