File size: 3,148 Bytes
9af4e87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# api.py
from fastapi import FastAPI, HTTPException
from typing import Optional
from fastapi.middleware.cors import CORSMiddleware
from Wright import automate_cwall_login, cwall_ww_sub, Get_PHPSESSID, get_cwall_ww_info, clear_auth, ww_like, ww_Comment

app = FastAPI()

# 添加CORS中间件
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

@app.post("/automate_cwall_login")
def api_automate_cwall_login(

    username: str,

    password: str,

    headless: bool = False,

    timeout: int = 30000,

    keep_open: bool = False

):
    try:
        result = automate_cwall_login(username, password, headless, timeout, keep_open)
        return {"success": result}
    except Exception as e:
        raise HTTPException(status_code=500, detail=str(e))

@app.post("/cwall_ww_sub")
def api_cwall_ww_sub(

    info: str,

    kind: str,

    image: str,

    image_update_enable: bool = False,

    kind_enable: bool = False,

    headless: bool = False,

    timeout: int = 30000,

    keep_open: bool = False

):
    try:
        result = cwall_ww_sub(info, kind, kind_enable, headless=headless, timeout=timeout, keep_open=keep_open, image=image, image_update_enable=image_update_enable)
        return {"success": result}
    except Exception as e:
        raise HTTPException(status_code=500, detail=str(e))

@app.post("/Get_PHPSESSID")
def api_Get_PHPSESSID(

    username: str,

    password: str,

    headless: bool = False,

    timeout: int = 30000,

    keep_open: bool = False

):
    try:
        result = Get_PHPSESSID(username, password, headless, timeout, keep_open)
        return {"success": result}
    except Exception as e:
        raise HTTPException(status_code=500, detail=str(e))

@app.post("/get_cwall_ww_info")
def api_get_cwall_ww_info(page: str = "1"):
    try:
        result = get_cwall_ww_info(page)
        return {"success": True, "data": result}
    except Exception as e:
        raise HTTPException(status_code=500, detail=str(e))

@app.post("/clear_auth")
def api_clear_auth():
    try:
        clear_auth()
        return {"success": True}
    except Exception as e:
        raise HTTPException(status_code=500, detail=str(e))

@app.post("/ww_like")
def api_ww_like(

    post_id: str,

    headless: bool = False,

    timeout: int = 30000,

    keep_open: bool = False

):
    try:
        result = ww_like(post_id, headless, timeout, keep_open)
        return {"success": result}
    except Exception as e:
        raise HTTPException(status_code=500, detail=str(e))

@app.post("/ww_Comment")
def api_ww_Comment(

    info: str,

    post_id: str,

    headless: bool = False,

    timeout: int = 30000,

    keep_open: bool = False

):
    try:
        result = ww_Comment(info, post_id, headless, timeout, keep_open)
        return {"success": result}
    except Exception as e:
        raise HTTPException(status_code=500, detail=str(e))

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000)