add crontab task
continuous-integration/drone/push Build is passing

This commit is contained in:
jianxin committed 2024-02-04 19:35:23 +08:00
1 parent 9ec12d9cfb
commit 57e98728eb
13 files changed
+259 -5

No files matched your search

+5
View File
@@ -17,3 +17,8 @@ TABLE_ID=tblwgGCDCE74Ugv6
# REDIS
BROKER_URL=redis://office-xbot-redis
RESULT_BACKEND=redis://office-xbot-redis
# Yingdao PassWord
XBOT_USERNAME=jxcs@bigdata
XBOT_PASSWORD=320753691love
+1
View File
@@ -1 +1,2 @@
venv/
*.pyc
+5 -1
View File
@@ -15,7 +15,7 @@ from lark_oapi.api.im.v1 import *
from lark_oapi.api.bitable.v1 import *
from app.task import *
from app.utils import *
from app.utils.utils import *
from app.task import *
load_dotenv()
@@ -106,6 +106,10 @@ def create_app() -> Flask:
add.delay(1, 2)
return {"test": "ok"}
@app.route("/index", methods=["GET"])
def index():
return {"test": "ok"}
return app
Binary file not shown.
Binary file not shown.
Binary file not shown.
+7
View File
@@ -2,3 +2,10 @@ from app import create_app
flask_app = create_app()
celery_app = flask_app.extensions["celery"]
celery_app.conf.beat_schedule = {
"add-every-30-seconds": {
"task": "app.task.sync_xbot_activity_info",
"schedule": 1800,
}
}
celery_app.conf.timezone = "UTC"
+14 -1
View File
@@ -6,7 +6,8 @@ from itertools import chain
from celery import shared_task
from celery import Task
from app.utils import *
from app.utils.utils import *
from app.utils.yd_utils import get_token, get_activity_info
@shared_task(ignore_result=False)
@@ -88,3 +89,15 @@ def process_message_callback(
# 回复群组的消息
content = f'{{"text": "反馈的问题已经记录到多维表格, 稍后有小伙伴跟进"}}'
send_group_message(client, message_id, content)
@shared_task()
def sync_xbot_activity_info():
xbot_username = os.environ["XBOT_USERNAME"]
xbot_password = os.environ["XBOT_PASSWORD"]
token = get_token(xbot_username, xbot_password)
office_activity_uuids: list = get_activity_info(token)
for item in office_activity_uuids:
uuid = item.get("uuid")
package_viewName = item.get("packageViewName")
print(uuid, package_viewName)
View File
File renamed without changes.
+100
View File
@@ -0,0 +1,100 @@
import os
import requests
import dotenv
from urllib import parse
def get_token(username, password):
"""
利用网页端获取 token
:param username: 用户名
:param password: 密码
:return: token
"""
url = "https://api.winrobot360.com/oauth/token"
data = {
"username": username,
"password": password,
"grant_type": "password",
"scope": "all",
}
payload = parse.urlencode(data)
headers = {
"accept": "application/json",
"authorization": "Basic Y29uc29sZTpzVVdpeTZzTmlYZDBlNUxo",
"content-type": "application/x-www-form-urlencoded;charset=UTF-8",
}
response = requests.request("POST", url, headers=headers, data=payload).json()
if response.get("success") == "false":
raise ValueError(response.get("msg"))
return response.get("access_token")
def get_activity_info(token, page=1, size=200):
"""
获取活动信息列表
:param token: 认证用的 token
:param page: 分页页码,默认为 1
:param size: 分页大小,默认为 10
:return: 所有页的数据列表
"""
url = "https://api.winrobot360.com/api/v1/robot/activity/package/list"
all_data = []
while True:
payload = {
"source": "market",
"page": page,
"size": size,
"groupInfoUuid": "22222222-2222-2222-2222-222222222222",
"marketUiTag": "",
"uiaType": "pc",
"order": "desc",
}
headers = {
"Authorization": f"bearer {token}",
"Accept": "application/json",
"Accept-Encoding": "json",
}
response = requests.get(url, headers=headers, params=payload)
response_json = response.json()
if not response.ok or not response_json.get("success"):
raise ValueError(response_json.get("msg"))
data = response_json.get("data")
all_data.extend(data)
if not data or len(data) < size:
break
page += 1
return all_data
def get_activity_detail(token, package_name, package_version):
"""
获取自定义指令的相关信息
:param token: token
:param sdk: 自定义指令
:return: package_name, package_url
"""
url = f"https://api.winrobot360.com/api/v1/robot/use/activity/package/detail?packageName={package_name}&version={package_version}"
payload = {}
headers = {
"Authorization": f"bearer {token}",
"Accept": "application/json",
"Accept-Encoding": "json",
}
response = requests.request("GET", url, headers=headers, data=payload)
return response.json().get("data")
if __name__ == "__main__":
dotenv.load_dotenv()
xbot_username = os.environ["XBOT_USERNAME"]
xbot_password = os.environ["XBOT_PASSWORD"]
token = get_token(xbot_username, xbot_password)
office_activity_uuids: list = get_activity_info(token)
for item in office_activity_uuids:
print(item)
+36 -1
View File
@@ -15,11 +15,20 @@ services:
- TABLE_ID=${TABLE_ID}
- BROKER_URL=${BROKER_URL}
- RESULT_BACKEND=${RESULT_BACKEND}
- XBOT_USERNAME=${XBOT_USERNAME}
- XBOT_PASSWORD=${XBOT_PASSWORD}
healthcheck:
test: ["CMD", "curl", "-f", "http://office-xbot-app/index"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
start_interval: 5s
office-xbot-celery:
container_name: office-xbot-celery
image: "${APP_IMAGE}"
command: "celery -A app.make_celery worker --loglevel INFO"
command: "celery -A app.make_celery worker -B --loglevel INFO"
environment:
- APP_ID=${APP_ID}
- APP_SECRET=${APP_SECRET}
@@ -29,12 +38,38 @@ services:
- TABLE_ID=${TABLE_ID}
- BROKER_URL=${BROKER_URL}
- RESULT_BACKEND=${RESULT_BACKEND}
- XBOT_USERNAME=${XBOT_USERNAME}
- XBOT_PASSWORD=${XBOT_PASSWORD}
healthcheck:
test: ["CMD", "celery", "inspect", "ping"]
interval: 10s
timeout: 10s
retries: 3
depends_on:
- office-xbot-redis
office-xbot-redis:
container_name: office-xbot-redis
image: redis:latest
ports:
- "6379:6379"
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 10s
retries: 3
office-xbot-flower:
container_name: office-xbot-flower
image: "${APP_IMAGE}"
command: "celery --broker=${BROKER_URL} flower --loglevel INFO"
ports:
- "5555:5555"
depends_on:
office-xbot-celery:
condition: service_healthy
restart: true
networks:
office-xbot-network:
Generated
+89 -2
View File
@@ -1,4 +1,4 @@
# This file is automatically @generated by Poetry 1.5.1 and should not be changed by hand.
# This file is automatically @generated by Poetry 1.5.0 and should not be changed by hand.
[[package]]
name = "amqp"
@@ -308,6 +308,38 @@ Werkzeug = ">=3.0.0"
async = ["asgiref (>=3.2)"]
dotenv = ["python-dotenv"]
[[package]]
name = "flower"
version = "2.0.1"
description = "Celery Flower"
optional = false
python-versions = ">=3.7"
files = [
{file = "flower-2.0.1-py2.py3-none-any.whl", hash = "sha256:9db2c621eeefbc844c8dd88be64aef61e84e2deb29b271e02ab2b5b9f01068e2"},
{file = "flower-2.0.1.tar.gz", hash = "sha256:5ab717b979530770c16afb48b50d2a98d23c3e9fe39851dcf6bc4d01845a02a0"},
]
[package.dependencies]
celery = ">=5.0.5"
humanize = "*"
prometheus-client = ">=0.8.0"
pytz = "*"
tornado = ">=5.0.0,<7.0.0"
[[package]]
name = "humanize"
version = "4.9.0"
description = "Python humanize utilities"
optional = false
python-versions = ">=3.8"
files = [
{file = "humanize-4.9.0-py3-none-any.whl", hash = "sha256:ce284a76d5b1377fd8836733b983bfb0b76f1aa1c090de2566fcf008d7f6ab16"},
{file = "humanize-4.9.0.tar.gz", hash = "sha256:582a265c931c683a7e9b8ed9559089dea7edcf6cc95be39a3cbc2c5d5ac2bcfa"},
]
[package.extras]
tests = ["freezegun", "pytest", "pytest-cov"]
[[package]]
name = "idna"
version = "3.6"
@@ -425,6 +457,16 @@ files = [
{file = "MarkupSafe-2.1.3-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:5bbe06f8eeafd38e5d0a4894ffec89378b6c6a625ff57e3028921f8ff59318ac"},
{file = "MarkupSafe-2.1.3-cp311-cp311-win32.whl", hash = "sha256:dd15ff04ffd7e05ffcb7fe79f1b98041b8ea30ae9234aed2a9168b5797c3effb"},
{file = "MarkupSafe-2.1.3-cp311-cp311-win_amd64.whl", hash = "sha256:134da1eca9ec0ae528110ccc9e48041e0828d79f24121a1a146161103c76e686"},
{file = "MarkupSafe-2.1.3-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:f698de3fd0c4e6972b92290a45bd9b1536bffe8c6759c62471efaa8acb4c37bc"},
{file = "MarkupSafe-2.1.3-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:aa57bd9cf8ae831a362185ee444e15a93ecb2e344c8e52e4d721ea3ab6ef1823"},
{file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ffcc3f7c66b5f5b7931a5aa68fc9cecc51e685ef90282f4a82f0f5e9b704ad11"},
{file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:47d4f1c5f80fc62fdd7777d0d40a2e9dda0a05883ab11374334f6c4de38adffd"},
{file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:1f67c7038d560d92149c060157d623c542173016c4babc0c1913cca0564b9939"},
{file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:9aad3c1755095ce347e26488214ef77e0485a3c34a50c5a5e2471dff60b9dd9c"},
{file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:14ff806850827afd6b07a5f32bd917fb7f45b046ba40c57abdb636674a8b559c"},
{file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8f9293864fe09b8149f0cc42ce56e3f0e54de883a9de90cd427f191c346eb2e1"},
{file = "MarkupSafe-2.1.3-cp312-cp312-win32.whl", hash = "sha256:715d3562f79d540f251b99ebd6d8baa547118974341db04f5ad06d5ea3eb8007"},
{file = "MarkupSafe-2.1.3-cp312-cp312-win_amd64.whl", hash = "sha256:1b8dd8c3fd14349433c79fa8abeb573a55fc0fdd769133baac1f5e07abf54aeb"},
{file = "MarkupSafe-2.1.3-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:8e254ae696c88d98da6555f5ace2279cf7cd5b3f52be2b5cf97feafe883b58d2"},
{file = "MarkupSafe-2.1.3-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:cb0932dc158471523c9637e807d9bfb93e06a95cbf010f1a38b98623b929ef2b"},
{file = "MarkupSafe-2.1.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9402b03f1a1b4dc4c19845e5c749e3ab82d5078d16a2a4c2cd2df62d57bb0707"},
@@ -457,6 +499,20 @@ files = [
{file = "MarkupSafe-2.1.3.tar.gz", hash = "sha256:af598ed32d6ae86f1b747b82783958b1a4ab8f617b06fe68795c7f026abbdcad"},
]
[[package]]
name = "prometheus-client"
version = "0.19.0"
description = "Python client for the Prometheus monitoring system."
optional = false
python-versions = ">=3.8"
files = [
{file = "prometheus_client-0.19.0-py3-none-any.whl", hash = "sha256:c88b1e6ecf6b41cd8fb5731c7ae919bf66df6ec6fafa555cd6c0e16ca169ae92"},
{file = "prometheus_client-0.19.0.tar.gz", hash = "sha256:4585b0d1223148c27a225b10dbec5ae9bc4c81a99a3fa80774fa6209935324e1"},
]
[package.extras]
twisted = ["twisted"]
[[package]]
name = "prompt-toolkit"
version = "3.0.43"
@@ -540,6 +596,17 @@ files = [
[package.extras]
cli = ["click (>=5.0)"]
[[package]]
name = "pytz"
version = "2024.1"
description = "World timezone definitions, modern and historical"
optional = false
python-versions = "*"
files = [
{file = "pytz-2024.1-py2.py3-none-any.whl", hash = "sha256:328171f4e3623139da4983451950b28e95ac706e13f3f2630a879749e7a8b319"},
{file = "pytz-2024.1.tar.gz", hash = "sha256:2a29735ea9c18baf14b448846bde5a48030ed267578472d8955cd0e7443a9812"},
]
[[package]]
name = "redis"
version = "5.0.1"
@@ -604,6 +671,26 @@ files = [
{file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"},
]
[[package]]
name = "tornado"
version = "6.4"
description = "Tornado is a Python web framework and asynchronous networking library, originally developed at FriendFeed."
optional = false
python-versions = ">= 3.8"
files = [
{file = "tornado-6.4-cp38-abi3-macosx_10_9_universal2.whl", hash = "sha256:02ccefc7d8211e5a7f9e8bc3f9e5b0ad6262ba2fbb683a6443ecc804e5224ce0"},
{file = "tornado-6.4-cp38-abi3-macosx_10_9_x86_64.whl", hash = "sha256:27787de946a9cffd63ce5814c33f734c627a87072ec7eed71f7fc4417bb16263"},
{file = "tornado-6.4-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f7894c581ecdcf91666a0912f18ce5e757213999e183ebfc2c3fdbf4d5bd764e"},
{file = "tornado-6.4-cp38-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:e43bc2e5370a6a8e413e1e1cd0c91bedc5bd62a74a532371042a18ef19e10579"},
{file = "tornado-6.4-cp38-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f0251554cdd50b4b44362f73ad5ba7126fc5b2c2895cc62b14a1c2d7ea32f212"},
{file = "tornado-6.4-cp38-abi3-musllinux_1_1_aarch64.whl", hash = "sha256:fd03192e287fbd0899dd8f81c6fb9cbbc69194d2074b38f384cb6fa72b80e9c2"},
{file = "tornado-6.4-cp38-abi3-musllinux_1_1_i686.whl", hash = "sha256:88b84956273fbd73420e6d4b8d5ccbe913c65d31351b4c004ae362eba06e1f78"},
{file = "tornado-6.4-cp38-abi3-musllinux_1_1_x86_64.whl", hash = "sha256:71ddfc23a0e03ef2df1c1397d859868d158c8276a0603b96cf86892bff58149f"},
{file = "tornado-6.4-cp38-abi3-win32.whl", hash = "sha256:6f8a6c77900f5ae93d8b4ae1196472d0ccc2775cc1dfdc9e7727889145c45052"},
{file = "tornado-6.4-cp38-abi3-win_amd64.whl", hash = "sha256:10aeaa8006333433da48dec9fe417877f8bcc21f48dda8d661ae79da357b2a63"},
{file = "tornado-6.4.tar.gz", hash = "sha256:72291fa6e6bc84e626589f1c29d90a5a6d593ef5ae68052ee2ef000dfd273dee"},
]
[[package]]
name = "tzdata"
version = "2023.4"
@@ -673,4 +760,4 @@ watchdog = ["watchdog (>=2.3)"]
[metadata]
lock-version = "2.0"
python-versions = "^3.10"
content-hash = "52a8819fa1ada0e76b575b691fdc306fdca4671d11b3aa118a6f227a1535cf64"
content-hash = "2e056586ede929b134afce8a0b28ce5189b1ea298f1682472fdfde6e3e88cb79"
+2
View File
@@ -13,6 +13,8 @@ python-dotenv = "^1.0.0"
lark-oapi = "^1.0.28"
celery = "^5.3.6"
redis = "^5.0.1"
requests = "^2.31.0"
flower = "^2.0.1"
[build-system]