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
94c3a9d9
Commit
94c3a9d9
authored
Apr 22, 2016
by
fendouai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Schedule and Report Api with Example
parent
b90b648b
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
200 additions
and
0 deletions
+200
-0
example_all.py
examples/push/example_all.py
+1
-0
conf.py
examples/schedule/conf.py
+2
-0
example_delete_schedule.py
examples/schedule/example_delete_schedule.py
+6
-0
example_get_schedule.py
examples/schedule/example_get_schedule.py
+6
-0
example_get_schedule_list.py
examples/schedule/example_get_schedule_list.py
+7
-0
example_post_schedule.py
examples/schedule/example_post_schedule.py
+18
-0
example_put_schedule.py
examples/schedule/example_put_schedule.py
+19
-0
__init__.py
jpush/__init__.py
+7
-0
common.py
jpush/common.py
+2
-0
core.py
jpush/core.py
+5
-0
__init__.py
jpush/schedule/__init__.py
+6
-0
core.py
jpush/schedule/core.py
+77
-0
schedulepayload.py
jpush/schedule/schedulepayload.py
+44
-0
No files found.
examples/push/example_all.py
View file @
94c3a9d9
...
@@ -6,4 +6,5 @@ push = _jpush.create_push()
...
@@ -6,4 +6,5 @@ push = _jpush.create_push()
push
.
audience
=
jpush
.
all_
push
.
audience
=
jpush
.
all_
push
.
notification
=
jpush
.
notification
(
alert
=
"Hello, world!"
)
push
.
notification
=
jpush
.
notification
(
alert
=
"Hello, world!"
)
push
.
platform
=
jpush
.
all_
push
.
platform
=
jpush
.
all_
push
.
send
()
push
.
send
()
examples/schedule/conf.py
0 → 100644
View file @
94c3a9d9
app_key
=
u'6be9204c30b9473e87bad4dc'
master_secret
=
u'9349ad7c90292a603c512e92'
examples/schedule/example_delete_schedule.py
0 → 100644
View file @
94c3a9d9
import
jpush
as
jpush
from
conf
import
app_key
,
master_secret
_jpush
=
jpush
.
JPush
(
app_key
,
master_secret
)
schedule
=
_jpush
.
create_schedule
()
schedule
.
delete_schedule
(
"e9c553d0-0850-11e6-b6d4-0021f652c102"
)
examples/schedule/example_get_schedule.py
0 → 100644
View file @
94c3a9d9
import
jpush
as
jpush
from
conf
import
app_key
,
master_secret
_jpush
=
jpush
.
JPush
(
app_key
,
master_secret
)
schedule
=
_jpush
.
create_schedule
()
schedule
.
get_schedule_by_id
(
"e9c553d0-0850-11e6-b6d4-0021f652c102"
)
examples/schedule/example_get_schedule_list.py
0 → 100644
View file @
94c3a9d9
import
jpush
as
jpush
from
conf
import
app_key
,
master_secret
_jpush
=
jpush
.
JPush
(
app_key
,
master_secret
)
schedule
=
_jpush
.
create_schedule
()
schedule
.
get_schedule_list
(
"1"
)
\ No newline at end of file
examples/schedule/example_post_schedule.py
0 → 100644
View file @
94c3a9d9
import
jpush
as
jpush
from
conf
import
app_key
,
master_secret
_jpush
=
jpush
.
JPush
(
app_key
,
master_secret
)
schedule
=
_jpush
.
create_schedule
()
push
=
_jpush
.
create_push
()
push
.
audience
=
jpush
.
all_
push
.
notification
=
jpush
.
notification
(
alert
=
"Hello, world!"
)
push
.
platform
=
jpush
.
all_
push
=
push
.
payload
trigger
=
jpush
.
schedulepayload
.
trigger
(
"2016-05-17 12:00:00"
)
schedulepayload
=
jpush
.
schedulepayload
.
schedulepayload
(
"name"
,
True
,
trigger
,
push
)
schedule
.
post_schedule
(
schedulepayload
)
examples/schedule/example_put_schedule.py
0 → 100644
View file @
94c3a9d9
import
jpush
as
jpush
from
conf
import
app_key
,
master_secret
_jpush
=
jpush
.
JPush
(
app_key
,
master_secret
)
schedule
=
_jpush
.
create_schedule
()
push
=
_jpush
.
create_push
()
push
.
audience
=
jpush
.
all_
push
.
notification
=
jpush
.
notification
(
alert
=
"Hello, world!"
)
push
.
platform
=
jpush
.
all_
push
=
push
.
payload
trigger
=
jpush
.
schedulepayload
.
trigger
(
"2016-05-17 12:00:00"
)
schedulepayload
=
jpush
.
schedulepayload
.
schedulepayload
(
"putanewname"
,
True
,
trigger
,
push
)
schedule
.
put_schedule
(
schedulepayload
,
"17349f00-0852-11e6-91b1-0021f653c902"
)
\ No newline at end of file
jpush/__init__.py
View file @
94c3a9d9
...
@@ -37,6 +37,11 @@ from .report import (
...
@@ -37,6 +37,11 @@ from .report import (
Report
,
Report
,
)
)
from
.schedule
import
(
Schedule
,
schedulepayload
,
)
__all__
=
[
__all__
=
[
JPush
,
JPush
,
JPushFailure
,
JPushFailure
,
...
@@ -63,6 +68,8 @@ __all__ = [
...
@@ -63,6 +68,8 @@ __all__ = [
device_alias
,
device_alias
,
device_regid
,
device_regid
,
Report
,
Report
,
Schedule
,
schedulepayload
,
]
]
# Silence urllib3 INFO logging by default
# Silence urllib3 INFO logging by default
...
...
jpush/common.py
View file @
94c3a9d9
...
@@ -17,6 +17,8 @@ RECEIVED_URL=REPORT_BASEURL+"v3/received?msg_ids="
...
@@ -17,6 +17,8 @@ RECEIVED_URL=REPORT_BASEURL+"v3/received?msg_ids="
MESSAGES_URL
=
REPORT_BASEURL
+
"v3/messages?msg_ids="
MESSAGES_URL
=
REPORT_BASEURL
+
"v3/messages?msg_ids="
USERS_URL
=
REPORT_BASEURL
+
"v3/users?"
USERS_URL
=
REPORT_BASEURL
+
"v3/users?"
BASE_SCHEDULEURL
=
"https://api.jpush.cn/v3/schedules/"
BASE_LISTURL
=
"https://api.jpush.cn/v3/schedules?page="
logger
=
logging
.
getLogger
(
'jpush'
)
logger
=
logging
.
getLogger
(
'jpush'
)
class
Unauthorized
(
Exception
):
class
Unauthorized
(
Exception
):
...
...
jpush/core.py
View file @
94c3a9d9
...
@@ -8,6 +8,7 @@ from . import common
...
@@ -8,6 +8,7 @@ from . import common
from
.push
import
Push
from
.push
import
Push
from
.device
import
Device
from
.device
import
Device
from
.report
import
Report
from
.report
import
Report
from
.schedule
import
Schedule
logger
=
logging
.
getLogger
(
'jpush'
)
logger
=
logging
.
getLogger
(
'jpush'
)
class
JPush
(
object
):
class
JPush
(
object
):
...
@@ -72,3 +73,7 @@ class JPush(object):
...
@@ -72,3 +73,7 @@ class JPush(object):
def
create_report
(
self
):
def
create_report
(
self
):
"""Create a Push notification."""
"""Create a Push notification."""
return
Report
(
self
)
return
Report
(
self
)
def
create_schedule
(
self
):
"""Create a Push notification."""
return
Schedule
(
self
)
jpush/schedule/__init__.py
0 → 100644
View file @
94c3a9d9
from
.core
import
Schedule
__all__
=
[
Schedule
,
]
\ No newline at end of file
jpush/schedule/core.py
0 → 100644
View file @
94c3a9d9
import
json
import
logging
from
jpush
import
common
from
schedulepayload
import
*
logger
=
logging
.
getLogger
(
'jpush'
)
class
Schedule
(
object
):
"""JPush Report API V3"""
def
__init__
(
self
,
jpush
):
self
.
_jpush
=
jpush
def
send
(
self
,
method
,
url
,
body
,
content_type
=
None
,
version
=
3
):
response
=
self
.
_jpush
.
_request
(
method
,
body
,
url
,
content_type
,
version
=
3
)
return
ScheduleResponse
(
response
)
def
post_schedule
(
self
,
schedulepayload
):
url
=
common
.
BASE_SCHEDULEURL
body
=
json
.
dumps
(
schedulepayload
)
result
=
self
.
send
(
"POST"
,
url
,
body
)
print
(
result
)
return
result
def
get_schedule_by_id
(
self
,
schedule_id
):
url
=
common
.
BASE_SCHEDULEURL
+
schedule_id
print
url
body
=
None
result
=
self
.
send
(
"GET"
,
url
,
body
)
print
(
result
)
return
result
def
get_schedule_list
(
self
,
page_id
):
if
page_id
is
not
None
:
url
=
common
.
BASE_LISTURL
+
page_id
else
:
url
=
common
.
BASE_LISTURL
print
url
body
=
None
result
=
self
.
send
(
"GET"
,
url
,
body
)
print
(
result
)
return
result
def
put_schedule
(
self
,
schedulepayload
,
schedule_id
):
url
=
common
.
BASE_SCHEDULEURL
+
schedule_id
body
=
json
.
dumps
(
schedulepayload
)
result
=
self
.
send
(
"PUT"
,
url
,
body
)
print
(
result
)
return
result
def
delete_schedule
(
self
,
schedule_id
):
url
=
common
.
BASE_SCHEDULEURL
+
schedule_id
print
url
body
=
None
result
=
self
.
send
(
"DELETE"
,
url
,
body
)
print
(
result
)
return
result
class
ScheduleResponse
(
object
):
"""Response to a successful device request send.
Right now this is a fairly simple wrapper around the json payload response,
but making it an object gives us some flexibility to add functionality
later.
"""
payload
=
None
def
__init__
(
self
,
response
):
if
0
!=
len
(
response
.
content
):
data
=
response
.
json
()
self
.
payload
=
data
elif
200
==
response
.
status_code
:
self
.
payload
=
"success"
def
__str__
(
self
):
return
"Schedule response Payload: {0}"
.
format
(
self
.
payload
)
\ No newline at end of file
jpush/schedule/schedulepayload.py
0 → 100644
View file @
94c3a9d9
import
re
from
jpush
import
push
def
schedulepayload
(
name
=
None
,
enabled
=
None
,
trigger
=
None
,
push
=
None
):
schedulepayload
=
{}
if
name
is
not
None
:
schedulepayload
[
'name'
]
=
name
if
enabled
is
not
None
:
schedulepayload
[
'enabled'
]
=
enabled
if
trigger
is
not
None
:
schedulepayload
[
'trigger'
]
=
trigger
if
push
is
not
None
:
schedulepayload
[
'push'
]
=
push
if
not
schedulepayload
:
raise
ValueError
(
"schedulepayload may not be empty"
)
return
schedulepayload
def
trigger
(
time
,
start
=
None
,
end
=
None
,
time_unit
=
None
,
frequency
=
None
,
point
=
None
):
if
(
start
==
None
and
end
==
None
and
time_unit
==
None
and
frequency
==
None
):
trigger
=
{}
single
=
{}
single
[
"time"
]
=
time
trigger
[
"single"
]
=
single
return
trigger
else
:
trigger
=
{}
periodical
=
{}
if
time
is
not
None
:
periodical
[
'time'
]
=
time
if
start
is
not
None
:
periodical
[
'start'
]
=
start
if
end
is
not
None
:
periodical
[
'end'
]
=
end
if
time_unit
is
not
None
:
periodical
[
'time_unit'
]
=
time_unit
if
frequency
is
not
None
:
periodical
[
'frequency'
]
=
frequency
if
point
is
not
None
:
periodical
[
'point'
]
=
point
trigger
[
"periodical"
]
=
periodical
return
trigger
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