CodeXDevloper commited on
Commit
fa3a365
·
verified ·
1 Parent(s): d82acc2

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +38 -99
app.py CHANGED
@@ -2,18 +2,15 @@ from flask import Flask, request
2
  import pyarrow.parquet as pq
3
 
4
  app = Flask(__name__)
5
-
6
  PARQUET_FILE = "mera_data.parquet"
7
 
8
  def search_data(query):
9
  query = str(query).strip().lower()
10
  pf = pq.ParquetFile(PARQUET_FILE)
11
-
12
  for batch in pf.iter_batches(batch_size=10000):
13
  for i in range(batch.num_rows):
14
  tg_id = str(batch.column("TG_ID")[i].as_py() or "").lower()
15
  tg_username = str(batch.column("TG_USERNAME")[i].as_py() or "").lower()
16
-
17
  if query == tg_id or query == tg_username:
18
  return {
19
  "TG_ID": batch.column("TG_ID")[i].as_py(),
@@ -26,112 +23,54 @@ def search_data(query):
26
  @app.route("/search", methods=["GET"])
27
  def search():
28
  query = request.args.get("search", "").strip()
29
-
30
  if not query:
31
- response_text = (
32
- '{
33
- '
34
- ' "status": "error",
35
- '
36
- ' "message": "Search value required!",
37
- '
38
- ' "example": "/search?search=Kudesner77",
39
- '
40
- '
41
-
42
-
43
-
44
- '
45
- ' "owner": "Code X",
46
- '
47
- ' "username": "@C4DX1"
48
- '
49
- '}'
50
- )
51
- return app.response_class(response=response_text, status=400, mimetype='application/json')
52
-
53
  result = search_data(query)
54
-
55
  if result:
56
- response_text = (
57
- '{
58
- '
59
- f' "status": "found",
60
- '
61
- f' "query": "{query}",
62
- '
63
- f' "data": {{
64
- '
65
- f' "TG_ID": "{result["TG_ID"]}",
66
- '
67
- f' "TG_USERNAME": "{result["TG_USERNAME"]}",
68
- '
69
- f' "FIRST_NAME": "{result["FIRST_NAME"]}",
70
- '
71
- f' "PHONE": "{result["PHONE"]}"
72
- '
73
- f' }},
74
- '
75
- '
76
-
77
-
78
-
79
- '
80
- ' "owner": "Code X",
81
- '
82
- ' "username": "@C4DX1"
83
- '
84
- '}'
85
  )
86
- return app.response_class(response=response_text, status=200, mimetype='application/json')
87
  else:
88
- response_text = (
89
- '{
90
- '
91
- f' "status": "not found",
92
- '
93
- f' "query": "{query}",
94
- '
95
- ' "message": "No data found!",
96
- '
97
- '
98
-
99
-
100
-
101
- '
102
- ' "owner": "Code X",
103
- '
104
- ' "username": "@C4DX1"
105
- '
106
- '}'
107
  )
108
- return app.response_class(response=response_text, status=404, mimetype='application/json')
109
 
110
  @app.route("/", methods=["GET"])
111
  def home():
112
- response_text = (
113
- '{
114
- '
115
- ' "status": "online",
116
- '
117
- ' "name": "Code X API",
118
- '
119
- ' "usage": "/search?search=TG_USERNAME or TG_ID",
120
- '
121
- ' "example": "/search?search=Kudesner77",
122
- '
123
- '
124
-
125
-
126
-
127
- '
128
- ' "owner": "Code X",
129
- '
130
- ' "username": "@C4DX1"
131
- '
132
- '}'
133
  )
134
- return app.response_class(response=response_text, status=200, mimetype='application/json')
135
 
136
  if __name__ == "__main__":
137
  app.run(host="0.0.0.0", port=7860)
 
2
  import pyarrow.parquet as pq
3
 
4
  app = Flask(__name__)
 
5
  PARQUET_FILE = "mera_data.parquet"
6
 
7
  def search_data(query):
8
  query = str(query).strip().lower()
9
  pf = pq.ParquetFile(PARQUET_FILE)
 
10
  for batch in pf.iter_batches(batch_size=10000):
11
  for i in range(batch.num_rows):
12
  tg_id = str(batch.column("TG_ID")[i].as_py() or "").lower()
13
  tg_username = str(batch.column("TG_USERNAME")[i].as_py() or "").lower()
 
14
  if query == tg_id or query == tg_username:
15
  return {
16
  "TG_ID": batch.column("TG_ID")[i].as_py(),
 
23
  @app.route("/search", methods=["GET"])
24
  def search():
25
  query = request.args.get("search", "").strip()
 
26
  if not query:
27
+ r = '{"status":"error","message":"Search value required!","example":"/search?search=Kudesner77"}'
28
+ return app.response_class(response=r, status=400, mimetype="application/json")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  result = search_data(query)
 
30
  if result:
31
+ r = (
32
+ "{\n"
33
+ ' "status": "found",\n'
34
+ f' "query": "{query}",\n'
35
+ ' "data": {\n'
36
+ f' "TG_ID": "{result["TG_ID"]}",\n'
37
+ f' "TG_USERNAME": "{result["TG_USERNAME"]}",\n'
38
+ f' "FIRST_NAME": "{result["FIRST_NAME"]}",\n'
39
+ f' "PHONE": "{result["PHONE"]}"\n'
40
+ " },\n"
41
+ "\n\n\n\n"
42
+ ' "owner": "Code X",\n'
43
+ ' "username": "@C4DX1"\n'
44
+ "}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  )
46
+ return app.response_class(response=r, status=200, mimetype="application/json")
47
  else:
48
+ r = (
49
+ "{\n"
50
+ ' "status": "not found",\n'
51
+ f' "query": "{query}",\n'
52
+ ' "message": "No data found!",\n'
53
+ "\n\n\n\n"
54
+ ' "owner": "Code X",\n'
55
+ ' "username": "@C4DX1"\n'
56
+ "}"
 
 
 
 
 
 
 
 
 
 
57
  )
58
+ return app.response_class(response=r, status=404, mimetype="application/json")
59
 
60
  @app.route("/", methods=["GET"])
61
  def home():
62
+ r = (
63
+ "{\n"
64
+ ' "status": "online",\n'
65
+ ' "name": "Code X API",\n'
66
+ ' "usage": "/search?search=TG_USERNAME or TG_ID",\n'
67
+ ' "example": "/search?search=Kudesner77",\n'
68
+ "\n\n\n\n"
69
+ ' "owner": "Code X",\n'
70
+ ' "username": "@C4DX1"\n'
71
+ "}"
 
 
 
 
 
 
 
 
 
 
 
72
  )
73
+ return app.response_class(response=r, status=200, mimetype="application/json")
74
 
75
  if __name__ == "__main__":
76
  app.run(host="0.0.0.0", port=7860)