Exemplo n.º 1
0
def analyze(tweet):
    os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = read_property(
        'google.credentials.path')
    client = language.LanguageServiceClient()
    document = types.Document(content=tweet,
                              type=enums.Document.Type.PLAIN_TEXT)
    sentiment = client.analyze_sentiment(document).document_sentiment
    return sentiment.score, sentiment.magnitude
Exemplo n.º 2
0
#!/usr/bin/env python
# -*- coding:utf-8 -*-

"""
Error information definition.
--
[email protected]
blueantelope 2015-01-08
"""

from __init__ import *
from constant import *
import util

errors = util.read_property(ERROR_PROP_PATH)
# parse and objectify option: listening
class Arguments:
    tooshort = TOOSHORT
    illegal = ILLEGAL

    def __init__(self):
        _tooshort = errors["arguments.tooshort"]
        if ~util.str_isblank(_tooshort):
            self.tooshort = _tooshort
        _illegal = errors["arguments.illegal"]
        if ~util.str_isblank(_illegal):
            self.illegal = _illegal

arguments = Arguments()

Exemplo n.º 3
0
 def test_read_property(self):
     properties = util.read_property(ERROR_PROPERTY_PATH)
     print properties
Exemplo n.º 4
0
#!/usr/bin/env python
# -*- coding:utf-8 -*-

"""
Error information definition.
--
[email protected]
blueantelope 2015-01-08
"""

from __init__ import *
from constant import *
import util

errors = util.read_property(ERROR_PROP_PATH)
# parse and objectify option: listening
class Arguments:
    tooshort = TOOSHORT
    illegal = ILLEGAL

    def __init__(self):
        _tooshort = errors["arguments.tooshort"]
        if ~util.str_isblank(_tooshort):
            self.tooshort = _tooshort
        _illegal = errors["arguments.illegal"]
        if ~util.str_isblank(_illegal):
            self.illegal = _illegal


arguments = Arguments()
Exemplo n.º 5
0
from twython import Twython
from util import read_property
import requests

CONSUMER_KEY = read_property('consumer.key')
CONSUMER_SECRET = read_property('consumer.secret')
ACCESS_TOKEN = read_property('access.token')
ACCESS_TOKEN_SECRET = read_property('access.token.secret')
GEOCODING_KEY = read_property('geocoding.key')
GOOGLE_MAPS_API_URL = read_property('google.maps.api.url')


def search(hashtag, city, radius):
    t = Twython(app_key=CONSUMER_KEY,
                app_secret=CONSUMER_SECRET,
                oauth_token=ACCESS_TOKEN,
                oauth_token_secret=ACCESS_TOKEN_SECRET)
    params = {'address': city, 'key': GEOCODING_KEY}
    req = requests.get(GOOGLE_MAPS_API_URL, params=params)
    res = req.json()
    result = res['results'][0]
    lat = result['geometry']['location']['lat']
    lng = result['geometry']['location']['lng']
    geocode = str(lat) + ',' + str(lng) + ',' + str(radius) + 'mi'
    results = t.search(q=hashtag,
                       geocode=geocode,
                       lang='en',
                       result_type='recent',
                       count=10)
    statuses = results['statuses']
    tweets = []