import sys import sqlite3 import merge_databases PARAMETERS="""timestamp , google_connection_test , http_connection_test , network_type , mobile_data_network_type , sim_state , detailed_state , is_connected , is_roaming , is_available , is_failover , data_activity , data_state , reason , extra_info , wifi_ssid , wifi_bssid , wifi_frequency , wifi_channel , wifi_signal_strength , wifi_rssi , sim_operator , sim_mcc , sim_mnc , network_operator , network_mcc , network_mnc , is_network_metered , device_latitude, device_longitude, device_position_accuracy, cell_signal_strength , cell_signal_strength_dbm , cell_asu_level , gsm_ber , lte_rsrq , cdma_cell_base_station_id , cdma_cell_latitude , cdma_cell_longitude , cdma_cell_network_id , cdma_cell_system_id , gsm_full_cell_id , gsm_rnc , gsm_short_cell_id , gsm_cell_lac , gsm_cell_psc , network_interface , ipv4_address , ipv6_address , battery_level , download_speed , upload_speed """ # if the database is not supplied on the commandline if sys.argv[1] == None: sys.exit(2) target = open("log", 'r') print sys.argv[1] database_to_merge = str(sys.argv[1]) for line in target: if str(line[:-1]) == database_to_merge: print "Already merged this database" target.close() sys.exit(3) target.close() user_id = "networkmonitor" if len(database_to_merge) >= 16: user_id = database_to_merge[:16] try: con = sqlite3.connect( "files/" + database_to_merge) cursor = con.cursor() command = "select " +PARAMETERS+" from networkmonitor" cursor.execute(command) result = cursor.fetchone() if result == None: sys.exit(4) while result != None: merge_databases.insert_into_table(result,PARAMETERS,user_id) result = cursor.fetchone() print "Writing to log file" target = open("log", 'a') target.write(database_to_merge) target.write('\n') target.close() con.close() except: con.close()