From 09fe0298a864a002b927d2dd6e628cb646b1d34d Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Tue, 20 Feb 2018 12:03:30 +0300 Subject: [PATCH 1/7] LIL-16. Add django-constance[database] to req --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index fa1be26b..5e9e81b0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,3 +16,4 @@ djangorestframework==3.7.7 drf-yasg[validation]==1.4.0 django-silk==2.0.0 django-cors-headers==2.1.0 +django-constance[database]==2.1.0 \ No newline at end of file From 76da0b4371b43fb994a44cc337d365ad881b5505 Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Tue, 20 Feb 2018 15:36:17 +0300 Subject: [PATCH 2/7] LIL-266. Add celery worker service --- docker-compose.yml | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index a6d65c69..647430e4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -34,4 +34,23 @@ services: - redis links: - db - - redis \ No newline at end of file + - redis + + workers: + build: . + restart: always + volumes: + - .:/lilcity + command: bash -c "celery worker -A project -B" + environment: + - DJANGO_SETTINGS_MODULE=project.settings + - DATABASE_SERVICE_HOST=db + - REDIS_SERVICE_HOST=redis + depends_on: + - db + - redis + - web + links: + - db + - redis + - web From 265dc1ca441c30b69efcce4762f5c9c5d2c4c184 Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Tue, 20 Feb 2018 15:36:50 +0300 Subject: [PATCH 3/7] LIL-16. Add instagram api lib to req --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 5e9e81b0..e02b575a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,4 +16,5 @@ djangorestframework==3.7.7 drf-yasg[validation]==1.4.0 django-silk==2.0.0 django-cors-headers==2.1.0 -django-constance[database]==2.1.0 \ No newline at end of file +django-constance[database]==2.1.0 +InstagramAPI==1.0.2 From a2f00458b46e58ac4dd6f04de541f62d7b47eea3 Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Tue, 20 Feb 2018 15:38:10 +0300 Subject: [PATCH 4/7] LIL-266. Fix celery app --- project/celery.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/celery.py b/project/celery.py index 8cbb640c..bbc97ed5 100644 --- a/project/celery.py +++ b/project/celery.py @@ -10,7 +10,7 @@ app = Celery('project') # the configuration object to child processes. # - namespace='CELERY' means all celery-related configuration keys # should have a `CELERY_` prefix. -app.config_from_object('project.celery_settings') +app.config_from_object('project.settings', namespace='CELERY') # Load task modules from all registered Django app configs. app.autodiscover_tasks() From 45f1dcfbf3f7cf00d70b6604be7c9a71eed98642 Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Tue, 20 Feb 2018 15:39:32 +0300 Subject: [PATCH 5/7] LIL-266. Move celery settings to main settings file. --- project/celery_settings.py | 3 --- project/settings.py | 7 +++++++ 2 files changed, 7 insertions(+), 3 deletions(-) delete mode 100644 project/celery_settings.py diff --git a/project/celery_settings.py b/project/celery_settings.py deleted file mode 100644 index 8afa610e..00000000 --- a/project/celery_settings.py +++ /dev/null @@ -1,3 +0,0 @@ -broker_url = 'redis://redis:6379/0' -result_backend = 'redis://redis:6379/1' -task_serializer = 'json' diff --git a/project/settings.py b/project/settings.py index 10c5e93b..6ec6ff69 100644 --- a/project/settings.py +++ b/project/settings.py @@ -205,6 +205,13 @@ REST_FRAMEWORK = { 'PAGE_SIZE': 10, } +# Celery settings + +CELERY_BROKER_URL = 'redis://redis:6379/0' +CELERY_RESULT_BACKEND = 'redis://redis:6379/1' +CELERY_TASK_SERIALIZER = 'json' + + # CORS settings if DEBUG: From fc301cc8ace3aaabec017bf591cee797c7875949 Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Tue, 20 Feb 2018 15:41:41 +0300 Subject: [PATCH 6/7] LIL-266. Add instagram settings --- project/settings.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/project/settings.py b/project/settings.py index 6ec6ff69..93195e33 100644 --- a/project/settings.py +++ b/project/settings.py @@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/2.0/ref/settings/ """ import os +from collections import OrderedDict # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -47,6 +48,8 @@ INSTALLED_APPS = [ 'rest_framework.authtoken', 'drf_yasg', 'corsheaders', + 'constance', + 'constance.backends.database', ] + [ 'apps.auth.apps', 'apps.user', @@ -212,6 +215,22 @@ CELERY_RESULT_BACKEND = 'redis://redis:6379/1' CELERY_TASK_SERIALIZER = 'json' +# Dynamic settings + +CONSTANCE_BACKEND = 'constance.backends.database.DatabaseBackend' +CONSTANCE_CONFIG = OrderedDict(( + ('INSTAGRAM_CLIENT_LOGIN', ('', '')), + ('INSTAGRAM_CLIENT_PASSWORD', ('', '')), + ('INSTAGRAM_RESULTS_TAG', ('#lil_акварель', 'Тэг результатов работ.')), + ('INSTAGRAM_RESULTS_PATH', ('media/instagram/results/', 'Путь до результатов работ.')), +)) + +try: + from .local_settings import * +except ImportError: + pass + + # CORS settings if DEBUG: From 38cbea07488c2ba92caad6cc88ded52cd32fd23a Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Tue, 20 Feb 2018 16:53:22 +0300 Subject: [PATCH 7/7] LIL-266. Add simple task for retrieve data by hashtag. --- apps/content/tasks.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 apps/content/tasks.py diff --git a/apps/content/tasks.py b/apps/content/tasks.py new file mode 100644 index 00000000..898266bf --- /dev/null +++ b/apps/content/tasks.py @@ -0,0 +1,19 @@ +import json +from time import sleep +from project.celery import app +from constance import config +from InstagramAPI import InstagramAPI + + +@app.task +def retrieve_photos(): + instagram = InstagramAPI( + config.INSTAGRAM_CLIENT_LOGIN, + config.INSTAGRAM_CLIENT_PASSWORD, + ) + instagram.login() + sleep(1) + if instagram.isLoggedIn and instagram.getHashtagFeed(config.INSTAGRAM_RESULTS_TAG): + with open('s.json', 'w') as f: + f.write(json.dumps(instagram.LastJson)) + return instagram.LastJson