def receivefile(self, sock, commandArgs, recoveryFunc): try: fileWorker = FileWorker(sock, commandArgs, recoveryFunc) fileWorker.recvFileInfo() fileWorker.recvPacketsTCP() except FileWorkerError: pass
def recvfileUDP(self, sock, commandArgs): try: fileWorker = FileWorker(sock, commandArgs, None) fileWorker.recvFileInfo() fileWorker.recvPacketsUDP() except FileWorkerError: pass
def sendfile(self, sock, commandArgs, recoveryFunc): try: fileWorker = FileWorker(sock, commandArgs, recoveryFunc) fileWorker.sendFileInfo() fileWorker.sendPacketsTCP() except FileWorkerError: pass
def downloadStateMachine(self,sock,fileInfoRoutine,packetsRoutine,recoverRoutine,clientMsg): #transfer init if self.status == QueryStatus.Actual: self.fileWorker = FileWorker(sock,self.args,recoverRoutine) try: #get udp client addr if sock.proto == IPPROTO_UDP: self.getClientAddr() fileInfoRoutine(self.fileWorker) self.status = QueryStatus.InPorgress except FileWorkerError as e: self.clientIsAlive = False self.completeState(e.args[0]) #packets elif self.status == QueryStatus.InPorgress: try: if sock.proto == IPPROTO_UDP: self.restoreClientAddrForUDP() packetsRoutine(self.fileWorker) if self.fileWorker.file.closed: #download complete self.completeState(clientMsg) except FileWorkerError as e: #download error self.clientIsAlive = False self.completeState(e.args[0])
def download(sock,fileName): fileWorker = FileWorker(sock,fileName,None,0) try: fileWorker.sendFileInfo() fileWorker.sendPacketsTCP() except FileWorkerError as e: sock.sendMsg(e.args[0]) else: sock.sendMsg('downloaded')
import sys sys.path.append('/home/rodrigo/Twitter Analysis Library/lib') from FileWorker import * import re from pymongo import * client = MongoClient('localhost', 27017) db = client['db_terremoto'] collection = db['ecuador_terremoto'] tweets_iterator = collection.find() data = {} locations = [] for tweet in tweets_iterator: if 'coordinates' in tweet.keys(): if tweet['coordinates'] != None: coordinates = tweet['coordinates'] lng = coordinates['coordinates'][0] lat = coordinates['coordinates'][1] obj = {} obj['coordinates'] = {} obj['coordinates']['lat'] = lat obj['coordinates']['lng'] = lng locations.append(obj) data["num_tweets"] = len(locations) data["tweets"] = locations FileWorker().writeJSON("locations.json", data)
# # import Globals as glb import FileWorker as fw import City as spacePoint from GeneticAndEvoLib import GeneticAlgorithm as ga import Visualizer as vis if __name__ == "__main__": # # fileWorker = fw.FileWorker(citiesFilepath=glb.CITIES_FILEPATH, optTourFilepath=glb.OPTIMAL_TOUR_FILEPATH) citiesFileMetadata, optTourFileMetadata, \ citiesCoordsList, optTourPointIdList = fileWorker.run() print() print("Cities File Metadata: ") print(citiesFileMetadata) print() print("Opt Tour File Metadata: ") print(optTourFileMetadata) print() print("Cities Coords List: ") print(citiesCoordsList) print() print("Opt Tour Point Id List: ") print(optTourPointIdList) #