-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_and_format_comet_data.py
More file actions
73 lines (43 loc) · 1.12 KB
/
Copy pathget_and_format_comet_data.py
File metadata and controls
73 lines (43 loc) · 1.12 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
import json
import requests
import os
name = input("Name of Comet: ").lower()
url = f"https://theskylive.com/objects/{name}/chartdata_dg.json"
try:
os.mkdir(name)
except:
pass
filename = f"{name}/{name}"
# saving data
data = requests.get(url).text
f = open(filename + "_raw.txt", "w")
f.write(data)
f.close()
# reading in the data
f = open(filename + "_raw.txt", "r")
original = f.readlines()
f.close()
# removing uncessary lines
lines = original[16:]
formatted_lines = []
for i in lines:
formatted = i.replace('"__rawdata":[', "")
formatted_lines.append(formatted)
formatted_lines = formatted_lines[:-1]
total = []
distance = []
for line in formatted_lines:
x = line.replace("\n", "")[:-1]
y = x.replace("[", "").replace("]", "")
x, y, z = y.split(",")
date = x.replace("_d('", "").replace("')", "")
total.append(date + "," + z)
distance.append(z)
f = open(filename + "_formatted.csv", "w")
for i in total:
f.write(i.strip() + "\n")
f.close()
f = open(filename + "_formatted_distance_only.txt", "w")
for i in distance:
f.write(i + "\n")
f.close()