Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
evsuits
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
OpsTeam
evsuits
Commits
b0af1fc8
提交
b0af1fc8
authored
6月 03, 2020
作者:
blu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
dingbot
上级
fcbb4ee4
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
75 行增加
和
8 行删除
+75
-8
notify.py
opencv-motion-detect/dingbot/notify.py
+74
-6
updater.py
opencv-motion-detect/updater.py
+1
-2
没有找到文件。
opencv-motion-detect/dingbot/notify.py
浏览文件 @
b0af1fc8
...
...
@@ -6,13 +6,27 @@ import base64
import
urllib.parse
import
requests
import
os
,
json
import
datetime
from
database
import
db_session
from
models
import
Terminal
import
paho.mqtt.client
as
mqtt
import
logging
import
pdb
,
traceback
,
sys
,
socket
logger
=
logging
.
getLogger
(
__file__
)
logger
.
setLevel
(
logging
.
INFO
)
ch
=
logging
.
StreamHandler
()
ch
.
setFormatter
(
logging
.
Formatter
((
'[
%(asctime)
s][ota][
%(lineno)
d][
%(levelname)
s]
%(message)
s'
)))
logger
.
addHandler
(
ch
)
SECRET
=
os
.
getenv
(
'SECRET'
,
'SEC3219d0b06510f560349170c4d571b8fd10a5dfa616d4f9ef5494f63add766d65'
)
# SECf8938911f24df40a0b86b711179fa7fc8ba88eb5d82e4e9f07bc03b5f29e8f6a
TOKEN
=
os
.
getenv
(
"TOKEN"
,
'3bb560ac5a3ee5943aeeb21c452162a3f23c44d675b42935c56f6685aceb4153'
)
#'3d72d0b376f8061b9cae44c1d1048221bc19e245a631ef31fa195f89fca9215d')
API_ADDR
=
os
.
getenv
(
'API'
,
'https://oapi.dingtalk.com/robot/send'
)
API_TPL
=
API_ADDR
+
"?access_token={}×tamp={}&sign={}"
MQTT_HOST
=
'evcloudsvc.ilabservice.cloud'
MQTT_PORT
=
11883
MQTT_USER
=
'admin'
MQTT_PASSWORD
=
'vJ3zHqWrHbrqxVMT'
app
=
Flask
(
__name__
,
static_url_path
=
''
,
...
...
@@ -21,6 +35,7 @@ app = Flask(__name__,
class
DingBot
:
secret
=
None
token
=
None
client
=
None
def
__init__
(
self
,
token
,
secret
):
self
.
secret
=
secret
self
.
token
=
token
...
...
@@ -41,10 +56,63 @@ class DingBot:
'text'
:
text
}}
r
=
requests
.
post
(
url
,
json
=
body
)
print
(
r
.
status_code
,
r
.
text
)
logger
.
info
(
"{}, {}"
.
format
(
r
.
status_code
,
r
.
text
)
)
def
destroy
(
self
):
pass
# The callback for when the client receives a CONNACK response from the server.
@staticmethod
def
on_connect
(
client
,
userdata
,
flags
,
rc
):
now
=
datetime
.
datetime
.
now
()
logger
.
info
(
"Connected with result code "
+
str
(
rc
))
topic
=
'evsuits/report/evcloudsvc'
client
.
subscribe
(
topic
,
qos
=
1
)
logger
.
info
(
'subscribed to {}'
.
format
(
topic
))
# The callback for when a PUBLISH message is received from the server.
@staticmethod
def
on_message
(
client
,
userdata
,
msg
):
payload
=
msg
.
payload
.
decode
(
'utf-8'
)
logger
.
info
(
msg
.
topic
+
" "
+
payload
)
if
userdata
:
try
:
jd
=
json
.
loads
(
payload
)
userdata
.
handle
(
jd
)
except
Exception
as
e
:
logger
.
error
(
'exception in process message: {}'
.
format
(
e
))
#extype, value, tb = sys.exc_info()
# traceback.print_exc()
# pdb.post_mortem(tb)
@staticmethod
def
on_disconnect
(
client
,
userdata
,
rc
):
logger
.
info
(
"disconnected"
)
def
handle
(
self
,
jd
):
self
.
send_msg
(
'alarm'
,
json
.
dumps
(
jd
))
def
__init__
(
self
,
token
,
secret
,
host
=
MQTT_HOST
,
port
=
MQTT_PORT
):
'''
Parameters
'''
self
.
host
=
host
self
.
port
=
port
self
.
token
=
token
self
.
secret
=
secret
try
:
self
.
client
=
mqtt
.
Client
(
"evb-dingbot"
,
userdata
=
self
)
if
MQTT_USER
and
MQTT_PASSWORD
:
self
.
client
.
username_pw_set
(
username
=
MQTT_USER
,
password
=
MQTT_PASSWORD
)
self
.
client
.
on_connect
=
DingBot
.
on_connect
self
.
client
.
on_message
=
DingBot
.
on_message
self
.
client
.
connect_async
(
self
.
host
,
self
.
port
,
30
)
self
.
client
.
loop_start
()
except
Exception
as
e
:
logger
.
error
(
'exception in init:'
,
e
)
extype
,
value
,
tb
=
sys
.
exc_info
()
traceback
.
print_exc
()
pdb
.
post_mortem
(
tb
)
@app.teardown_appcontext
def
shutdown_session
(
exception
=
None
):
db_session
.
remove
()
...
...
@@ -53,13 +121,13 @@ DINGBOT = DingBot(TOKEN, SECRET)
@app.route
(
'/'
)
def
index
():
ret
=
'ok'
name
=
request
.
args
.
get
(
"name"
,
"World"
)
DINGBOT
.
send_msg
(
'test'
,
'this is a test'
)
term
=
Terminal
.
query
.
filter
(
Terminal
.
sn
==
'SNaaaaaa'
)
.
first
()
ret
=
'ok'
if
term
:
ret
=
term
.
sn
print
(
term
)
# term = Terminal.query.filter(Terminal.sn == 'SNaaaaaa').first()
# if term:
# ret = term.sn
# logger.info(term)
return
ret
@app.route
(
'/addterminal'
,
methods
=
[
'POST'
])
def
add_terminal
():
...
...
opencv-motion-detect/updater.py
浏览文件 @
b0af1fc8
...
...
@@ -142,8 +142,6 @@ class OTAClient:
self
.
client
.
username_pw_set
(
username
=
self
.
username
,
password
=
self
.
password
)
self
.
client
.
on_connect
=
self
.
on_connect
self
.
client
.
on_message
=
self
.
on_message
#self.client.loop_start()
#self.client.connect_async(self.host, self.port, 30)
def
run
(
self
):
retry
=
0
...
...
@@ -164,6 +162,7 @@ class OTAClient:
logger
.
error
(
"updater exiting since network failure"
)
def
run_nonblock
(
self
):
self
.
client
.
connect_async
(
self
.
host
,
self
.
port
,
30
)
self
.
client
.
loop_start
()
def
download
(
self
,
url
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论