def parse_tweets(tweets): import re result = [] for tw in tweets: tweet = tw.text; #compile regexes as objects hash_regex = re.compile(r'#[0-9a-zA-Z+_]*',re.IGNORECASE) user_regex = re.compile(r'@[0-9a-zA-Z+_]*',re.IGNORECASE) #first deal with links. Any http://... string change to a proper link tweet = re.sub('http://[^ ,]*', lambda t: "%s" % (t.group(0), t.group(0)), tweet) #for all elements matching our pattern... for usr in user_regex.finditer(tweet): #for each whole match replace '@' with '' url_tweet = usr.group(0).replace('@','') #in tweet's text replace text with proper link, now without '@' tweet = tweet.replace(usr.group(0), ''+usr.group(0)+'') #do the same for hash tags for hash in hash_regex.finditer(tweet): url_hash = hash.group(0).replace('#','%23') if len ( hash.group(0) ) > 2: tweet = tweet.replace(hash.group(0), ''+hash.group(0)+''); #append each tweet to our list. Here I'm creating a dict containing tweet's text and date posts.append({'tweet': tweet, 'date': s.pub_time}) return posts
And now to show it in template :
- {% for t in tweets %}
{% for k, v in t.items %}
{% ifequal k 'summary' %}
{{ v|safe }}
{% else %}
{% ifequal k 'date' %}
{{v|timesince}} ago
{% endifequal %}
{% endifequal %}
{% endfor %}
{% endfor %}
i tried to enter this string
ReplyDeleteMinitutorial de uso de Slowloris en Windows. http://pastebin.com/AxDgn6up @AnonOps_CL @IberoAnon @Ibero_Anon @An0nChile #OpNoLeyAntiterrorismo Minitutorial de uso de Slowloris en Windows. http://pastebin.com/AxDgn6up @AnonOps_CL @IberoAnon @Ibero_Anon
But it returned something weird...
(couldnt post the result html...)
Apparently, the error was here:
title="'+usr.group(0)+'"
if i remove that part then everything else works fine :)
Any idea how to fix that issue?