Skip to content

Commit 9572786

Browse files
committed
Write SGF data to buffer
1 parent f3c2d8c commit 9572786

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

go_capture/tasks.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import io
12
import os
23
from pathlib import Path
34

45
import firebase_admin
56
from celery import Celery
67
from django.conf import settings
8+
from django.core.files import File
79
from firebase_admin import credentials, messaging
810

911
from go_capture.sgf.process_image import process_image
@@ -34,17 +36,17 @@ def debug_task(self):
3436
@app.task
3537
def process_image_task(image_filename, fcm_token):
3638
print(f'token: {fcm_token}')
37-
sgf_filename = f'{Path(image_filename).stem}.sgf'
38-
sgf_path = settings.SGF_DIR / sgf_filename
3939
print(f'Processing {image_filename}')
4040
with open(image_filename, 'rb') as image_file:
41-
with open(sgf_path, 'w') as sgf_file:
42-
process_image(image_file, sgf_file)
41+
sgf_buffer = io.StringIO()
42+
process_image(image_file, sgf_buffer)
4343

44-
# See documentation on defining a message payload.
44+
sgf_buffer.seek(0)
45+
sgf_data = sgf_buffer.read()
46+
print(sgf_data)
4547
message = messaging.Message(
4648
data={
47-
'sgf_file': str(sgf_path),
49+
'sgf': sgf_data,
4850
},
4951
token=fcm_token,
5052
)

0 commit comments

Comments
 (0)