Created
April 23, 2014 08:39
-
-
Save ciaranbradley/11207319 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function, unicode_literals | |
from optparse import make_option | |
#Import DB to close | |
from django import db | |
from django.core.management.base import NoArgsCommand | |
from mezzanine.twitter.models import Query, TwitterQueryException | |
class Command(NoArgsCommand): | |
""" | |
Polls the Twitter API for tweets associated to the queries in templates. | |
""" | |
option_list = NoArgsCommand.option_list + ( | |
make_option("--force", default=False, action="store_true"), | |
) | |
def handle_noargs(self, **options): | |
queries = Query.objects.all() | |
if not options["force"]: | |
queries = queries.filter(interested=True) | |
for query in queries: | |
try: | |
query.run() | |
except TwitterQueryException as e: | |
print("Twitter query error [%s]: %s" % (query, e)) | |
#Explicitly close DB connection. | |
db.close_connection() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment