-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessiers.py
More file actions
86 lines (74 loc) · 2.55 KB
/
Copy pathmessiers.py
File metadata and controls
86 lines (74 loc) · 2.55 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import json
import random
import time
import os
import logging
from dict2xml import dict2xml
import yaml
import json2table
logging.basicConfig(filename='log.log', level=logging.DEBUG)
def get(object="missing", format="json"):
print(format)
format = format.lower()
if object == "all":
with open("./data/messier.json", "r") as f:
data = json.load(f)
if "json" in format:
return data
elif "xml" in format:
print("dict2xml starting")
xml_data = dict2xml(data, wrap='root', indent=" ")
print(xml_data)
return xml_data
elif format == "yaml":
return yaml.dump(data, allow_unicode=True)
elif format == "html" or "visual":
html_data = json2table.convert(
data,
build_direction="LEFT_TO_RIGHT",
table_attributes={"border": "1"})
print(html_data)
return html_data
try:
print(object)
object = int(object)
print(object)
except ValueError:
return {"success": "false", "name": "Must be integer!"}
print("get")
print(f"object is {object}")
if object == "missing":
return {
"success": "false",
"name":
"object cannot be None! Please specify the object you want..."
}
else:
if int(object) > 110:
return {
"success": "false",
"name": "Messier only found 110 objects! You are over 110!"
}
elif int(object) <= 0:
return {"success": "false", "name": "Object cannot be 0 or below!"}
else:
object = f"M{object}"
print(object)
with open("./data/messier.json", "r") as f:
data = json.load(f)
data = data[object]
if "json" in format:
return data
elif format == "xml":
xml_data = dict2xml(data, wrap='root', indent=" ")
print(xml_data)
return xml_data
elif format == "yaml":
return yaml.dump(data, allow_unicode=True)
elif format == "html" or "visual":
html_data = json2table.convert(
data,
build_direction="LEFT_TO_RIGHT",
table_attributes={"border": "1"})
print(html_data)
return html_data