Spaces:
Sleeping
Sleeping
Download app.py from CodeXDevloper/Simple: direct link, hf CLI and curl.
- Browser
- Download file 2.07 kB
-
https://huggingface.co/spaces/CodeXDevloper/Simple/resolve/c313aae902ed8e813e186eecbeea25d019e3669b/app.py
- Command line
-
hf download hf://spaces/CodeXDevloper/Simple@c313aae902ed8e813e186eecbeea25d019e3669b/app.py
-
curl -L -o app.py https://huggingface.co/spaces/CodeXDevloper/Simple/resolve/c313aae902ed8e813e186eecbeea25d019e3669b/app.py
2.07 kB
| from flask import Flask, request, jsonify | |
| import pyarrow.parquet as pq | |
| app = Flask(__name__) | |
| PARQUET_FILE = "mera_data.parquet" | |
| def search_data(query): | |
| query = str(query).strip().lower() | |
| pf = pq.ParquetFile(PARQUET_FILE) | |
| for batch in pf.iter_batches(batch_size=10000): | |
| for i in range(batch.num_rows): | |
| tg_id = str(batch.column("TG_ID")[i].as_py() or "").lower() | |
| tg_username = str(batch.column("TG_USERNAME")[i].as_py() or "").lower() | |
| if query == tg_id or query == tg_username: | |
| return { | |
| "TG_ID": batch.column("TG_ID")[i].as_py(), | |
| "FIRST_NAME": batch.column("FIRST_NAME")[i].as_py(), | |
| "TG_USERNAME": batch.column("TG_USERNAME")[i].as_py(), | |
| "PHONE": batch.column("PHONE")[i].as_py(), | |
| } | |
| return None | |
| def search(): | |
| query = request.args.get("search", "").strip() | |
| if not query: | |
| return jsonify({ | |
| "status": "error", | |
| "message": "Search value required!", | |
| "example": "/search?search=Kudesner77", | |
| "owner": "Code X", | |
| "username": "@C4DX1" | |
| }), 400 | |
| result = search_data(query) | |
| if result: | |
| return jsonify({ | |
| "status": "found", | |
| "query": query, | |
| "data": result, | |
| "owner": "Code X", | |
| "username": "@C4DX1" | |
| }) | |
| else: | |
| return jsonify({ | |
| "status": "not found", | |
| "query": query, | |
| "message": "No data found!", | |
| "owner": "Code X", | |
| "username": "@C4DX1" | |
| }), 404 | |
| def home(): | |
| return jsonify({ | |
| "status": "online", | |
| "name": "Code X API", | |
| "owner": "Code X", | |
| "username": "@C4DX1", | |
| "usage": "/search?search=TG_USERNAME or TG_ID", | |
| "example": "/search?search=Kudesner77" | |
| }) | |
| if __name__ == "__main__": | |
| app.run(host="0.0.0.0", port=7860) | |