Beispiel #1
0
    def set_auth_handlers(self):
        with open(self.credentials_file_path, 'r') as credentials_file:
            credentials = byteify(json.load(credentials_file))

        for item in credentials:
            auth_handler = CustomAuthHandler(item['access_token'], item['access_token_secret'], item['consumer_key'],
                                             item['consumer_secret'])
            self.auth_handlers.append(auth_handler)
def exportCSV(outPath,data):
	freq = byteify(data)
	with open(outPath,'w+') as o:
		o.write('tag,word,count,sentiment\n')
		for tag in freq:
			for word in freq[tag]:
				count = str(freq[tag][word]['count'])
				sentiment = str(freq[tag][word]['sentiment'])
				o.write(tag+','+word+','+count+','+sentiment+'\n')
 def on_data(self, raw_data):
     today = datetime.utcnow().date()
     dir = self.data_dir + '/' + today.strftime('%Y-%m-%d')
     if not os.path.exists(dir):
         os.makedirs(dir)
     master = open('{0}/{1}_{2}.json'.format(dir, 'master', str(self.index)), 'a')
     data = byteify(json.loads(raw_data))
     print data['text']
     master.write(jsonpickle.encode(data, unpicklable=False)+'\n')
     master.close()
Beispiel #4
0
def exportCSV(outPath, data):
    freq = byteify(data)
    with open(outPath, 'w+') as o:
        o.write('tag,word,count,sentiment\n')
        for tag in freq:
            for word in freq[tag]:
                count = str(freq[tag][word]['count'])
                sentiment = str(freq[tag][word]['sentiment'])
                o.write(tag + ',' + word + ',' + count + ',' + sentiment +
                        '\n')
    def load_settings(self):
        with open(self.settings_file_path,"r") as f:
            settings =  byteify(json.load(f)) # to parse unicodes to strings

        # Apply specified settings
        for arg in self.arg_list:
            try:
                value = settings[arg]
            except:
                raise KeyError('No value for argument '+arg+' found in arg_list')

            setattr(self, arg, value)
    def on_data(self, raw_data):
        today = datetime.utcnow().date()
        dir = self.data_dir + '/' + today.strftime('%Y-%m-%d')
        if not os.path.exists(dir):
            os.makedirs(dir)
        master = open('{0}/{1}_{2}.json'.format(dir, 'master', str(self.index)), 'a')
        data = byteify(json.loads(raw_data))
	try:
		print data['text']
		master.write(jsonpickle.encode(data, unpicklable=False)+'\n')
		master.close()
	except (AttributeError,KeyError):
		master.close()
    def __init__(self,path, settings_list):
        with open(os.path.join(os.path.dirname(__file__),"global.json"),"r") as f:
            self.global_setup =  byteify(json.load(f))

        self.generate_relevant_paths(path)

        self.arg_list = settings_list +\
            ['X_name','X_coord','X_start','X_end','X_points',
            'Y_name','Y_coord','Y_start','Y_end','Y_points',
            'Z_name','Z_coord','Z_start','Z_end','Z_points']


        self.start_comments = ""
        self.end_comments = ""
        self.detail = ""
        self.load_settings()