Make management commands for periodic tasks
authorCharles Connell <charles@connells.org>
Fri, 16 May 2014 14:41:52 +0000 (10:41 -0400)
committerCharles Connell <charles@connells.org>
Fri, 16 May 2014 14:41:52 +0000 (10:41 -0400)
karmaworld/apps/notes/management/commands/tweet_note.py [new file with mode: 0644]
karmaworld/apps/quizzes/management/__init__.py
karmaworld/apps/quizzes/management/commands/__init__.py
karmaworld/apps/quizzes/management/commands/get_mturk_results.py [new file with mode: 0644]
karmaworld/apps/quizzes/management/commands/nltk_download.py [deleted file]
karmaworld/apps/quizzes/tasks.py

diff --git a/karmaworld/apps/notes/management/commands/tweet_note.py b/karmaworld/apps/notes/management/commands/tweet_note.py
new file mode 100644 (file)
index 0000000..6b42455
--- /dev/null
@@ -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()
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..8be65774812b9141088b806cb961ef67dc47a103 100644 (file)
@@ -0,0 +1 @@
+__author__ = 'charles'
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..8be65774812b9141088b806cb961ef67dc47a103 100644 (file)
@@ -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 (file)
index 0000000..02fa95b
--- /dev/null
@@ -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 (file)
index 925ed65..0000000
+++ /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')
-
index 2fea3dedec9556a53bcf0c7a36dcc1921e10155c..16d3ac6e7f0249081c14d10235f0f3048d42f0fe 100644 (file)
@@ -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)