1
1
import os
2
2
from pathlib import Path
3
3
4
+ import firebase_admin
4
5
from celery import Celery
5
6
from django .conf import settings
7
+ from firebase_admin import credentials , messaging
6
8
7
9
from go_capture .sgf .process_image import process_image
8
10
20
22
# Load task modules from all registered Django apps.
21
23
app .autodiscover_tasks ()
22
24
25
+ cred = credentials .Certificate (settings .FIREBASE_CREDENTIALS_FILE )
26
+ firebase_admin .initialize_app (cred )
27
+
23
28
24
29
@app .task (bind = True )
25
30
def debug_task (self ):
@@ -31,6 +36,21 @@ def process_image_task(image_filename, fcm_token):
31
36
print (f'token: { fcm_token } ' )
32
37
sgf_filename = f'{ Path (image_filename ).stem } .sgf'
33
38
sgf_path = settings .SGF_DIR / sgf_filename
39
+ print (f'Processing { image_filename } ' )
34
40
with open (image_filename , 'rb' ) as image_file :
35
41
with open (sgf_path , 'w' ) as sgf_file :
36
42
process_image (image_file , sgf_file )
43
+
44
+ # See documentation on defining a message payload.
45
+ message = messaging .Message (
46
+ data = {
47
+ 'sgf_file' : str (sgf_path ),
48
+ },
49
+ token = fcm_token ,
50
+ )
51
+
52
+ # Send a message to the device corresponding to the provided
53
+ # registration token.
54
+ response = messaging .send (message )
55
+ # Response is a message ID string.
56
+ print ('Successfully sent message:' , response )
0 commit comments