Spaces:
Sleeping
Sleeping
| # 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=["*"], | |
| ) | |
| 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)) | |
| 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)) | |
| 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)) | |
| 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)) | |
| def api_clear_auth(): | |
| try: | |
| clear_auth() | |
| return {"success": True} | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=str(e)) | |
| 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)) | |
| 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) |