-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_openexoplanetcatalogue_systems.py
executable file
·68 lines (58 loc) · 2.28 KB
/
generate_openexoplanetcatalogue_systems.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/python
import urllib.request
import sys
import os
import shutil
import xml.etree.ElementTree as ET
import xmltools
import math
import datetime
import csv
import html
import cleanup
import glob
#####################
# Open Exoplanet Catalogue
# Only checking for new planets
#####################
def parse():
print("Reading previous planet list")
previous_planets = {}
with open("openexoplanetcatalogue_previous_planets.xml", 'rt') as f:
previous_planets_root = ET.parse(f).getroot()
for planet in previous_planets_root.findall(".//planet"):
name = planet.findtext("./name")
first_seen = planet.findtext("./first_seen")
previous_planets[name] = first_seen
print("Now checking if any changes occured")
for filename in glob.glob("../open_exoplanet_catalogue/systems/*.xml"):
f = open(filename, 'rt')
root = ET.parse(f).getroot()
systemname = root.findtext("./name")
changed = False
for planet in root.findall(".//planet"):
name = planet.findtext("./name")
markasnew = False
#markasnew = True
if name in previous_planets:
d1 = datetime.datetime.strptime(datetime.datetime.today().strftime('%Y-%m-%d'), "%Y-%m-%d")
d2 = datetime.datetime.strptime(previous_planets[name], "%Y-%m-%d")
age = (d1-d2)
if age.days <= 5 and previous_planets[name]!="2023-10-09":
markasnew = True
if name not in previous_planets:
new_planet = ET.SubElement(previous_planets_root, "planet")
ET.SubElement(new_planet, "name").text = name
ET.SubElement(new_planet, "first_seen").text = datetime.datetime.today().strftime('%Y-%m-%d')
markasnew = True
if markasnew:
ET.SubElement(planet, "new").text = "1"
changed = True
print("New planet found: " + name)
if changed:
ET.ElementTree(root).write(filename)
cleanup.checkonefile(filename)
xmltools.indent(previous_planets_root)
ET.ElementTree(previous_planets_root).write("openexoplanetcatalogue_previous_planets.xml")
if __name__=="__main__":
parse()