Toggle navigation
Toggle navigation
This project
Loading...
Sign in
장연우
/
WELLO
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
soonmyeong2
2019-11-17 20:28:08 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
009d2190755ee9d6d2bd38234fc1c9d35ea8f303
009d2190
1 parent
1a1a0fb3
make push alarm system by python file
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
12 deletions
push_messaging.py
push_messaging.py
View file @
009d219
from
firebase_admin
import
messaging
from
firebase_admin
import
credentials
from
firebase_admin
import
datetime
from
firebase_admin
import
db
import
firebase_admin
import
json
import
re
cred
=
credentials
.
Certificate
(
'wello_firebase_SDKKey.json'
)
default_app
=
firebase_admin
.
initialize_app
(
cred
)
firebase_admin
.
initialize_app
(
cred
,
{
'databaseURL'
:
'https://wello-topic.firebaseio.com/'
})
ref
=
db
.
reference
()
topics
=
list
(
ref
.
get
())
pre_topic
=
list
()
def
send_to_topic
():
# [START send_to_topic]
# The topic name can be optionally prefixed with "/topics/".
topic
=
'c1_1'
# See documentation on defining a message payload.
def
send_to_topic
(
policy
,
topic
):
message
=
messaging
.
Message
(
title
=
'wef'
,
android
=
messaging
.
AndroidConfig
(
ttl
=
datetime
.
timedelta
(
seconds
=
3600
),
priority
=
'normal'
,
notification
=
messaging
.
AndroidNotification
(
title
=
'새 정책 알람'
,
body
=
policy
,
icon
=
'@drawable/mini'
,
color
=
'#29ABE2'
,
sound
=
'default'
),
),
data
=
{
'score'
:
'850'
,
'time'
:
'2:45'
,
},
webpush
=
messaging
.
WebpushConfig
(
notification
=
messaging
.
WebpushNotification
(
title
=
'웹 알림'
,
body
=
'TEST'
,
icon
=
''
,
),
),
topic
=
topic
,
)
# Send a message to the devices subscribed to the provided topic.
response
=
messaging
.
send
(
message
)
# Response is a message ID string.
print
(
'Successfully sent message:'
,
response
)
send_to_topic
()
for
topic
in
topics
:
categorys
=
re
.
findall
(
'c[0-9]+[_][0-9]+'
,
topic
)
for
i
in
range
(
len
(
categorys
)
-
1
,
-
1
,
-
1
):
if
'1'
==
categorys
[
i
]
.
split
(
'_'
)[
-
1
]:
categorys
.
pop
(
i
)
pre_topic
.
append
(
categorys
)
print
(
'new policy category : '
,
end
=
''
)
policy
=
input
()
policy_category
=
re
.
findall
(
'c[0-9]+[_][0-9]+'
,
policy
)
policy_category_list
=
re
.
findall
(
'c[0-9]+'
,
policy
)
push_index
=
list
()
flag
=
True
for
i
,
categorys
in
enumerate
(
pre_topic
):
for
category
in
categorys
:
if
category
.
split
(
'_'
)[
0
]
in
policy_category_list
:
if
category
not
in
policy_category
:
flag
=
False
break
if
flag
:
push_index
.
append
(
i
)
flag
=
True
for
push
in
push_index
:
send_to_topic
(
'[가정복지부] 기성이를 보유하신 가정에 지원금을 드립니다.'
,
topics
[
push
])
...
...
Please
register
or
login
to post a comment