Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
lichenggang
/
tas_token_server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
0b7fa0fc
authored
Apr 01, 2020
by
lichenggang
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
digkey token失败后报警
parent
9a0d68d4
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
4 deletions
lib/apidigikey.py
utils/__init__.py
utils/robots.py
lib/apidigikey.py
View file @
0b7fa0fc
...
...
@@ -4,8 +4,9 @@ import traceback
import
redis
import
requests
from
retry
import
retry
import
token_lib
from
utils.robots
import
dd_send_msg
PLATFORM
=
"apidigikey"
LEVEL
=
"HH"
...
...
@@ -47,6 +48,7 @@ class DGTokenCrawler(token_lib.BaseTokenCrawler):
access_token
,
refresh_token
=
self
.
get_token_by_refresh_token
()
return
access_token
,
refresh_token
except
Exception
:
dd_send_msg
(
'digikey token同步失败:'
+
traceback
.
format_exc
())
self
.
logger
.
error
(
traceback
.
format_exc
())
def
get_token
(
self
):
...
...
@@ -65,6 +67,7 @@ class DGTokenCrawler(token_lib.BaseTokenCrawler):
token_json
=
resp
.
json
()
return
token_json
[
'access_token'
],
token_json
[
'refresh_token'
]
@retry
(
tries
=
3
)
def
get_token_by_refresh_token
(
self
):
refresh_token
=
self
.
_redis
.
get
(
self
.
refresh_token_key
)
.
decode
()
p_data
=
{
...
...
@@ -74,13 +77,11 @@ class DGTokenCrawler(token_lib.BaseTokenCrawler):
# 'refresh_token': 'jwki255qAu14VPDGhuJKQVPHixiAGO1D',
'grant_type'
:
'refresh_token'
}
resp
=
requests
.
post
(
p_url
,
headers
=
p_headers
,
data
=
p_data
)
resp
=
requests
.
post
(
p_url
,
headers
=
p_headers
,
data
=
p_data
,
timeout
=
(
15
,
20
)
)
token_json
=
resp
.
json
()
return
token_json
[
'access_token'
],
token_json
[
'refresh_token'
]
def
process
(
self
,
is_main
):
access_token
,
refresh_token
=
self
.
collect_token
()
print
(
access_token
)
print
(
refresh_token
)
self
.
_redis
.
set
(
self
.
token_key
,
access_token
)
self
.
_redis
.
set
(
self
.
refresh_token_key
,
refresh_token
)
utils/__init__.py
0 → 100644
View file @
0b7fa0fc
#!/usr/bin/env python
# -*- coding:utf-8 -*-
\ No newline at end of file
utils/robots.py
0 → 100644
View file @
0b7fa0fc
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import
time
import
requests
dd_robot_api
=
' https://oapi.dingtalk.com/robot/send?access_token='
tom
=
'c19beeab837f5c6e019e7fc602d470704d634ae33510f40fb0e903cde215fb24'
def
dd_send_msg
(
msg
,
robot
=
tom
):
data
=
{
"msgtype"
:
"text"
,
"text"
:
{
"content"
:
msg
}
}
requests
.
post
(
dd_robot_api
+
robot
,
json
=
data
)
time
.
sleep
(
5
)
if
__name__
==
"__main__"
:
dd_send_msg
(
'喂喂 你发的太多了!'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment