Wasifali95 commited on
Commit
0d4ec61
·
verified ·
1 Parent(s): 8667d11

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +12 -0
  2. main.py +191 -0
  3. requirements.txt +4 -0
Dockerfile ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9-slim
2
+
3
+ WORKDIR /app
4
+
5
+ COPY requirements.txt .
6
+ RUN pip install --no-cache-dir -r requirements.txt
7
+
8
+ COPY main.py .
9
+
10
+ EXPOSE 7860
11
+
12
+ CMD ["python", "main.py"]
main.py ADDED
@@ -0,0 +1,191 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # main.py
2
+ from fastapi import FastAPI, Query
3
+ from fastapi.responses import JSONResponse
4
+ from fastapi.middleware.cors import CORSMiddleware
5
+ import requests
6
+ import re
7
+ from bs4 import BeautifulSoup
8
+ import uvicorn
9
+
10
+ app = FastAPI(title="SIM Tracker API", version="1.0.0", docs_url=None, redoc_url=None)
11
+
12
+ # CORS middleware
13
+ app.add_middleware(
14
+ CORSMiddleware,
15
+ allow_origins=["*"],
16
+ allow_credentials=True,
17
+ allow_methods=["*"],
18
+ allow_headers=["*"],
19
+ )
20
+
21
+ # Headers for simlivetracker.com.pk
22
+ HEADERS = {
23
+ "Host": "simlivetracker.com.pk",
24
+ "sec-ch-ua-platform": "Android",
25
+ "user-agent": "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Mobile Safari/537.36",
26
+ "accept": "*/*",
27
+ "referer": "https://simlivetracker.com.pk/",
28
+ "accept-language": "en-US,en;q=0.9,ur-PK;q=0.8,ur;q=0.7"
29
+ }
30
+
31
+ def detect_network(mobile: str) -> str:
32
+ if not mobile or len(mobile) < 4:
33
+ return "Unknown"
34
+ try:
35
+ prefix = int(mobile[:4])
36
+ if 301 <= prefix <= 329:
37
+ return "Jazz"
38
+ elif 310 <= prefix <= 319:
39
+ return "Zong"
40
+ elif 330 <= prefix <= 339:
41
+ return "Ufone"
42
+ elif 340 <= prefix <= 359:
43
+ return "Telenor"
44
+ else:
45
+ return "Unknown"
46
+ except:
47
+ return "Unknown"
48
+
49
+ def fetch_data(search: str, search_type: str) -> dict:
50
+ url = "https://simlivetracker.com.pk/api.php"
51
+ params = {"search": search, "type": search_type}
52
+
53
+ try:
54
+ response = requests.get(url, params=params, headers=HEADERS, timeout=15)
55
+
56
+ if response.status_code != 200:
57
+ return {"success": False, "message": f"API error: {response.status_code}"}
58
+
59
+ html = response.text
60
+ soup = BeautifulSoup(html, 'html.parser')
61
+ text = html
62
+
63
+ data = {"success": True}
64
+
65
+ if search_type == "mobile":
66
+ name_match = re.search(r'Name[:\s]*([^<\n]+)', text, re.IGNORECASE)
67
+ mobile_match = re.search(r'Mobile[:\s]*([0-9]+)', text, re.IGNORECASE)
68
+ cnic_match = re.search(r'CNIC[:\s]*([0-9-]+)', text, re.IGNORECASE)
69
+ address_match = re.search(r'Address[:\s]*([^<\n]+)', text, re.IGNORECASE)
70
+
71
+ if mobile_match:
72
+ data["mobile"] = mobile_match.group(1).strip()
73
+ data["network"] = detect_network(data["mobile"])
74
+ if name_match:
75
+ data["name"] = name_match.group(1).strip()
76
+ if cnic_match:
77
+ data["cnic"] = cnic_match.group(1).strip()
78
+ if address_match:
79
+ data["address"] = address_match.group(1).strip()
80
+
81
+ else: # cnic search
82
+ records = []
83
+ rows = soup.find_all('tr')
84
+ for row in rows:
85
+ cols = row.find_all('td')
86
+ if len(cols) >= 3:
87
+ mobile = cols[0].get_text(strip=True) if len(cols) > 0 else ""
88
+ name = cols[1].get_text(strip=True) if len(cols) > 1 else ""
89
+ cnic_val = cols[2].get_text(strip=True) if len(cols) > 2 else ""
90
+ address_val = cols[3].get_text(strip=True) if len(cols) > 3 else ""
91
+
92
+ if mobile and re.match(r'^03[0-9]{9}$', mobile):
93
+ records.append({
94
+ "name": name,
95
+ "mobile": mobile,
96
+ "cnic": cnic_val,
97
+ "network": detect_network(mobile),
98
+ "address": address_val
99
+ })
100
+
101
+ if records:
102
+ data["cnic"] = search
103
+ data["name"] = records[0].get("name", "")
104
+ data["total_sims"] = len(records)
105
+ data["records"] = records
106
+ else:
107
+ # Single record fallback
108
+ name_match = re.search(r'Name[:\s]*([^<\n]+)', text, re.IGNORECASE)
109
+ mobile_match = re.search(r'Mobile[:\s]*([0-9]+)', text, re.IGNORECASE)
110
+ cnic_match = re.search(r'CNIC[:\s]*([0-9-]+)', text, re.IGNORECASE)
111
+
112
+ if mobile_match:
113
+ data["cnic"] = search
114
+ data["name"] = name_match.group(1).strip() if name_match else ""
115
+ data["total_sims"] = 1
116
+ data["records"] = [{
117
+ "name": name_match.group(1).strip() if name_match else "",
118
+ "mobile": mobile_match.group(1).strip(),
119
+ "cnic": cnic_match.group(1).strip() if cnic_match else "",
120
+ "network": detect_network(mobile_match.group(1).strip())
121
+ }]
122
+
123
+ return data
124
+
125
+ except Exception as e:
126
+ return {"success": False, "message": str(e)}
127
+
128
+ @app.get("/")
129
+ async def root():
130
+ return JSONResponse({
131
+ "status": "active",
132
+ "endpoints": {
133
+ "mobile": "/api?search=03007058868",
134
+ "cnic": "/api?search=35201-1234567-8"
135
+ },
136
+ "developer": "WASIF ALI",
137
+ "telegram": "@THE_FREE_HACKS"
138
+ })
139
+
140
+ @app.get("/api")
141
+ async def search(search: str = Query(...)):
142
+ search_clean = re.sub(r'\s+', '', search)
143
+
144
+ if re.match(r'^03[0-9]{9}$', search_clean):
145
+ search_type = "mobile"
146
+ elif re.match(r'^[0-9]{5}-[0-9]{7}-[0-9]$', search_clean) or re.match(r'^[0-9]{13}$', search_clean):
147
+ search_type = "cnic"
148
+ if re.match(r'^[0-9]{13}$', search_clean):
149
+ search_clean = f"{search_clean[:5]}-{search_clean[5:12]}-{search_clean[12]}"
150
+ else:
151
+ return JSONResponse({
152
+ "status": False,
153
+ "message": "Invalid format. Use mobile (03xxxxxxxxx) or CNIC (xxxxx-xxxxxxx-x)",
154
+ "developer": "WASIF ALI",
155
+ "telegram": "@THE_FREE_HACKS"
156
+ }, status_code=400)
157
+
158
+ result = fetch_data(search_clean, search_type)
159
+
160
+ if result.get("success"):
161
+ response_data = {"status": True, "developer": "WASIF ALI", "telegram": "@THE_FREE_HACKS"}
162
+
163
+ if search_type == "mobile":
164
+ for key in ["name", "mobile", "cnic", "network", "address"]:
165
+ if result.get(key):
166
+ response_data[key] = result[key]
167
+ else:
168
+ for key in ["cnic", "name", "total_sims", "records"]:
169
+ if result.get(key):
170
+ response_data[key] = result[key]
171
+
172
+ return JSONResponse(response_data)
173
+ else:
174
+ return JSONResponse({
175
+ "status": False,
176
+ "message": result.get("message", "No data found"),
177
+ "developer": "WASIF ALI",
178
+ "telegram": "@THE_FREE_HACKS"
179
+ }, status_code=404)
180
+
181
+ @app.get("/test")
182
+ async def test():
183
+ return JSONResponse({
184
+ "status": True,
185
+ "message": "API is working",
186
+ "developer": "WASIF ALI",
187
+ "telegram": "@THE_FREE_HACKS"
188
+ })
189
+
190
+ if __name__ == "__main__":
191
+ uvicorn.run(app, host="0.0.0.0", port=7860)
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ fastapi==0.104.1
2
+ uvicorn==0.24.0
3
+ requests==2.31.0
4
+ beautifulsoup4==4.12.3