Example #1
0
def main(argv=None):
    '''
    app entry point
    '''
    # gets a twitter object
    tw = twitter(TWITTER['CONSUMER_KEY'], TWITTER['CONSUMER_SECRET'], \
        TWITTER['ACCESS_TOKEN'], TWITTER['ACCESS_TOKEN_SECRET'])
    # gets a bitly object
    bl = bitly(BITLY['USER'], BITLY['APIKEY'])

    # tries to load the history from the file. If an exception is raised,
    # istantiates an empty dictionary object
    try:
        history = pickle.load(open(HISTORY_FILE, 'rb'))
    except:
        history = dict()

    # cycles through the RSSs defined in settings
    for rsskey, rssvalue in RSS.iteritems():
        # gets a feed object
        fd = feeds(rssvalue['RSS'])
        # tries to load last timestamp. If an exception is raised,
        # initializes it with the init value defined in settings
        try:
            last_timestamp = history[rsskey]
        except:
            last_timestamp = (rssvalue['HISTORY'])['INIT_VALUE']
            history[rsskey] = last_timestamp
        # gets the updated feeds
        entries = fd.get_updated_feeds(rssvalue['HISTORY'], last_timestamp)
        # cycles through the feeds, tweetin them
        for feed in entries:
            link = bl.shorten_url(getattr(feed, rssvalue['LINK']))
            tweet = getattr(feed, rssvalue['TEXT'])
            length = TWITTER['TWEET_LENGTH'] - len(rssvalue['HASHTAG']) \
                     - len(link) - 10
            tweet = rssvalue['HASHTAG'] + ' ' + tw.truncate(tweet, length) \
                    + ' ' + link
            tw.update_status(tweet, DEBUG)
        # updates the last timestamp
        history[rsskey] = fd.get_last_timestamp()
    # saves the history
    pickle.dump(history, open(HISTORY_FILE, 'wb'))
    sys.exit(0)
Example #2
0
import sentiments
import findEntities
import search

print "scriptinicial"
# Processamento das bibliotecas... Colocar o ficheiro personalidades e e sentilex em dicionarios
politiciansList = []
opinionDic = {}
lexiDic = {} # Dicionario que contem como key -> primeira palavra value e uma lista com tuplas
tuple = ()	# (resto da frase, comprimento da frase, polaridade)
list_personalities = []

#Tratamento com o sentilex
sentiments.sentilexTratamento(lexiDic, tuple)
findEntities.personalidadesTratamento(list_personalities)

#Feeds das noticias
feeds.feeds(lexiDic, list_personalities, opinionDic)

print "\nNoticias:"
for op in opinionDic:
	print op
	print "\nPoliticos:"
	for i in opinionDic[op][0]:
		print i
	print "\nValor da noticia: ",opinionDic[op][1],"\n\n"
#Extração dos dados para um ficheiro.dat
sentiments.analiseSentimentos(opinionDic)
#sentiments. analiseSentimentos(opinionDic):
#Pesquisa BM25
search.search(list_personalities)
	def child_feeds(self, ctx):
		return feeds(self.username, self.app, self.log)
 def child_feeds(self, ctx):
     return feeds(self.username, self.app, self.log)