def testMergeTwoSystems(self): '''Tests merging two distinct Databases. ''' # Creates Database containing systems 11 Com and 11 UMi comAndUmiDB = Database() data = convert.getOEC(minidom.parse("test_files/11 Com.xml")) comAndUmiDB.update_xml(data) data = convert.getOEC(minidom.parse("test_files/11 UMi.xml")) comAndUmiDB.update_xml(data) mergedDB = merge(self.umiDB, self.comDB) self.assertEqual(mergedDB == comAndUmiDB, True)
def testGetOEC(self): ''' Tests that getOEC produces the correct dict when reading a parsed XML file. ''' dom = minidom.parse("test_files/11 Com.xml") systemsDict = convert.getOEC(dom) expectedDict = {'system': {'distance': '88.9', 'distance_attrs': {'errorminus': '1.7', 'errorplus': '1.7'}, 'star': {'planet': {'lastupdate': '15/09/20', 'periastrontime': '2452899.6', 'mass_attrs': {'errorminus': '1.5', 'type': 'msini', 'errorplus': '1.5'}, 'name': '11 Com b', 'semimajoraxis': '1.29', 'discoveryyear': '2008', 'periastrontime_attrs': {'errorminus': '1.6', 'errorplus': '1.6'}, 'discoverymethod': 'RV', 'eccentricity_attrs': {'errorminus': '0.005', 'errorplus': '0.005'}, 'list': 'Confirmed planets', 'period': '326.03', 'periastron_attrs': {'errorminus': '1.5', 'errorplus': '1.5'}, 'mass': '19.4', 'period_attrs': {'errorminus': '0.32', 'errorplus': '0.32'}, 'eccentricity': '0.231', 'semimajoraxis_attrs': {'errorminus': '0.05', 'errorplus': '0.05'}, 'periastron': '94.8', 'description': '11 Com b is a brown dwarf-mass companion to the intermediate-mass star 11 Comae Berenices.'}, 'magB_attrs': {'errorminus': '0.02', 'errorplus': '0.02'}, 'mass_attrs': {'errorminus': '0.3', 'errorplus': '0.3'}, 'name': ['11 Com', '11 Comae Berenices', 'HD 107383', 'HIP 60202', 'TYC 1445-2560-1', 'SAO 100053', 'HR 4697', 'BD+18 2592', '2MASS J12204305+1747341'], 'spectraltype': 'G8 III', 'radius_attrs': {'errorminus': '2', 'errorplus': '2'}, 'magV': '4.74', 'metallicity_attrs': {'errorminus': '0.09', 'errorplus': '0.09'}, 'magK': '2.282', 'magJ': '2.943', 'metallicity': '-0.35', 'magH': '2.484', 'radius': '19', 'temperature': '4742', 'magB': '5.74', 'mass': '2.7', 'magJ_attrs': {'errorminus': '0.334', 'errorplus': '0.334'}, 'magH_attrs': {'errorminus': '0.268', 'errorplus': '0.268'}, 'temperature_attrs': {'errorminus': '100', 'errorplus': '100'}, 'magK_attrs': {'errorminus': '0.346', 'errorplus': '0.346'}}, 'name': '11 Com', 'declination': '+17 47 34', 'videolink': 'http://youtu.be/qyJXJJDrEDo', 'rightascension': '12 20 43'}} self.assertEqual(systemsDict == expectedDict, True)
def testUpdateXmlName(self): '''Tests update_xml on an XML file containing the 11 Com system.''' # Parse XML with system 11 Com parsed = minidom.parse("test_files/11 Com.xml") data = convert.getOEC(parsed) db = dboec.Database() db.update_xml(data) self.assertEqual(db.pldata[0].name, ['11 Com b'])
def update(): #OEC print("Updating OEC database.............\n") # do a git pull to update OEC try: cloned_repo = git.Repo("open_exoplanet_catalogue") cloned_repo.git.checkout('master') cloned_repo.git.pull() except git.exc.GitCommandError: print "The repo 'open_exoplanet_catalogue' does not exist for updating." root_dir = os.getcwd() root_dir = root_dir + "/" + "open_exoplanet_catalogue" + "/" + "systems" oec_database = dboec.Database() for root, dirs, files in os.walk(root_dir): for name in files: data_one_system = minidom.parse(root + "/" + name) one_system_dict = convert.getOEC(data_one_system) oec_database.update_xml(one_system_dict) local_oec = open("local_oec_init", "wb") pickle.dump(oec_database, local_oec) local_oec.close() #EU database print("Updating .eu database..............\n") url_eu = "http://exoplanet.eu/catalog/csv" list_eu = [] with requests.Session() as s: download = s.get(url_eu) decoded_content = download.content.decode('utf-8') cr = csv.reader(decoded_content.splitlines(), delimiter=',') my_list = list(cr) for row in my_list: list_eu.append(row) eu_data = convert.getEU(list_eu) eu_database = dboec.Database() eu_database.update_csv(eu_data, dboec.attr_eu) local_eu = open("local_eu", "wb") pickle.dump(eu_database, local_eu) local_eu.close() #NASA database print("Updating NASA database..............\n") url_nasa = "http://exoplanetarchive.ipac.caltech.edu/cgi-bin/nstedAPI/nph-nstedAPI?table=exoplanets&select=*" list_nasa = [] with requests.Session() as s: download = s.get(url_nasa) decoded_content = download.content.decode('utf-8') cr = csv.reader(decoded_content.splitlines(), delimiter=',') my_list = list(cr) for row in my_list: list_nasa.append(row) nasa_data = convert.getNASA(list_nasa) nasa_database = dboec.Database() nasa_database.update_csv(nasa_data, dboec.attr_nasa) local_nasa = open("local_nasa", "wb") pickle.dump(nasa_database, local_nasa) local_nasa.close() print("Updating finished.")
def testMergeTwoSystemsWithThree(self): '''Tests merging two Databases where that each have multiple systems. ''' # Creates expected Database with all 5 systems expectedDB = Database() data = convert.getOEC(minidom.parse("test_files/11 Com.xml")) expectedDB.update_xml(data) data = convert.getOEC(minidom.parse("test_files/11 Umi.xml")) expectedDB.update_xml(data) data = convert.getOEC(minidom.parse("test_files/14 And.xml")) expectedDB.update_xml(data) data = convert.getOEC(minidom.parse("test_files/14 Her.xml")) expectedDB.update_xml(data) data = convert.getOEC(minidom.parse("test_files/16 Cygni.xml")) expectedDB.update_xml(data) mergedDB = merge(self.herToDel, self.comToAnd) self.assertEqual(mergedDB == expectedDB, True)
def setUp(self): # Database class with system 11 Com self.comDB = Database() parsed = minidom.parse("test_files/11 Com.xml") data = convert.getOEC(parsed) self.comDB.update_xml(data) # Database class with system 11 UMi self.umiDB = Database() parsed = minidom.parse("test_files/11 UMi.xml") data = convert.getOEC(parsed) self.umiDB.update_xml(data) # Database class with systems 11 Com, 11 UMi, 14 And self.comToAnd = Database() data = convert.getOEC(minidom.parse("test_files/11 Com.xml")) self.comToAnd.update_xml(data) data = convert.getOEC(minidom.parse("test_files/11 Umi.xml")) self.comToAnd.update_xml(data) data = convert.getOEC(minidom.parse("test_files/14 And.xml")) self.comToAnd.update_xml(data) # Database class with systems 14 Her, 16 Cygni self.herToDel = Database() data = convert.getOEC(minidom.parse("test_files/14 Her.xml")) self.herToDel.update_xml(data) data = convert.getOEC(minidom.parse("test_files/16 Cygni.xml")) self.herToDel.update_xml(data) self.comB1 = Planet() self.comB1.name = ['11 Com b'] self.comSt1 = Star() self.comSt1.name = ['11 Com'] self.comSt1.planet = [self.comB1] self.comSt2 = Star() self.comSt2.name = ['11 Com'] self.comSt2.planet = [self.comB1] self.sys1 = System() self.sys1.star = [self.comSt1] self.sys2 = System() self.sys2.star = [self.comSt1] self.comB2 = Planet() self.comB2.name = ['11 Com b'] self.umiB = Planet() self.umiB.name = ['11 UMi b'] self.umiSt = Star() self.umiSt.planet = [self.umiB] self.umiSys = System() self.umiSys.star = [self.umiSt]
from email.mime.multipart import MIMEMultipart from email import encoders from email.header import Header from subprocess import Popen if len(sys.argv) == 1: g = push_to_git.configuration() push_to_git.clone_repo(g) print("Initiating OEC database, Please wait.............\n") root_dir1 = os.getcwd() root_dir = root_dir1 + "/" + g.name + "/" + "systems" oec_database = dboec.Database() for root, dirs, files in os.walk(root_dir): for name in files: data_one_system = minidom.parse(root + "/" + name) one_system_dict = convert.getOEC(data_one_system) oec_database.update_xml(one_system_dict) local_oec = open("local_oec_init", "wb") pickle.dump(oec_database, local_oec) local_oec.close() print("Initialize finished.") print( "Welcome! Here you find a software to update open_exoplanet_catalogue.\n" ) print("For more information type '\help' to start!\n") while 1: user_input = sys.stdin.readline() if (user_input == r"\help" + "\n"): print("********************** User Guide ************************") print("\n") print("\help ---------------------- Open the User Guide.")
getattr(item, attrs)['errorminus'].decode('utf-8')) elif i == 'unit' and getattr(item, attrs)['unit']: subelem.set(i, getattr(item, attrs)['unit'].decode('utf-8')) elif i == 'upperlimit' and getattr(item, attrs)['upperlimit']: subelem.set( i, getattr(item, attrs)['upperlimit'].decode('utf-8')) elif i == 'lowerlimit' and getattr(item, attrs)['lowerlimit']: subelem.set( i, getattr(item, attrs)['lowerlimit'].decode('utf-8')) elif i == 'type' and getattr(item, attrs)['type']: subelem.set(i, getattr(item, attrs)['type'].decode('utf-8')) if __name__ == '__main__': import dboec import convert oecd = minidom.parse("systemexample.xml") data = convert.getOEC(oecd) d1 = dboec.Database() d1.update_xml(data) print(d1) for system in d1.system: print(system.name) toXml(system)