Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jpush-api-python-client
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
jpush-api-python-client
Commits
25300fa5
Commit
25300fa5
authored
May 05, 2016
by
fendouai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add customize of logging level
parent
6612ae14
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
18 deletions
+32
-18
example_all.py
examples/push/example_all.py
+10
-3
core.py
jpush/core.py
+22
-15
No files found.
examples/push/example_all.py
View file @
25300fa5
...
@@ -6,15 +6,21 @@ from jpush import common
...
@@ -6,15 +6,21 @@ from jpush import common
_jpush
=
jpush
.
JPush
(
app_key
,
master_secret
)
_jpush
=
jpush
.
JPush
(
app_key
,
master_secret
)
push
=
_jpush
.
create_push
()
push
=
_jpush
.
create_push
()
# the default logging level is WARNING,if you set the logging level to "DEBUG",the it will show the debug logging
_jpush
.
set_logging
(
"DEBUG"
)
push
.
audience
=
jpush
.
all_
push
.
audience
=
jpush
.
all_
push
.
notification
=
jpush
.
notification
(
alert
=
"hello python jpush api"
)
push
.
notification
=
jpush
.
notification
(
alert
=
"hello python jpush api"
)
push
.
platform
=
jpush
.
all_
push
.
platform
=
jpush
.
all_
core
.
logger
.
debug
(
'logger debug message test'
)
try
:
try
:
response
=
push
.
send
()
response
=
push
.
send
()
except
common
.
Unauthorized
:
except
common
.
Unauthorized
:
raise
common
.
Unauthorized
(
"Unauthorized"
)
raise
common
.
Unauthorized
(
"Unauthorized"
)
except
common
.
APIConnectionException
:
except
common
.
APIConnectionException
:
raise
common
.
APIConnectionException
(
"conn"
)
raise
common
.
APIConnectionException
(
"conn"
)
except
common
.
JPushFailure
:
print
"JPushFailure"
except
:
print
"Exception"
\ No newline at end of file
jpush/core.py
View file @
25300fa5
...
@@ -11,11 +11,6 @@ from .schedule import Schedule
...
@@ -11,11 +11,6 @@ from .schedule import Schedule
logger
=
logging
.
getLogger
(
'jpush'
)
logger
=
logging
.
getLogger
(
'jpush'
)
logging
.
basicConfig
(
level
=
logging
.
DEBUG
,
format
=
'
%(asctime)
s
%(filename)
s[line:
%(lineno)
d]
%(levelname)
s
%(message)
s'
,
datefmt
=
'
%
a,
%
d
%
b
%
Y
%
H:
%
M:
%
S'
,
filename
=
'jpush.log'
,
filemode
=
'a'
)
class
JPush
(
object
):
class
JPush
(
object
):
...
@@ -34,9 +29,7 @@ class JPush(object):
...
@@ -34,9 +29,7 @@ class JPush(object):
headers
[
'content-type'
]
=
'application/json;charset:utf-8'
headers
[
'content-type'
]
=
'application/json;charset:utf-8'
logger
.
debug
(
"Making
%
s request to
%
s. Headers:
\n\t
%
s
\n
Body:
\n\t
%
s"
,
logger
.
debug
(
"Making
%
s request to
%
s. Headers:
\n\t
%
s
\n
Body:
\n\t
%
s"
,
method
,
url
,
'
\n\t
'
.
join
(
method
,
url
,
'
\n\t
'
.
join
(
'
%
s:
%
s'
%
(
key
,
value
)
for
(
key
,
value
)
in
headers
.
items
()),
body
)
'
%
s:
%
s'
%
(
key
,
value
)
for
(
key
,
value
)
in
headers
.
items
()),
body
)
try
:
try
:
response
=
self
.
session
.
request
(
method
,
url
,
data
=
body
,
params
=
params
,
headers
=
headers
,
timeout
=
30
)
response
=
self
.
session
.
request
(
method
,
url
,
data
=
body
,
params
=
params
,
headers
=
headers
,
timeout
=
30
)
except
requests
.
exceptions
.
ConnectTimeout
:
except
requests
.
exceptions
.
ConnectTimeout
:
...
@@ -44,11 +37,8 @@ class JPush(object):
...
@@ -44,11 +37,8 @@ class JPush(object):
except
:
except
:
raise
common
.
APIConnectionException
(
"Connection to api.jpush.cn error."
)
raise
common
.
APIConnectionException
(
"Connection to api.jpush.cn error."
)
logger
.
debug
(
"Received
%
s response. Headers:
\n\t
%
s
\n
Body:
\n\t
%
s"
,
logger
.
debug
(
"Received
%
s response. Headers:
\n\t
%
s
\n
Body:
\n\t
%
s"
,
response
.
status_code
,
'
\n\t
'
.
join
(
response
.
status_code
,
'
\n\t
'
.
join
(
'
%
s:
%
s'
%
(
key
,
value
)
for
(
key
,
value
)
in
response
.
headers
.
items
()),
response
.
content
)
'
%
s:
%
s'
%
(
key
,
value
)
for
(
key
,
value
)
in
response
.
headers
.
items
()),
response
.
content
)
if
response
.
status_code
==
401
:
if
response
.
status_code
==
401
:
raise
common
.
Unauthorized
(
"Please check your AppKey and Master Secret"
)
raise
common
.
Unauthorized
(
"Please check your AppKey and Master Secret"
)
...
@@ -66,8 +56,25 @@ class JPush(object):
...
@@ -66,8 +56,25 @@ class JPush(object):
"JPush.push() is deprecated. See documentation on upgrading."
,
"JPush.push() is deprecated. See documentation on upgrading."
,
DeprecationWarning
)
DeprecationWarning
)
body
=
json
.
dumps
(
payload
)
body
=
json
.
dumps
(
payload
)
self
.
_request
(
'POST'
,
body
,
common
.
PUSH_URL
,
self
.
_request
(
'POST'
,
body
,
common
.
PUSH_URL
,
'application/json'
,
version
=
1
)
'application/json'
,
version
=
1
)
def
set_logging
(
self
,
level
):
level_list
=
[
"CRITICAL"
,
"ERROR"
,
"WARNING"
,
"INFO"
,
"DEBUG"
,
"NOTSET"
]
if
level
in
level_list
:
if
(
level
==
"CRITICAL"
):
logging
.
basicConfig
(
level
=
logging
.
CRITICAL
)
if
(
level
==
"ERROR"
):
logging
.
basicConfig
(
level
=
logging
.
ERROR
)
if
(
level
==
"WARNING"
):
logging
.
basicConfig
(
level
=
logging
.
WARNING
)
if
(
level
==
"INFO"
):
logging
.
basicConfig
(
level
=
logging
.
INFO
)
if
(
level
==
"DEBUG"
):
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
if
(
level
==
"NOTSET"
):
logging
.
basicConfig
(
level
=
logging
.
NOTSET
)
else
:
print
"set logging level failed ,the level is invalid."
def
create_push
(
self
):
def
create_push
(
self
):
"""Create a Push notification."""
"""Create a Push notification."""
...
...
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