forked from cwren/davesgalaxy
-
Notifications
You must be signed in to change notification settings - Fork 2
/
listfleets
executable file
·48 lines (41 loc) · 1.12 KB
/
listfleets
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
#!/usr/bin/env python
# vim: set ts=2 sw=2 expandtab:
import game
from optparse import OptionParser
import sys
import types
parser = OptionParser()
parser.add_option("-U", "--username", dest="username",
help="username of login")
parser.add_option("-P", "--password", dest="password",
help="password for login")
(options, args) = parser.parse_args()
g=game.Galaxy()
if options.username and options.password:
# explicit login
g.login(options.username, options.password, force=True)
else:
# try to pick up stored credentials
g.login()
def dictstr(d):
return "(" + " ".join(
"%s=%s" % (str(k),str(v)) for (k,v) in d.items()) + ")"
print 'ID, Disposition, Coords, Destination, Ships'
count = 0
for f in g.fleets:
if f.load():
count += 1
if (count % 100) == 0:
g.write_fleet_cache()
dest = f.destination
if type(dest) in (types.ListType, types.TupleType):
dest = '(%.1f,%.1f)' % tuple(dest)
else:
dest = str(dest)
print '%d %s (%.1f,%.1f)-->%s %s' % (
f.fleetid, f.disposition,
f.coords[0], f.coords[1],
dest,
dictstr(f.ships)
)
g.write_fleet_cache()