コード例 #1
0
	def __init__(self, file_path):
		ini = IniReader(file_path)
		mysql_info = ini.get_mysql_info()
		self.host = mysql_info[0]
		self.port = mysql_info[1]
		self.user = mysql_info[2]
		self.passwd = mysql_info[3]
		self.db_name = mysql_info[4]
		self.db =  MySQLdb.connect(host = self.host , user = self.user ,passwd = self.passwd ,db = self.db_name)
		self.cursor = self.db.cursor()
コード例 #2
0
 def __init__(self, file_path):
     ini = IniReader(file_path)
     mysql_info = ini.get_mysql_info()
     self.host = mysql_info[0]
     self.port = mysql_info[1]
     self.user = mysql_info[2]
     self.passwd = mysql_info[3]
     self.db_name = mysql_info[4]
     self.db = MySQLdb.connect(host=self.host,
                               user=self.user,
                               passwd=self.passwd,
                               db=self.db_name)
     self.cursor = self.db.cursor()
コード例 #3
0
	def setUp(self):
		db=MySQLdb.connect("localhost","ttt","ttt","ttt_testing")
		db.query("truncate tweets;")
		db.query("truncate tweets_matched;")
		db.query("truncate tweets_parsed;")
		self.expected_requests = ["#busco", "#sebusca", "#ruok", "#need"]
		self.expected_responses = ["#encontre","#seencontro","#imok","#found"]
		self.expected_location = ["#sitio","#location","#en","#loc","#zona","#localidad","#gps"," #lugar"]
		self.expected_contact = ["#contacto","#contact","#contactar","#con","#cont","#avisar","#telefono","#fono","#tel","#cel"]
		self.expected_name = ["#name","#nombre"]
		ini = IniReader("testing.ini")
		mysql_info = ini.get_mysql_info()
		mysql_info = [mysql_info[0]]+mysql_info[2:]
		self.tweet_matcher = tweetmatcher.TweetMatcher("categoria",self.expected_requests, self.expected_responses,self.expected_location,self.expected_contact,self.expected_name,mysql_info)
コード例 #4
0
def main(ini_filename):
    try:
        #connectors = config.get('CONFIG','connectors')
        #connectors = connectors.split(' ')
        #log.debug(connectors)

        #savers = []

        ini = IniReader(ini_filename)
		
        mysql_info = ini.get_mysql_info()
        mysql_host = mysql_info[0]
        mysql_port = mysql_info[1]
        mysql_user = mysql_info[2]
        mysql_pass = mysql_info[3]
        mysql_db_name = mysql_info[4]

        csv_info_path = ini.get_csv_info()

        log_saver = tweetsavers.TweetSaverLog(logging.getLogger('tweets'))
        csv_saver = tweetsavers.TweetSaverCSV(csv_info_path)
        mysql_saver = tweetsavers.TweetSaverMySQL(mysql_host, mysql_db_name, mysql_user, mysql_pass)
#        print ini.get_secondary_tag_list()
        listener = StreamWatcherListener(ini.get_secondary_tag_list(),ini.get_username(), ini.get_password(), [log_saver, csv_saver, mysql_saver])
        stream = tweepy.Stream(ini.get_username(),
                                ini.get_password(),
                                listener,
                                timeout = None)
#		track_list = [k.strip() for k in PRIMARY_TRACK_LIST.split(',')]
#		track_list = [k.strip() for k in ini.get_primary_tag_list().split(' ')]
        track_list = [k.strip() for k in ini.get_primary_tag_list()]

        stream.filter(track = track_list)
    except KeyboardInterrupt:
        print '\nCiao!'
