From: Charles Connell Date: Fri, 16 May 2014 14:41:52 +0000 (-0400) Subject: Make management commands for periodic tasks X-Git-Tag: release-20150131~49 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=03aaf70a1fcc990688037e76af93f30b824abbec;p=oweals%2Fkarmaworld.git Make management commands for periodic tasks --- diff --git a/karmaworld/apps/notes/management/commands/tweet_note.py b/karmaworld/apps/notes/management/commands/tweet_note.py new file mode 100644 index 0000000..6b42455 --- /dev/null +++ b/karmaworld/apps/notes/management/commands/tweet_note.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python +# -*- coding:utf8 -*- +# Copyright (C) 2014 FinalsClub Foundation +from django.core.management import BaseCommand +from karmaworld.apps.notes.tasks import tweet_note + + +class Command(BaseCommand): + """ Tweet about a note that has recently been uploaded """ + args = 'none' + help = "Send one tweet about a newly uploaded note." + + def handle(self, *args, **kwargs): + tweet_note() diff --git a/karmaworld/apps/quizzes/management/__init__.py b/karmaworld/apps/quizzes/management/__init__.py index e69de29..8be6577 100644 --- a/karmaworld/apps/quizzes/management/__init__.py +++ b/karmaworld/apps/quizzes/management/__init__.py @@ -0,0 +1 @@ +__author__ = 'charles' diff --git a/karmaworld/apps/quizzes/management/commands/__init__.py b/karmaworld/apps/quizzes/management/commands/__init__.py index e69de29..8be6577 100644 --- a/karmaworld/apps/quizzes/management/commands/__init__.py +++ b/karmaworld/apps/quizzes/management/commands/__init__.py @@ -0,0 +1 @@ +__author__ = 'charles' diff --git a/karmaworld/apps/quizzes/management/commands/get_mturk_results.py b/karmaworld/apps/quizzes/management/commands/get_mturk_results.py new file mode 100644 index 0000000..02fa95b --- /dev/null +++ b/karmaworld/apps/quizzes/management/commands/get_mturk_results.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python +# -*- coding:utf8 -*- +# Copyright (C) 2014 FinalsClub Foundation +from django.core.management import BaseCommand +from karmaworld.apps.quizzes.tasks import get_extract_keywords_results + + +class Command(BaseCommand): + """ Download results from Mechanical Turk """ + args = 'none' + help = "Download results from Mechanical Turk." + + def handle(self, *args, **kwargs): + get_extract_keywords_results() diff --git a/karmaworld/apps/quizzes/management/commands/nltk_download.py b/karmaworld/apps/quizzes/management/commands/nltk_download.py deleted file mode 100644 index 925ed65..0000000 --- a/karmaworld/apps/quizzes/management/commands/nltk_download.py +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env python2 -from django.core.management import BaseCommand - -import nltk - - -class Command(BaseCommand): - help = "Download the data needed for the Natural Language Toolkit to find note keywords." - - def handle(self, *args, **kwargs): - nltk.download('punkt') - nltk.download('maxent_treebank_pos_tagger') - nltk.download('stopwords') - diff --git a/karmaworld/apps/quizzes/tasks.py b/karmaworld/apps/quizzes/tasks.py index 2fea3de..16d3ac6 100644 --- a/karmaworld/apps/quizzes/tasks.py +++ b/karmaworld/apps/quizzes/tasks.py @@ -118,16 +118,17 @@ def submit_extract_keywords_hit(note): def get_extract_keywords_results(): try: - from karmaworld.secret.mturk import AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, MTURK_HOST + MTURK_HOST = os.environ['MTURK_HOST'] except ImportError: logger.warn('Could not find Mechanical Turk secrets, not running get_extract_keywords_results') return - connection = MTurkConnection(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, + connection = MTurkConnection(settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_ACCESS_KEY, host=MTURK_HOST) reviewable_hits = connection.get_reviewable_hits(page_size=100) for hit in reviewable_hits: + logger.info('Found HIT {0}'.format(hit.HITId)) try: note_id = connection.get_hit(hit.HITId)[0].RequesterAnnotation note_id = int(note_id)