def main(): arg = sys.argv if len(arg) != 2: print "Usage: dataUpload [radio-observer configFile]" sys.exit(1) else: configFile = arg[1] parser = ejson.Parser() config = parser.parse_file(configFile) station = config["configurations"][0]["children"][0]["origin"] observatory = config["storage_username"] payload = {'station': station, 'observatory': observatory, 'msg': 'Hello!'} print payload r = requests.get('http://rtbolidozor.astro.cz/event', params=payload, timeout=1) print station print observatory while True: try: pipe = sys.stdin.readline() if "met" in pipe: print "Meteor from radio-observer pipe:", pipe payload = {'station': station, 'observatory': observatory, 'msg': ''} print payload r = requests.get('http://rtbolidozor.astro.cz/event', params=payload, timeout=1) else: time.sleep(0.5) except Exception, e: print e time.sleep(1)
#!/usr/bin/python import time, datetime import telepot import sys import os from telepot.loop import MessageLoop from mlabutils import ejson parser = ejson.Parser() #### Script Arguments ############################################### if len(sys.argv) != 2: sys.stderr.write("Invalid number of arguments.\n") sys.stderr.write("Usage: %s CONFIG_FILE\n" % (sys.argv[0], )) sys.exit(1) value = parser.parse_file(sys.argv[1]) dataSource = value['data_path'] # raw data dataMeteo = value['data_meteo'] # meteo data stationName = value['origin'] meteoSensors = [ ['Time', 'unix t.s.'], ['Wind direction', 'deg'], ['Wind speed', 'm/s'], ['Gusty wind', 'm/s'], ['Precipitation', 'mm'],
def start(self): print "started OK" print self.configFile parser = ejson.Parser() value = parser.parse_file(self.configFile) self.value = value sync_folders = [] remoteBasePath = os.path.join( value["storage_stationpath"], value["storage_username"], value["configurations"][0]["children"][0]["origin"]) #navazani ssh spojeni pomoci ssh klice a username z cfg souboru ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(value["storage_hostname"], username=value["storage_username"]) sftp = ssh.open_sftp() if value["project"] == "bolidozor": #TODO: udelat lepsi zpusob ziskani cest z config souboru sync_folders.append( value["configurations"][0]["children"][0]["metadata_path"]) sync_folders.append(value["configurations"][0]["children"][0] ["children"][0]["output_dir"]) sync_folders.append(value["configurations"][0]["children"][0] ["children"][1]["output_dir"]) sync_folders.append(value["project_home_folder"]) elif value["project"] == "ionozor": sync_folders.append(value["configurations"][1]["children"][0] ["children"][0]["output_dir"]) sync_folders.append(value["project_home_folder"]) elif value["project"] == "meteo": sync_folders.append( value["configurations"][0]["children"][0]["metadata_path"]) sync_folders.append(value["project_home_folder"]) else: print "Uknown project." for i, folder in enumerate(sync_folders): print i, folder TimeStartFolder = time.time() filelist = os.listdir(folder) for i2, file in enumerate(filelist): remote_path = None local_path = os.path.join(folder, file) if any(x in file for x in ["meta.csv", "freq.csv"]): remote_path = os.path.join(remoteBasePath, os.path.basename(folder), "data", file[0:4], file[4:6], file[6:8], file) elif any(x in file for x in ["snap.fits"]): remote_path = os.path.join(remoteBasePath, os.path.basename(folder), "snapshots", file[0:4], file[4:6], file[6:8], file[8:10], file) elif any(x in file for x in ["met.fits", "raws.fits"]): remote_path = os.path.join(remoteBasePath, os.path.basename(folder), "meteors", file[0:4], file[4:6], file[6:8], file[8:10], file) elif "station" in os.path.dirname(folder) and os.path.isfile( local_path): print "file in station folder:", file remote_path = os.path.join(remoteBasePath, file) else: print os.path.dirname(folder), print "Preskakuji:", folder, file if remote_path: print local_path, remote_path # zkontrolovat jestli existuje slozka na remote server try: sftp.chdir(os.path.dirname(remote_path)) except IOError: # popripade ji vytvorit print "create folder:", os.path.dirname(remote_path) #sftp.mkdir(os.path.dirname(remote_path)+ "/") # touto cesto nelze vytvorit vice slozek zaroven TODO: otestovat jine moznosti ssh.exec_command('mkdir -p ' + repr(os.path.dirname(remote_path)) + "/") sftp.put(local_path, remote_path) # ziskani kontrolnich souctu na remote serveru a lokalnich souboru stdin_remote, stdout_remote, stderr_remote = ssh.exec_command( "md5 -q " + remote_path) md5_remote = stdout_remote.read() md5 = hashlib.md5(open(local_path, 'rb').read()).hexdigest() #print md5_remote, md5 #print "Baf: ", os.path.dirname(folder) ''' if md5 in md5_remote and "moussala" not in os.path.dirname(folder): # na konci md5_remote je odradkovani, kontrola, zdali nejde o soubor v /bolidozor/stotion self.UploadEvent(remote_path, md5) if ".csv" not in local_path: os.remove(local_path) print "odstraneno" elif os.path.getmtime(local_path) < time.time() - 2*60*100: # ochrana pred smazanim metadat, do kterych se zapisuje prubezne os.remove(local_path) print "odstranen starsi dokument" else: print "bude odstraneno" else: print "Ble" ''' sftp.close() ssh.close()