|
@@ -0,0 +1,49 @@
|
|
|
|
+# 一致监听本地剪切板,如果有变化,则打印出来
|
|
|
|
+import threading
|
|
|
|
+import time
|
|
|
|
+
|
|
|
|
+import pyperclip
|
|
|
|
+import redis
|
|
|
|
+import requests
|
|
|
|
+import uvicorn as uvicorn
|
|
|
|
+from fastapi import FastAPI
|
|
|
|
+from starlette.middleware.cors import CORSMiddleware
|
|
|
|
+from starlette.middleware.sessions import SessionMiddleware
|
|
|
|
+from starlette.responses import JSONResponse
|
|
|
|
+
|
|
|
|
+r = redis.StrictRedis(host='127.0.0.1', port=6379, db=0)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def getRemoteValue():
|
|
|
|
+ res = requests.get('http://192.168.3.17:8000/clipboard')
|
|
|
|
+ if res.status_code == 200:
|
|
|
|
+ return res.json()['clipboard']
|
|
|
|
+ else:
|
|
|
|
+ return None
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+app = FastAPI(title="project name2", description="系统描述 ", version="v 0.0.0")
|
|
|
|
+app.add_middleware(SessionMiddleware, secret_key='123456hhh1')
|
|
|
|
+app.add_middleware(
|
|
|
|
+ CORSMiddleware,
|
|
|
|
+ allow_origins=["*", ],
|
|
|
|
+ allow_credentials=True,
|
|
|
|
+ allow_methods=["*"],
|
|
|
|
+ allow_headers=["*"],
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+# api 获取剪切板
|
|
|
|
+@app.get('/clipboard')
|
|
|
|
+def get_clipboard():
|
|
|
|
+ return {'clipboard': getRemoteValue()}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+@app.exception_handler(Exception)
|
|
|
|
+def validation_exception_handler(request, exc):
|
|
|
|
+ """请求校验异常捕获; application/json """
|
|
|
|
+ return JSONResponse({'message': "服务器内部错误", 'status_code': 500})
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+if __name__ == '__main__':
|
|
|
|
+ uvicorn.run(app='readClient2:app', host="0.0.0.0", port=8001)
|