[csw-devel] SF.net SVN: opencsw:[591] twitter/sweets/sweets.py
skayser at users.sourceforge.net
skayser at users.sourceforge.net
Wed Jan 11 23:04:42 CET 2012
Revision: 591
http://opencsw.svn.sourceforge.net/opencsw/?rev=591&view=rev
Author: skayser
Date: 2012-01-11 22:04:42 +0000 (Wed, 11 Jan 2012)
Log Message:
-----------
twitter/sweets: filter search result spam
Modified Paths:
--------------
twitter/sweets/sweets.py
Modified: twitter/sweets/sweets.py
===================================================================
--- twitter/sweets/sweets.py 2011-11-26 23:42:25 UTC (rev 590)
+++ twitter/sweets/sweets.py 2012-01-11 22:04:42 UTC (rev 591)
@@ -119,7 +119,13 @@
encoding = sys.stdout.encoding or 'utf-8'
print msg.encode(encoding, 'replace')
+ def get_matchting_tweets(self, string):
+ """Get list of tweets where the tweet contains a given string."""
+ for tweet in self.get_tweets():
+ if tweet['text'].find(string) == -1: continue
+ else: yield tweet
+
def twitter_search_mock(query="", state=""):
"""Search twitter (mockup), returns a single-line, JSON search result."""
f = open("sample-search-results.txt", "r")
@@ -150,7 +156,11 @@
response = TSResponse(file=outfile)
while 1:
try:
+ # Unfortunately, some search results are spam (text in tweet not
+ # related to query), thus we need to filter the search results
new_response = twitter_search(query, state=response.get_state())
+ new_response.set_tweets(new_response.get_matching_tweets(query))
+
if new_response.has_tweets():
new_response.print_tweets()
response.update(new_response)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the devel
mailing list