def formJSON(sentimentValue,text, name, nameTwitter): data = {} data['sentimentValue'] = sentimentValue data['text'] = text data['name'] = name data['nameTwitter'] = nameTwitter return json.dumps(data)
def on_data(self, data): if (final_colect_time > tm.time()): try: with open(dir + date.today().isoformat() + '.txt', 'a') as f: #with open(date.isocalendar() + '.txt', 'a') as f: # Recebo em Json # Converto para Dict new_data = json.loads(data) if ((new_data['place'] is not None or new_data['coordinates'] is not None or new_data['geo'] )): #save tweets with or without geolocation # filtro (Pode ser outra função dentro da minha classe) basic_filter(new_data) #print(len(new_data)) # Salva como Json no Disco new_data = (json.dumps(new_data)) print(new_data) f.write(new_data) f.write('\n') f.close() except BaseException as e: error_handler(e, bound_boxes, track, dir, ckey, csecret, atoken, asecret, initial_colect_time, final_colect_time, time) print("Error on_data : %s" % str(e)) return True else: print("Final time:" + tm.asctime(tm.localtime(final_colect_time))) return False
def sendRecieveMeaningCloud(tweets): url = 'http://sentiment.vivekn.com/api/batch/' data = tweets r = requests.post(url, data=json.dumps(data)) return r