python - Using the twitter API in Django -
i've been using python twitter tools automate stuff (automatically add tweets favourite etc.). useful, thought i'd turn open-source program called "mojito". problem i'm not expert in python/django, , i'm stuck here:
this form used collect 2 variables: mkeyword (the keyword on twitter) , mcount (how many tweets):
from django import forms class getvariables(forms.form): mkeyword = forms.charfield(max_length=100) mcount = forms.integerfield(max_value=100, min_value=1)
i have "mojitoform" function uses python-twitter-tools' auto_fav function. both below:
def mojitoform (request): try: form = getvariables(request.post) if form.is_valid(): mkeyword = form.cleaned_data['mkeyword'] mcount = form.cleaned_data['mcount'] success = true tweets = auto_fav( mkeyword, mcount)['text'] except: notloggedin = true return render (request, '../templates/dashboard.html', locals())
this "auto_fav()" , "search_tweets()" function:
def auto_fav(q, count=100, result_type="recent"): """ favorites tweets match phrase (hashtag, word, etc.) """ result = search_tweets(q, count, result_type) tweet in result["statuses"]: try: # don't favorite own tweets if tweet["user"]["screen_name"] == twitter_handle: continue result = t.favorites.create(_id=tweet["id"]) print("favorited: %s" % (result["text"].encode("utf-8"))) # when have favorited tweet, error thrown except twitterhttperror e: print("error: %s" % (str(e))) def search_tweets(q, count=100, result_type="recent"): return t.search.tweets(q=q, result_type=result_type, count=count)
my problem is: when run mojitoform, doesn't take account "mcount" variable. 1 tweet favourited everytime. weird because auto_fav() script works fine when run on shell, on django it'll ignore mcount variable.. i've twisted every way around, i'm lost.
Comments
Post a Comment