コード例 #5
0
def main(ini_filename):
    try:
        #connectors = config.get('CONFIG','connectors')
        #connectors = connectors.split(' ')
        #log.debug(connectors)

        #savers = []

        ini = IniReader(ini_filename)

        mysql_info = ini.get_mysql_info()
        mysql_host = mysql_info[0]
        mysql_port = mysql_info[1]
        mysql_user = mysql_info[2]
        mysql_pass = mysql_info[3]
        mysql_db_name = mysql_info[4]

        csv_info_path = ini.get_csv_info()

        log_saver = tweetsavers.TweetSaverLog(logging.getLogger('tweets'))
        csv_saver = tweetsavers.TweetSaverCSV(csv_info_path)
        mysql_saver = tweetsavers.TweetSaverMySQL(mysql_host, mysql_db_name,
                                                  mysql_user, mysql_pass)
        #        print ini.get_secondary_tag_list()
        listener = StreamWatcherListener(ini.get_secondary_tag_list(),
                                         ini.get_username(),
                                         ini.get_password(),
                                         [log_saver, csv_saver, mysql_saver])
        stream = tweepy.Stream(ini.get_username(),
                               ini.get_password(),
                               listener,
                               timeout=None)
        #		track_list = [k.strip() for k in PRIMARY_TRACK_LIST.split(',')]
        #		track_list = [k.strip() for k in ini.get_primary_tag_list().split(' ')]
        track_list = [k.strip() for k in ini.get_primary_tag_list()]

        stream.filter(track=track_list)
    except KeyboardInterrupt:
        print '\nCiao!'
コード例 #6
0
    def __init__(self, file_path):

        ini = IniReader(file_path)
        mysql_info = ini.get_mysql_info()
        mysql_host = mysql_info[0]
        mysql_port = mysql_info[1]
        mysql_user = mysql_info[2]
        mysql_pass = mysql_info[3]
        mysql_db_name = mysql_info[4]

        categorias = ini.get_categories()
        diccionario = ini.get_categories_req_resp()

        location = ini.get_info_location()
        contact = ini.get_info_contact()
        name = ini.get_info_name()

        for categoria in categorias:

            requests = diccionario[(categoria, 'request')]
            responses = diccionario[(categoria, 'response')]

            tweet_matcher = tweetmatcher.TweetMatcher(
                categoria, requests, responses, location, contact, name,
                [mysql_host, mysql_user, mysql_pass, mysql_db_name])

            tweets = self.tweet_reader(mysql_host, mysql_user, mysql_pass,
                                       mysql_db_name)
            rows = tweets.fetch_row(0)
            for tweet in rows:  #tweet[0] = id, #tweet[1] = text
                tupla = [tweet[0], tweet[1], tweet[2]]
                [type, text] = tweet_matcher.parse(tupla)
                if text:
                    #TODO: hacer update a los tweets con el id, que esta en text[0]
                    #acutalizar el dispatcher para leer del diccionario
                    #modificar el mysql para que lea los parametros de la bd del .ini
                    #ponerse de acuerdo que hacer cuando se hace un match
                    if type == tweetmatcher.REQ:
                        map(
                            lambda x: self.tweet_match(
                                mysql_host, mysql_user, mysql_pass,
                                mysql_db_name, x, tweet[0], categoria), text)
                    elif type == tweetmatcher.RESP:
                        map(
                            lambda x: self.tweet_match(
                                mysql_host, mysql_user, mysql_pass,
                                mysql_db_name, tweet[0], x, categoria), text)
            self.set_parsed(mysql_host, mysql_user, mysql_pass, mysql_db_name)
