Пример #1
0
 def processrequest_gettweets(self):
     tweets = []
     punctpattern = re.compile(r'[,;\'"\)\(}{\[\].!\?<>=+-/*\\:]+')
     http = httplib2.Http()
     """
     tokens = util.tokenize(self.title)
     qts = []
     for i in tokens:
         #if i in stopwords.words('english') or punctpattern.match(i) != None:
         if punctpattern.match(i) != None:
             continue
         qts.append(i)
     twords = ' '.join(qts)
     q = twords + ' from:' + self.domain
     """
     q = self.title + ' from:' + self.domain
     searchurl = 'http://search.twitter.com/search.json?rpp=100&q={0}&page=1&include_entities=true&result_type=mixed'.format(urllib.quote_plus(q))
     response, content = http.request(searchurl, 'GET')
     if response['status'] == '200':
         content = json.loads(content)
         results = content['results']
         if len(results) > 0:
             tweet = results[0]
             tweetsjsonarr = []
             idstr = tweet['id_str']
             to_user_id = tweet['from_user']
             q = 'to:'+to_user_id + ' OR ' + '#'+to_user_id
             for k in range(1, 16):
                 searchurl = 'http://search.twitter.com/search.json?rpp=100&q={0}&page={1}&include_entities=true&result_type=mixed'.format(urllib.quote_plus(q), k)
                 response, content = http.request(searchurl, 'GET')
                 if response['status'] == '200':
                     content = json.loads(content)
                     results = content['results']
                     if len(results) == 0:
                         break
                     twts = []
                     for twt in results:
                         if 'in_reply_to_status_id_str' in twt and twt['in_reply_to_status_id_str'] == idstr:
                             twt['related_tweet'] = idstr
                             twts.append(twt)
                     if len(twts) > 0:
                         tweetsjsonarr.extend(twts)
             if len(tweetsjsonarr) > 0:
                 tweets = util.gettweets(tweetsjsonarr, self.items, self.title)
     #self.tweets = tweets
     return tweets
Пример #2
0
 def processrequest_gettweetsfromdb(self):
     id_it = self.db.blogcontent.find({'url':self.url})
     c = 0
     for blog in id_it:
         c += 1
         break
     if c == 0:
         return []
     twt_it = self.db.tweets.find({'related_tweet':blog['id_str']})
     twts = [] 
     for i in twt_it:
         twts.append(i)
     if len(twts) == 0:
         return []
     tweets = util.gettweets(twts, self.items, self.title)
     #self.tweets = tweets
     return tweets