Spaces:
Running
Running
Download scripts/deidentify_help_feedback.py from Success-dev/venthrive-api: direct link, hf CLI and curl.
- Browser
- Download file 1.25 kB
-
https://huggingface.co/spaces/Success-dev/venthrive-api/resolve/main/scripts/deidentify_help_feedback.py
- Command line
-
hf download hf://spaces/Success-dev/venthrive-api/scripts/deidentify_help_feedback.py
-
curl -L -o deidentify_help_feedback.py https://huggingface.co/spaces/Success-dev/venthrive-api/resolve/main/scripts/deidentify_help_feedback.py
1.25 kB
| """ | |
| De-identify help feedback older than 30 days: delete the free-text comment and the | |
| anonymous session id, keep page / vote / reason / device for trend reporting. | |
| Run on a schedule (it is safe to run repeatedly): | |
| python -m scripts.deidentify_help_feedback | |
| Needs the same FIREBASE_SERVICE_ACCOUNT environment as the API. | |
| """ | |
| import json | |
| import os | |
| import time | |
| import firebase_admin | |
| from firebase_admin import credentials, firestore | |
| def run() -> int: | |
| if not firebase_admin._apps: | |
| sa = os.environ.get("FIREBASE_SERVICE_ACCOUNT") | |
| cred = credentials.Certificate(json.loads(sa)) if sa else credentials.ApplicationDefault() | |
| firebase_admin.initialize_app(cred) | |
| db = firestore.client() | |
| # One range filter only (no composite index needed); skip finished records here. | |
| due = db.collection("help_feedback").where("deidentifyAfter", "<=", time.time()).stream() | |
| count = 0 | |
| for doc in due: | |
| if doc.to_dict().get("deidentified"): | |
| continue | |
| doc.reference.update({"comment": firestore.DELETE_FIELD, "sessionId": firestore.DELETE_FIELD, "deidentified": True}) | |
| count += 1 | |
| return count | |
| if __name__ == "__main__": | |
| print(f"De-identified {run()} help feedback record(s).") | |