Skip to content

Commit 94d5032

Browse files
authored
Merge pull request #47 from codeguru42/46-sgf-files
46 sgf files
2 parents 48bc9a2 + ccf9b45 commit 94d5032

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

go_capture/settings.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,14 @@
124124

125125
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
126126

127-
IMAGES_DIR = BASE_DIR / 'images'
127+
MEDIA_URL = 'media/'
128+
MEDIA_ROOT = BASE_DIR / 'media'
129+
MEDIA_ROOT.mkdir(exist_ok=True)
130+
131+
IMAGES_DIR = MEDIA_ROOT / 'images'
128132
IMAGES_DIR.mkdir(exist_ok=True)
129133

130-
SGF_DIR = BASE_DIR / 'sgf'
134+
SGF_DIR = MEDIA_ROOT / 'sgf'
131135
SGF_DIR.mkdir(exist_ok=True)
132136

133137
FIREBASE_CREDENTIALS_FILE = BASE_DIR / env.str('FIREBASE_CREDENTIALS_FILE')

go_capture/tasks.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import io
12
import os
2-
from pathlib import Path
33

44
import firebase_admin
55
from celery import Celery
@@ -34,17 +34,17 @@ def debug_task(self):
3434
@app.task
3535
def process_image_task(image_filename, fcm_token):
3636
print(f'token: {fcm_token}')
37-
sgf_filename = f'{Path(image_filename).stem}.sgf'
38-
sgf_path = settings.SGF_DIR / sgf_filename
3937
print(f'Processing {image_filename}')
4038
with open(image_filename, 'rb') as image_file:
41-
with open(sgf_path, 'w') as sgf_file:
42-
process_image(image_file, sgf_file)
39+
sgf_buffer = io.StringIO()
40+
process_image(image_file, sgf_buffer)
4341

44-
# See documentation on defining a message payload.
42+
sgf_buffer.seek(0)
43+
sgf_data = sgf_buffer.read()
44+
print(sgf_data)
4545
message = messaging.Message(
4646
data={
47-
'sgf_file': str(sgf_path),
47+
'sgf': sgf_data,
4848
},
4949
token=fcm_token,
5050
)

go_capture/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def capture_async(request):
3131
fcm_token = request.POST['fcm_registration_token']
3232
print(f'token: {fcm_token}')
3333
filename = Path(image_file.name)
34+
print(filename)
3435
output_path = settings.IMAGES_DIR / filename
3536
with output_path.open('wb') as output_file:
3637
output_file.write(image_file.read())

0 commit comments

Comments
 (0)