コード例 #7
0
class TestIniReader(unittest.TestCase):
    def setUp(self):
        self.ini=IniReader("testing.ini")

    def test_get_configs(self):
        self.assertEquals(self.ini.get_username(),"twitter_user")
        self.assertEquals(self.ini.get_password(),"twitter_pass")

    def test_get_primary_tags(self):
        self.assertEquals(self.ini.get_primary_tag_list(),["#chile","#terremoto","#fmarepoto"])

    def test_get_secondary_tag_list(self):
        expected=["#estaibien","#missing","#ruok","#sebusca","#estaibien","#buscapersona","#estasbien","#tavivo","#estabien","#tabien","#estoybien","#todobien","#toybien","#imok","#survivor","#encontr","#found","#necesita","#need","#necesidad","#donacion","#ofrece","#tenemos","#tengo","#have","#offer","#dono","#closed","#open","#damage","#evac","#edificiocolapso"]
        expected.sort()
        got=self.ini.get_secondary_tag_list()
        got.sort()
        self.assertEquals(got,expected)
    
    def test_get_categories_req_resp(self):
        expected=dict([])
        expected[('PEOPLE','request')]= ["#estaibien","#missing","#ruok","#sebusca","#estaibien","#buscapersona","#estasbien"]
        expected[('PEOPLE','response')]=["#tavivo","#estabien","#tabien","#estoybien","#todobien","#toybien","#imok","#survivor","#encontr","#found"]
        expected[('HELP','request')]=["#necesita","#need","#necesidad"]
        expected[('HELP','response')]=["#donacion","#ofrece","#tenemos","#tengo","#have","#offer","#dono"]
        expected[('INFO','request')]=[]
        expected[('INFO','response')]=["#closed","#open","#damage","#evac","#edificiocolapso"]
        self.assertEquals(self.ini.get_categories_req_resp(),expected)

    def test_get_categories(self):
        self.assertEquals(self.ini.get_categories(),["PEOPLE","HELP","INFO"])

    def test_get_mysqlinfo(self):
        self.assertEquals(self.ini.get_mysql_info(),["localhost","3306","ttt","ttt","ttt_testing"])
    
    def test_get_info_tags(self):
        self.assertEquals(self.ini.get_info_contact(), ["#contacto","#contact", "#contactar", "#con", "#cont", "#avisar", "#telefono", "#fono", "#tel", "#cel"])
        self.assertEquals(self.ini.get_info_location(), ["#sitio","#location","#en","#loc","#zona","#localidad","#gps","#lugar"])
        self.assertEquals(self.ini.get_info_name(),["#name","#nombre"])
コード例 #8
0
	def __init__(self, file_path):

		ini = IniReader(file_path)
		mysql_info = ini.get_mysql_info()
		mysql_host = mysql_info[0]
		mysql_port = mysql_info[1]
		mysql_user = mysql_info[2]
		mysql_pass = mysql_info[3]
		mysql_db_name = mysql_info[4]

		categorias = ini.get_categories()
		diccionario = ini.get_categories_req_resp()

		location = ini.get_info_location()
		contact = ini.get_info_contact()
		name = ini.get_info_name()

		for categoria in categorias:

			requests = diccionario[(categoria, 'request')]
			responses = diccionario[(categoria, 'response')]

			tweet_matcher = tweetmatcher.TweetMatcher(categoria, requests, responses,location,contact,name,[mysql_host,mysql_user,mysql_pass,mysql_db_name])

			tweets = self.tweet_reader(mysql_host, mysql_user, mysql_pass, mysql_db_name)
			rows = tweets.fetch_row(0)
			for tweet in rows: #tweet[0] = id, #tweet[1] = text
				tupla  = [tweet[0], tweet[1], tweet[2]]
				[type,text] = tweet_matcher.parse(tupla)
				if text:
					#TODO: hacer update a los tweets con el id, que esta en text[0]
					#acutalizar el dispatcher para leer del diccionario
					#modificar el mysql para que lea los parametros de la bd del .ini
					#ponerse de acuerdo que hacer cuando se hace un match
					if type==tweetmatcher.REQ:
						map(lambda x:self.tweet_match(mysql_host,mysql_user,mysql_pass,mysql_db_name,x,tweet[0],categoria),text)
					elif type==tweetmatcher.RESP:
						map(lambda x:self.tweet_match(mysql_host,mysql_user,mysql_pass,mysql_db_name,tweet[0],x,categoria),text)
			self.set_parsed(mysql_host,mysql_user,mysql_pass,mysql_db_name)
コード例 #9
0
 def setUp(self):
     self.ini=IniReader("testing.ini")