-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_server.py
More file actions
85 lines (61 loc) · 2.31 KB
/
test_server.py
File metadata and controls
85 lines (61 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python3
"""Lightweight FastAPI test server exposing KrisBot helpers.
Endpoints:
POST /tiktok/search {"email":..., "phone":...}
POST /tiktok/by_url {"url":...}
POST /instagram/by_url {"url":...}
POST /facebook/by_url {"url":...}
POST /probe {"pattern":...}
By default this server forces MOCK_MODE=1 so responses are deterministic and safe.
"""
import os
from typing import List, Dict, Any
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
import asyncio
# Ensure mock mode for predictable behavior
os.environ.setdefault("MOCK_MODE", "1")
from KrisBot import (
perform_tiktok_scrape,
perform_tiktok_scrape_by_url,
perform_instagram_scrape_by_url,
perform_facebook_scrape_by_url,
_expand_pattern,
_probe_usernames,
)
app = FastAPI(title="KrisBot Test Server")
class TikTokSearchRequest(BaseModel):
email: str
phone: str
class URLRequest(BaseModel):
url: str
class ProbeRequest(BaseModel):
pattern: str
@app.post("/tiktok/search")
async def tiktok_search(req: TikTokSearchRequest) -> List[Dict[str, Any]]:
res = await perform_tiktok_scrape(email=req.email, phone=req.phone)
return res
@app.post("/tiktok/by_url")
async def tiktok_by_url(req: URLRequest) -> List[Dict[str, Any]]:
res = await perform_tiktok_scrape_by_url(req.url)
return res
@app.post("/instagram/by_url")
async def instagram_by_url(req: URLRequest) -> List[Dict[str, Any]]:
res = await perform_instagram_scrape_by_url(req.url)
return res
@app.post("/facebook/by_url")
async def facebook_by_url(req: URLRequest) -> List[Dict[str, Any]]:
res = await perform_facebook_scrape_by_url(req.url)
return res
@app.post("/probe")
async def probe(req: ProbeRequest) -> Dict[str, Any]:
pattern = req.pattern
candidates = _expand_pattern(pattern, max_len=int(os.environ.get("PROBE_MAX_LEN", "2")))
# limit to avoid heavy loads
limit = int(os.environ.get("PROBE_CANDIDATE_LIMIT", "200"))
candidates = candidates[:limit]
found = await _probe_usernames(candidates, concurrency=int(os.environ.get("PROBE_CONCURRENCY", "5")))
return {"pattern": pattern, "generated": len(candidates), "found": found}
if __name__ == "__main__":
import uvicorn
uvicorn.run("test_server:app", host="127.0.0.1", port=8000, log_level="info")