forked from cwren/davesgalaxy
-
Notifications
You must be signed in to change notification settings - Fork 2
/
checkempire
43 lines (38 loc) · 1.03 KB
/
checkempire
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
#!/usr/bin/env python
import json
from optparse import OptionParser
import os
import sys
parser = OptionParser()
parser.add_option("-m", "--mine", dest="mine",
help="your owner id",
default=1, type="int")
(options, args) = parser.parse_args()
if len(args) == 0:
print 'usage: %s sectors/*.json' % sys.argv[0]
sys.exit(1)
for filename in args:
f = open(filename, 'r')
j = json.load(f)
secs = j["sectors"]["sectors"]
for secnum in secs:
planets = secs[secnum]["planets"]
for pnum in planets:
p = planets[pnum]
owner = int(p.get("o", 0))
x = float(p["x"])
y = - float(p["y"])
name = str(p["n"])
owner_name = 'nobody'
size = 0
if owner == options.mine:
owner_name = 'mine'
size = 1
elif owner != 0:
owner_name = 'theirs'
size = 0
print '%s, %d, %d, %s, %d' % (
name,
x, y,
owner_name,
size)