コード例 #1
0
    def load(self, sid, username=''):
        strs = []
        mozi = ''
        tweetModel = TweetModel()
        access_token = memcache.get(sid)
        if access_token:
            try:
                auth = tweepy.OAuthHandler(config.CONSUMER_KEY,
                                           config.CONSUMER_SECRET)
                auth.set_access_token(access_token.key, access_token.secret)

                if username == '':
                    username = auth.get_username()

                api = tweepy.API(auth_handler=auth)

                for tweet in tweepy.Cursor(api.user_timeline,
                                           screen_name=username,
                                           count=500).items(100):
                    p = re.compile('(@)(\w+)')
                    text = p.sub('', tweet.text)
                    p = re.compile('[!-@[-`{-~]')
                    text = p.sub('', text)
                    p = re.compile(u'[!”#$%&’()=~|‘{+*}<>?_-^¥@「;:」、。・]')
                    text = p.sub('', text)
                    mozi += text

                morpho = Morpho()
                strs = morpho.analyze(mozi, 200)
            except:
                pass
        return strs
コード例 #2
0
    def load(self, keyword):
        encKey = urllib.quote(keyword.encode('utf-8'))
        reqURL = (
            'https://ajax.googleapis.com/ajax/services/search/news?' +
            'v=1.0&key=ABQIAAAAzk2wmP0-QkezFZB4jKCidxTgNOgp-MR3hNxNEPAaDYM58TmiQRTDWA1p4xA7dYYta0tbq7J-_pb0UA&hl=ja&rsz=8&q='
        )

        req = urllib2.Request(reqURL + encKey, None,
                              {'Referer': 'http:/127.0.0.1:8080'})
        response = urllib2.urlopen(req)

        results = parse_json(response)
        contents = results['responseData']['results']
        str = ''

        for content in contents:
            str += content['titleNoFormatting']
            p = re.compile('[!-@[-`{-~]')
            str = p.sub('', str)
            p = re.compile(u'[!”#$%&’()=~|‘{+*}<>?_-^¥@「;:」、。・]')
            str = p.sub('', str)
            str = str.replace(unicode(keyword), '')

        morpho = Morpho()
        strs = morpho.analyze(str, 3)

        hasImg = False
        index = 0

        model = KeywordModel()
        model.keyword = keyword
        model.one = strs[0][1]
        model.two = strs[1][1]
        model.three = strs[2][1]

        try:
            for content in contents:
                if content['image']:
                    model.text = content['titleNoFormatting']
                    model.imgURL = content['image']['url']
                    model.url = content['image']['originalContextUrl']
                    model.status = 'Success'
                    break
                else:
                    model.text = content['titleNoFormatting']
                    model.url = content['image']['originalContextUrl']
        except:
            model.status = 'News Analyze Error'
        if not model.text:
            model.text = contents[0]['titleNoFormatting']
            model.url = urllib2.unquote(contents[0]['url']).encode(
                'raw_unicode_escape').decode('utf-8')
        model.put()
        return model
コード例 #3
0
    def load(self, sid, username=''):
        strs = []
        mozi = ''
        tweetModel = TweetModel()
        access_token = memcache.get(sid)
        if access_token:
            try:
                auth = tweepy.OAuthHandler(config.CONSUMER_KEY,
                                           config.CONSUMER_SECRET)
                auth.set_access_token(access_token.key, access_token.secret)

                if username == '':
                    username = auth.get_username()

                api = tweepy.API(auth_handler=auth)

                for tweet in tweepy.Cursor(api.user_timeline,
                                           screen_name=username,
                                           count=500).items(100):
                    p = re.compile('(@)(\w+)')
                    text = p.sub('', tweet.text)
                    p = re.compile('[!-@[-`{-~]')
                    text = p.sub('', text)
                    p = re.compile(u'[!”#$%&’()=~|‘{+*}<>?_-^¥@「;:」、。・]')
                    text = p.sub('', text)
                    mozi += text

                morpho = Morpho()
                strs = morpho.analyze(mozi)
                iconURL = api.me().profile_image_url

                try:
                    if iconURL.index('_normal'):
                        iconURL = iconURL.replace('_normal', '')
                except:
                    pass

                tweetModel.username = username
                tweetModel.iconURL = iconURL
                tweetModel.status = 'Success'
                tweetModel.one = strs[0][1]
                tweetModel.two = strs[1][1]
                tweetModel.three = strs[2][1]
                tweetModel.four = strs[3][1]
                tweetModel.five = strs[4][1]
                tweetModel.put()
            except:
                tweetModel.status = 'Authentication Error'
                tweetModel.put()
        return tweetModel
コード例 #4
0
ファイル: views.py プロジェクト: glassesfactory/WorldWordWeb
def morphotest(request):
    strs = []
    morpho = Morpho()
    strs = morpho.analyze(u'めがねもめがね、めがめがね')
    return render_to_response('www/mp.html', {'strs': strs})