-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsystemsFileReading.py
More file actions
34 lines (31 loc) · 1.2 KB
/
systemsFileReading.py
File metadata and controls
34 lines (31 loc) · 1.2 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
import json
with open("../../Downloads/ALL/galaxy_1month/galaxy_1month.json", 'r') as allSystemsFile:
numOfLine = 0
maxNumOfStars = 0
prevNumOfLine= 1
for line in allSystemsFile:
numOfLine += 1
if numOfLine > 1:
try:
jsonObj = json.loads('{ "info":' + line + '"empty":0}')
except:
print(numOfLine)
print(line)
continue
name = jsonObj["info"]["name"]
bodies = jsonObj["info"]["bodies"]
numOfStars = 0
for body in bodies:
if body["type"] == 'Star':
numOfStars += 1
if numOfStars == maxNumOfStars:
with open("systems2.txt", 'a') as systemsFile:
systemsFile.write(name + ' $' + str(numOfStars) + '$\n')
if numOfStars > maxNumOfStars:
maxNumOfStars = numOfStars
print(maxNumOfStars, numOfLine)
with open("systems2.txt", 'w') as systemsFile:
systemsFile.write(name + ' $' + str(numOfStars) + '$\n')
if numOfLine == prevNumOfLine*2:
prevNumOfLine*=2
print(numOfLine)