forked from cwren/davesgalaxy
-
Notifications
You must be signed in to change notification settings - Fork 2
/
saveempire
executable file
·92 lines (80 loc) · 2.56 KB
/
saveempire
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
87
88
89
90
91
92
#!/usr/bin/env python
# vim: set ts=2 sw=2 expandtab:
import json
from optparse import OptionParser
import os
import sys
import game
parser = OptionParser()
parser.add_option("-U", "--username", dest="username",
help="username of login")
parser.add_option("-P", "--password", dest="password",
help="password for login")
parser.add_option("-o", "--outdir", dest="outdir",
help="directory for sector data",
default='sectors')
(options, args) = parser.parse_args()
outdir = os.path.join(os.curdir, options.outdir)
try:
os.makedirs(outdir)
except OSError:
pass
resourcedir = os.path.join(outdir, 'site')
print resourcedir
try:
os.makedirs(resourcedir)
except OSError:
pass
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()
RESOURCES = [
'http://davesgalaxy.com/view/',
'http://davesgalaxy.com/site_media/jquery-1.4.2.min.js',
'http://davesgalaxy.com/site_media/jquery.color.utils.js',
'http://davesgalaxy.com/site_media/farbtastic.js',
'http://davesgalaxy.com/site_media/dg.18.js',
'http://davesgalaxy.com/site_media/QuadTree.js',
'http://davesgalaxy.com/site_media/jquery.countdown.pack.js',
'http://davesgalaxy.com/site_media/jquery.easing.1.3.js',
'http://davesgalaxy.com/site_media/jquery.hoverIntent.minified.js',
'http://davesgalaxy.com/site_media/jquery.bt.js',
'http://davesgalaxy.com/site_media/jquery.numeric.js',
'http://davesgalaxy.com/site_media/jquery-ui-1.8.4.custom.min.js',
'http://davesgalaxy.com/site_media/jquery.countdown.css',
'http://davesgalaxy.com/site_media/farbtastic.css',
'http://davesgalaxy.com/site_media/jquery.bt.css',
'http://davesgalaxy.com/site_media/dg.4.css'
]
for url in RESOURCES:
print url
file = url.split('/')[-1]
if len(file) == 0:
file ='index.html'
path = os.path.join(resourcedir, file)
resource_file = open(path, 'w')
req = g.opener.open(url)
response = req.read()
resource_file.write(response)
resource_file.close()
count = 0
sectors = {}
for p in g.planets:
x = int(p.location[0])/5
y = int(p.location[1])/5
for i in range(-1,2):
for j in range(-1,2):
sid = (x+i) * 1000 + (y+j)
sectors[sid] = p.location
for sid, location in sectors.iteritems():
print sid
filename = '%s.json' % sid
path = os.path.join(options.outdir, filename)
sector = g.load_raw_sector_at(location)
sector_file = open(path, 'w')
sector_file.write(sector)
sector_file.close()