Exemplo n.º 1
0
def output_tmap(options, the_world=None, skip_upload=False):
	from pages.map import team_map
	
	if not the_world:
		cursor = database.get_cursor()
		the_world = world.World(cursor)
	else:
		cursor = the_world.cursor
	
	team_dict = team_q.get_real_active_teams(cursor)
	# if len(args) == 0:
	# 	team_list, team_dict = team_q.get_real_active_teams()
	# else:
	# 	team_list, team_dict = team_q.get_teams_in_list(team_list=args, by_id=False)
	
	files = {}
	# for team_id in team_dict.keys():
	for team_id in progressbar(team_dict.keys(), "Creating TMaps: ", 60, True):
		the_team = the_world.teams()[team_id]
		md5_name = team_f.team_hash(the_team.name)
		
		html_source = team_map._draw_map(cursor, team_id, build=1)
		
		f = open('%s/tmap/%s.html' % (common.data['woa_folder'], md5_name), 'w')
		f.write(html_source)
		f.write(padding)
		f.close()
		
		files['%s.html' % (md5_name)] = '%s/tmap/%s.html' % (common.data['woa_folder'], md5_name)
	
	if not skip_upload:
		upload("ftp.woarl.com", "*****@*****.**", ftp_pass['tmap'], files, options.delay, options.verbose)
		print(database.shell_text('[g]Team maps uploaded[/g]'))
Exemplo n.º 2
0
def output_wh(options, the_world=None, skip_upload=False):
	from classes import wh
	
	if not the_world:
		cursor = database.get_cursor()
		the_world = world.World(cursor)
	else:
		cursor = the_world.cursor
	
	team_dict = team_q.get_real_active_teams(cursor)
	the_wh = wh.Wh(the_world.cursor, the_world)
	the_wh.setup(true_team_list=team_dict.keys())
	
	files = {}
	for team_id in progressbar(team_dict.keys(), "Creating WHs: ", 60, True):
		try:
			the_team = the_world.teams()[team_id]
			md5_name = team_f.team_hash(the_team.name)
			
			output = the_wh.make_wh(team_id)
			
			f = open('%s/wh/%s.html' % (common.data['woa_folder'], md5_name), 'w')
			f.write(output)
			f.write(padding)
			f.close()
			
			files['%s.html' % (md5_name)] = '%s/wh/%s.html' % (common.data['woa_folder'], md5_name)
		
		except Exception as e:
			print("Team name: %s" % the_team.name)
			raise
	
	if not skip_upload:
		upload("ftp.woarl.com", "*****@*****.**", ftp_pass['wh'], files, options.delay, options.verbose)
		print(database.shell_text('[g]War helpers uploaded[/g]'))
Exemplo n.º 3
0
def main(cursor):
	team_id = int(common.get_val("team", 0))
	default_border = int(common.get_val("default_border_state", 0))
	
	team_dict = team_q.get_real_active_teams(cursor, skip_irs=False)
	the_team = team_dict[team_id]
	
	queries = [
		"DELETE FROM team_borders WHERE host = %d" % team_id,
		"UPDATE teams SET default_borders = %d WHERE id = %d;" % (default_border, team_id),
	]
	insertions = []
	
	# Get a list of states
	for t, other_team in team_dict.items():
		if t == the_team.id: continue
		
		state = int(common.get_val("border_state_%d" % t, -1))
		if state >= 0:
			insertions.append("(%d, %d, %d)" % (team_id, t, state))
	
	# Add insertions to list
	if len(insertions) > 0:
		queries.append("INSERT INTO team_borders (host, visitor, state) values %s;" % ",".join(insertions))
		
	# print("")
	# print(common.print_post_data())
	# print("<br /><br />")
	# print("<br />".join(queries))
	# exit()
	
	database.query(cursor, queries)
	
	page_data['Redirect'] = 'view_borders&team={0:d}'.format(team_id)
	return ""
Exemplo n.º 4
0
Arquivo: di.py Projeto: Teifion/Rob3
def main(cursor):
	team_dict = team_q.get_real_active_teams(cursor)
	deity_dict = deity_q.get_all_deities(cursor)
	
	team_q.mass_get_team_deities(cursor, team_dict)
	
	# Stores lists of teams
	deities = {}
	
	# Make blank lists
	for d in deity_dict.keys():
		deities[d] = []
	
	# Find out who follows who
	for t, the_team in team_dict.items():
		for d, v in the_team.deities.items():
			deities[d].append(the_team.name)
	
	output = []
	for d, the_deity in deity_dict.items():
		if len(deities[d]) == 0: continue
		
		# Deity name and follower list
		if len(deities[d]) > 1:
			output.append("[b]%s[/b] %s followers (%s)" % (the_deity.name, len(deities[d]), ", ".join(deities[d])))
		else:
			output.append("[b]%s[/b] 1 follower (%s)" % (the_deity.name, deities[d][0]))
		
		output.append("Objective: %s" % the_deity.objective)
		output.append("DI: %s" % the_deity.di)
		output.append("Chosen follower: \n")
	
	return '&nbsp;<textarea rows="40" style="width:99%%;">%s</textarea>' % "\n".join(output)
Exemplo n.º 5
0
def open_results(cursor):
	from pages import common
	team_dict = team_q.get_real_active_teams(cursor)

	for team_id, the_team in team_dict.items():
		if the_team.results_topic > 0:
			cmd = "open http://woarl.com/board/viewtopic.php?t={topic}".format(
				topic = the_team.results_topic,
			)
			os.system(cmd)
Exemplo n.º 6
0
def open_int_orders(cursor):
	from pages import common
	team_dict = team_q.get_real_active_teams(cursor)
	
	for team_id, the_team in team_dict.items():
		# time.sleep(0.25)
		
		if the_team.intorders_topic > 0:
			cmd = "open http://localhost/rob3/web.py?mode=view_intorders\\&turn={turn}\\&team={team}\\&topic_id={topic}".format(
				turn = common.current_turn(),
				team = team_id,
				topic = the_team.intorders_topic,
			)
			os.system(cmd)
Exemplo n.º 7
0
def output_oh(options, the_world=None, skip_upload=False):
	from classes import oh
	
	if not the_world:
		cursor = database.get_cursor()
		the_world = world.World(cursor)
	else:
		cursor = the_world.cursor
	
	team_dict = team_q.get_real_active_teams(cursor)
	the_oh = oh.Oh(the_world.cursor, the_world)
	the_oh.setup(true_team_list=team_dict.keys())
	# if len(args) == 0:
	# 	team_list, team_dict = team_q.get_real_active_teams()
	# else:
	# 	team_list, team_dict = team_q.get_teams_in_list(team_list=args, by_id=False)
	
	files = {}
	# for team_id in team_dict.keys():
	for team_id in progressbar(team_dict.keys(), "Creating OHs: ", 60, True):
		try:
			the_team = the_world.teams()[team_id]
			md5_name = team_f.team_hash(the_team.name)
			
			# # Start of output related stuff
			# headers = ti_f.headers(the_team)
			# footers = ti_f.footers(the_team)
			# js = ti_f.javascript(the_team)
			
			output = the_oh.make_oh(team_id)
		
			f = open('%s/orders/%s.html' % (common.data['woa_folder'], md5_name), 'w')
			# f.write("".join([headers, output, footers]))
			f.write(output)
			f.write(padding)
			f.close()
			
			files['%s.html' % (md5_name)] = '%s/orders/%s.html' % (common.data['woa_folder'], md5_name)
		
		except Exception as e:
			print("Team name: %s" % the_team.name)
			raise
	
	if not skip_upload:
		upload("ftp.woarl.com", "*****@*****.**", ftp_pass['orders'], files, options.delay, options.verbose)
		print(database.shell_text('[g]Order helpers uploaded[/g]'))
Exemplo n.º 8
0
def output_ti(options, the_world=None, skip_upload=False):
	from functions import ti_f
	
	if not the_world:
		cursor = database.get_cursor()
		the_world = spy_world.Spy_world(cursor)
	else:
		cursor = the_world.cursor
	
	the_world.prep_for_ti()
	
	team_dict = team_q.get_real_active_teams(cursor)
	# if len(args) == 0:
	# 	team_dict = team_q.get_real_active_teams(cursor)
	# else:
	# 	team_dict = team_q.get_teams_in_list(cursor, team_list=args, by_id=False)
	
	files = {}
	for team_id in progressbar(team_dict.keys(), "Creating TIs: ", 60, True):
	# for team_id in team_dict.keys():
		try:
			the_team = the_world.teams()[team_id]
			md5_name = team_f.team_hash(the_team.name)
			
			# Start of output related stuff
			headers = ti_f.headers(the_team)
			footers = ti_f.footers(the_team)
			js = ti_f.javascript(the_team)
			
			output = ti_f.make_ti(cursor, the_world, the_team)
		
			f = open('%s/ti/%s.html' % (common.data['woa_folder'], md5_name), 'w')
			f.write("".join([headers, output, footers]))
			f.write(padding)
			f.close()
			
			files['%s.html' % (md5_name)] = '%s/ti/%s.html' % (common.data['woa_folder'], md5_name)
		
		except Exception as e:
			print("Team name: %s" % the_team.name)
			raise
	
	if not skip_upload:
		upload("ftp.woarl.com", "*****@*****.**", ftp_pass['ti'], files, options.delay, options.verbose)
		print(database.shell_text('[g]Team Infos uploaded[/g]'))
Exemplo n.º 9
0
def main(cursor):
	team_dict = team_q.get_real_active_teams(cursor, skip_irs=False)
	relations = team_q.get_relations(cursor)
	
	output = []
	
	# Now the actual set of borders
	output.append('''
	<div style="overflow: scroll;">
		<table border="0" cellspacing="0" cellpadding="5" style="width:100%; overflow: scroll;">
			<tr class='row2'>
				<th>&nbsp;</th>''')
	
	for t1, team1 in team_dict.items():
		output.append('<th>%s</th>' % team1.name[0:6])
	
	output.append('</tr>')
	
	# Data
	i = 1
	for t1, team1 in team_dict.items():
		i += 1
		output.append("<tr class='row%d'><td style='font-weight:bold;'>%s</td>" % (i % 2, team1.name[0:15]))
		
		for t2, team2 in team_dict.items():
			if t1 == t2:
				output.append('<td>&nbsp;</td>')
				continue
			
			output.append("""
			<td style="padding:0px;">
				<a class="block_link" href="web.py?mode=edit_relations&amp;t1={t1}&amp;t2={t2}">{other}</a>
			</td>
			""".format(
				other = team2.name[0:5],
				t1 = t1,
				t2 = t2,
			))
	
	# Close form
	output.append("</table></div>")
	return "".join(output)
Exemplo n.º 10
0
def output_json_ti(options, the_world=None, skip_upload=False):
	from json_lib import ti_j
	
	if not the_world:
		cursor = database.get_cursor()
		the_world = spy_world.Spy_world(cursor)
	else:
		cursor = the_world.cursor
	
	the_world.prep_for_ti()
	
	team_dict = team_q.get_real_active_teams(cursor)
	
	files = {}
	for team_id in progressbar(team_dict.keys(), "Creating JSON TIs: ", 60, True):
	# for team_id in team_dict.keys():
		try:
			the_team = the_world.teams()[team_id]
			md5_name = team_f.team_hash(the_team.name)
			
			# Make actual output
			output = ti_j.make_ti(the_world, the_team)
			
			# Save to DB
			database.query(cursor, ti_f.save_json(team_id, output))
			
			# Save to file
			with open('%s/ti_%s.json' % (common.data['cache_path'], md5_name), 'w') as f:
				f.write(output)
				f.write(padding)
			
			files['%s.json' % (md5_name)] = '%s/ti_%s.json' % (common.data['cache_path'], md5_name)
		
		except Exception as e:
			print("Team name: %s" % the_team.name)
			raise
	
	if not skip_upload:
		upload("ftp.woarl.com", "*****@*****.**", ftp_pass['ti'], files, options.delay, options.verbose)
		print(database.shell_text('[g]Json team infos uploaded[/g]'))
Exemplo n.º 11
0
def check_unit_ownership(cursor, verbose):
	team_dict = team_q.get_real_active_teams(cursor, skip_irs=False)
	
	# First we find the squads owned by a team that the army is not
	alert_list = []
	delete_list = []
	query = """SELECT s.id, s.team, s.amount
		FROM squads s, armies a
			WHERE s.army = a.id AND s.team != a.team"""
	try: cursor.execute(query)
	except Exception as e:
		raise Exception("Database error: %s\nQuery: %s" % (str(e.args[0]).replace("\n",""), query))
	for row in cursor:
		if row['amount'] > 0:
			if row['team'] not in team_dict:
				delete_list.append(str(row['id']))
			else:
				alert_list.append(str(row['id']))
		else:
			delete_list.append(str(row['id']))
	
	if len(delete_list) > 0:
		query = """DELETE FROM squad_battle_history WHERE squad in (%s)""" % ",".join(delete_list)
		try: cursor.execute(query)
		except Exception as e:
			raise Exception("Database error: %s\nQuery: %s" % (str(e.args[0]).replace("\n",""), query))
		
		query = """DELETE FROM squads WHERE id in (%s)""" % ",".join(delete_list)
		try: cursor.execute(query)
		except Exception as e:
			raise Exception("Database error: %s\nQuery: %s" % (str(e.args[0]).replace("\n",""), query))
			
		if verbose:
			print("military_check.check_unit_ownership deleted %d squads" % len(delete_list))
			
	
	if len(alert_list) > 0:
		print("Found squads that we can't delete")
		print(alert_list)
Exemplo n.º 12
0
Arquivo: cli.py Projeto: Teifion/Rob3
def find_requests(options):
	from queries import team_q
	from functions import request_f
	cursor = database.get_cursor()
	
	team_dict = team_q.get_real_active_teams(cursor)
	topic_list = []
	lookup = {}
	for k, v in team_dict.items():
		if v.request_topic > 0:
			topic_list.append(str(v.request_topic))
			lookup[str(v.request_topic)] = v.id
	
	topic_list = ",".join(topic_list)
	# print(topic_list)
	getter_data = "p=%s&mode=find_request_topics&topic_list=%s" % (common.data['getterPass'], topic_list)
	
	topics_to_read = urllib.request.urlopen(common.data['getter_url'], getter_data).read().strip().decode('utf-8')
	
	topic_list = topics_to_read.split("\n")
	
	if len(topic_list) < 1:
		if options.verbose:
			print(database.shell_text("No requests found"))
		return
	
	teams_to_read = []
	for t in topic_list:
		if t == '': continue
		teams_to_read.append(lookup[t])
	
	for t in teams_to_read:
		print(request_f.msn_run_orders(database.get_cursor(), t))
		time.sleep(options.delay)
	
	if options.verbose:
		print(database.shell_text("[g]Ran %d requests[/g]" % len(teams_to_read)))
Exemplo n.º 13
0
	def _setup_grid(self, cursor):
		self.check_size()
		
		# Teams
		self.team_dict = team_q.get_real_active_teams(cursor, skip_irs=False)
		
		# Cities
		self.city_dict = city_q.get_cities_for_map(cursor,
			left=self.left, top=self.top, right=self.right, bottom=self.bottom)
		
		# Buildings
		self.building_dict = building_q.get_all_buildings(cursor)
		
		# Very small saving
		city_q.mass_get_city_buildings(cursor, self.city_dict)
		
		# Huge time saving on this one
		city_f.mass_city_wall_check(cursor, self.city_dict)
		
		# Wonders
		self.wonder_dict = wonder_q.get_all_wonders(cursor)
		
		# Artefacts
		self.artefact_dict = artefact_q.get_all_artefacts(cursor)
		
		# Cache things so we don't need to iterate through all cities
		self.cities_with_wonder = []
		self.cities_with_artefact = []
		
		for k, v in self.wonder_dict.items():
			self.cities_with_wonder.append(v.city)
		
		for k, v in self.artefact_dict.items():
			self.cities_with_artefact.append(v.city)
		
		self.cities_with_wonder = set(self.cities_with_wonder)
		self.cities_with_artefact = set(self.cities_with_artefact)
Exemplo n.º 14
0
def get_all_live_units(cursor):
	team_list = list(team_q.get_real_active_teams(cursor, skip_irs = True).keys())
	team_list.append(1)
	
	return _unit_query(cursor, where="team in (%s)" % ",".join([str(t) for t in team_list]))
Exemplo n.º 15
0
def main(cursor):
	team_dict = team_q.get_real_active_teams(cursor)
	
	# Caching
	team_q.mass_get_team_resources(cursor, team_dict)
	
	# Defaults
	largest_army_id			= -1
	largest_army_size		= -1
	
	largest_navy_id			= -1
	largest_navy_size		= -1
	
	most_materials_id		= -1
	most_materials_size		= -1
	
	most_population_id		= -1
	most_population_size	= -1
	
	most_slaves_id			= -1
	most_slaves_size		= -1
	
	most_mages_id			= -1
	most_mages_size			= -1
	
	most_operatives_id		= -1
	most_operatives_size	= -1
	
	most_land_id			= -1
	most_land_size			= -1
	
	for t, the_team in team_dict.items():
		#	LARGEST ARMY?
		#------------------------
		size = team_q.get_army_size(cursor, the_team.id)
		if size > largest_army_size:
			largest_army_size	= size
			largest_army_id		= t
	
		#	LARGEST NAVY?
		#------------------------
		size = team_q.get_navy_size(cursor, the_team.id)
		if size > largest_navy_size:
			largest_navy_size	= size
			largest_navy_id		= t
		
		#	RICHEST NATION
		#------------------------
		if the_team.resources.get("Materials") > most_materials_size:
			most_materials_size	= the_team.resources.get("Materials")
			most_materials_id	= t
		
		#	LARGEST POPULATION
		#------------------------
		if the_team.get_population(cursor) > most_population_size:
			most_population_size	= the_team.get_population(cursor)
			most_population_id		= t
		
		#	MOST SLAVES
		#------------------------
		if the_team.get_slaves(cursor) > most_slaves_size:
			most_slaves_size	= the_team.get_slaves(cursor)
			most_slaves_id		= t
		
		#	MOST MAGES
		#------------------------
		size = team_q.get_mage_count(cursor, the_team.id)
		if size > most_mages_size:
			most_mages_size	= size
			most_mages_id	= t
		
		#	MOST OPERATIVES
		#------------------------
		if the_team.operative_count(cursor) > most_operatives_size:
			most_operatives_size	= the_team.operative_count(cursor)
		most_operatives_id	= t
	
		#	LAND CONTROLLED
		#------------------------
		stat_f.check_team_stats(cursor, the_team)
		team_stats = the_team.get_stats(cursor)
		
		if team_stats[common.current_turn()].land_controlled > most_land_size:
			most_land_size	= team_stats[common.current_turn()].land_controlled
			most_land_id	= t
	
	# Formatting
	largest_army_size = common.number_format(largest_army_size)
	largest_navy_size = common.number_format(largest_navy_size)
	
	most_materials_size = common.number_format(int(most_materials_size))
	
	most_population_size = common.number_format(most_population_size)
	most_slaves_size = common.number_format(most_slaves_size)
	
	most_mages_size = common.number_format(most_mages_size)
	most_operatives_size = common.number_format(most_operatives_size)
	
	most_land_size = round(most_land_size, 2)
	
	output = []
	the_world = world.World(cursor)
	for t, the_team in team_dict.items():
		output.append("\n\t%s" % the_team.name)
	
		# Military
		if largest_army_id == t: output.append("1: Largest army (%s)" % largest_army_size)
		if largest_navy_id == t: output.append("1: Largest navy (%s)" % largest_navy_size)
	
		# Resources
		if most_materials_id == t: output.append("1: Richest nation (%s)" % most_materials_size)
	
		produced_resources, new_resources = team_rules.produce_resources(cursor, the_team, the_world)
		
		if new_resources.get("Iron") > 0 and new_resources.get("Stone") > 0 and new_resources.get("Wood") > 0:
			output.append("2: Own a supply of each resource")
	
		# Population
		if most_population_id == t: output.append("1: Most population (%s)" % most_population_size)
		if most_slaves_id == t: output.append("1: Most slaves (%s)" % most_slaves_size)
	
		# Special units
		if most_mages_id == t: output.append("1: Most mages (%s)" % most_mages_size)
		if most_operatives_id == t: output.append("1: Most operatives (%s)" % most_operatives_size)
	
		# Land controlled
		if most_land_id == t: output.append("1: Most land controlled (%s)" % most_land_size)
	
		#	campaigns
		#------------------------
		campaign_dict = campaign_q.get_campaigns_from_team(cursor, t, include_secret=True, since_turn=common.current_turn()-4)
		
		team_war_count = 0
		team_campaign_dict = {}
		
		# if t == 71:
		# 	print("")
		# 	for k, v in campaign_dict.items():
		# 		print(v.name, " - ", v.turn, "<br />")
		
		if campaign_dict != ([], {}):
			for k, the_campaign in campaign_dict.items():
				team_campaign_dict[the_campaign.turn] = True
			
			if len(team_campaign_dict) == 1:
				output.append("1: Only one year with a war")
			
			elif len(team_campaign_dict) > 1:
				output.append("%s: %s years with wars" % (len(team_campaign_dict), len(team_campaign_dict)))
		
		
		
		# Roleplay?
		output.append("? 1: Good roleplay")
	
	return '&nbsp;<textarea rows="40" style="width:99%%;">%s</textarea>' % "\n".join(output)
Exemplo n.º 16
0
def main(cursor):
	team_id = int(common.get_val('team', 0))
	if team_id < 1: return "No team selected"
	
	team_dict = team_q.get_real_active_teams(cursor, skip_irs=False)
	the_team = team_dict[team_id]
	
	borders = team_q.get_relations(cursor)
	team_borders = borders[team_id]
	
	# Find our default
	state_find = 'value="%s"' % the_team.default_borders
	
	# What to replace it with
	state_replace = '%s selected="selected"' % state_find
	
	output = ["""
	<form action="exec.py" method="post" accept-charset="utf-8" style="padding:5px;">
	<span class="stitle">Borders for {team.name}</span><br /><br />
		<input type="hidden" name="mode" id="mode" value="edit_borders" />
		<input type="hidden" name="team" id="team" value="{team.id}" />
		""".format(
			team=the_team,
		)]
	
	# Now the actual set of borders
	output.append('''
	Default border state:&nbsp;&nbsp;
	<select name="default_border_state" id="default_border_state">
		{states}
	</select>
	<br /><br />

	<table border="0" cellspacing="0" cellpadding="5">
		<tr>
			<th>Team</th>
			<th>{team.name} state</th>
			<th>Their state</th>
		</tr>'''.format(
		states	= states.replace('<option value="-1">Default</option>', '').replace(state_find, state_replace),
		team	= the_team,
	))
	
	for t, other_team in team_dict.items():
		if t == the_team.id: continue
		# if other_team.hidden: continue
		# if not other_team.active: continue
		
		ir = ""
		if other_team.ir:
			ir = " <em>(IR)</em>"
		
		other_team_borders = borders[t].get(the_team.id, {}).get('border', other_team.default_borders)
		other_default_borders = other_team.default_borders
		
		# print(other_team_borders)
		
		# The state to find
		# state_find = 'value="%s"' % team_borders.get(t, default_borders)
		
		if t in team_borders:	default_state = team_borders[t]
		else:					default_state = "-1"
		
		state_find = 'value="%s"' % default_state
		
		# What to replace it with
		state_replace = '%s selected="selected"' % state_find
		
		# Their state to you
		# if the_team.id in other_team_borders:
		# 	other_state = team.border_states[other_team_borders[the_team.id]]
		# else:
		# 	other_state = team.border_states[other_default_borders]
		other_state = other_team_borders
		
		output.append("""
		<tr>
			<td>%(name)s%(ir)s</td>
			<td>
				<select name="border_state_%(t)d" id="border_state_%(t)d">
					%(states)s
				</select>
			</td>
			<td>&nbsp;&nbsp;
				<span style="color:#%(other_state_c)s;">%(other_state)s</span>
			</td>
		</tr>
		""" % {
			"t":				t,
			"ir":				ir,
			"name":				other_team.name,
			"states":			states.replace(state_find, state_replace),
			"other_state":		team.border_states[other_state],
			"other_state_c":	team.border_colour(other_state),
		})
	
	
	# Close form
	output.append("""</table>
		<input type="submit" value="Save" />
	</form>""".format(
		team=team_id
	))
	
	
	return "".join(output)
Exemplo n.º 17
0
def output_spyrep(options, the_world=None, skip_upload=False):
	from classes import spy_world
	from functions import spyrep_f
	
	if not the_world:
		cursor = database.get_cursor()
		the_world = spy_world.Spy_world(cursor)
	else:
		cursor = the_world.cursor
	
	team_dict = team_q.get_real_active_teams(cursor)
	# if len(args) == 0:
	# 	team_list, team_dict = team_q.get_real_active_teams()
	# else:
	# 	team_list, team_dict = team_q.get_teams_in_list(team_list=args, by_id=False)
	
	files = {}
	# for team_id in team_dict.keys():
	for team_id in progressbar(team_dict.keys(), "Creating Spy reps: ", 60, True):
		try:
			the_team = the_world.teams()[team_id]
			md5_name = team_f.team_hash(the_team.name)
			content = ""
			
			try:
				f = open('%sspyrep_%s.html' % (common.data['cache_path'], md5_name))
				content = f.read()
				f.close()
			except IOError as e:
				pass
			except Exception as e:
				raise
			
			if content == "":
				content = spyrep_f.make_report(the_world, the_team)
			
			# Start of output related stuff
			js = spyrep_f.javascript(the_team)
			headers = common.headers("%s spy reports" % the_team.name, local_path=False, javascript=js)
			footers = common.footers(the_team)
			
			html_content = "".join([headers, "<br />", content, footers])
			
			# Try to cache it
			try:
				f = open('%sspyrep_%s.html' % (common.data['cache_path'], md5_name), 'w')
				f.write(content)
				f.close()
			except Exception as e:
				pass
			
			# Save for upload
			f = open('%s/spyrep/%s.html' % (common.data['woa_folder'], md5_name), 'w')
			f.write(html_content)
			f.write(padding)
			f.close()
			files['%s.html' % (md5_name)] = '%s/spyrep/%s.html' % (common.data['woa_folder'], md5_name)
		
		except Exception as e:
			print("Team name: %s" % the_team.name)
			raise
	
	if not skip_upload:
		upload("ftp.woarl.com", "*****@*****.**", ftp_pass['spyrep'], files, options.delay, options.verbose)
		print(database.shell_text('[g]Spy reports uploaded[/g]'))
Exemplo n.º 18
0
def main(cursor):
	show_dead_teams		= common.get_val('show_dead')
	show_unqueued_teams	= common.get_val('show_unqueued')
	
	# Get the turn we'll want to get stuff for
	current_turn = common.current_turn()
	
	# Get our list
	team_dict = team_q.get_real_active_teams(cursor, skip_irs=True)
	
	output = []
	
	output.append("""
	<table border="0" cellspacing="0" cellpadding="5">
		<tr class="row2">
			<th>Team</th>
			<th>Materials</th>
			<th>Food</th>
			<th>Morale</th>
		</tr>""")
	
	count = -1
	for team_id, the_team in team_dict.items():
		count += 1
		
		team_res = the_team.get_resources(cursor)
		
		# TODO - Make it work out the material requirements correctly
		# Materials
		material_amount = int(team_res.get("Materials"))
		if material_amount < 0:
			material_style = "background-color:#AAA;color:#A00; font-weight:bold;"
			if material_amount < -200:
				material_style = "background-color:#000;color:#F00; font-weight:bold;"
		else:
			material_style = ""
		
		# Food
		food_amount = int(team_res.get("Food"))
		needed = team_rules.resource_needed(cursor, "Food", the_team)
		food_ratio = round(food_amount/float(needed), 2)
		
		if food_ratio < 1:
			food_style = "background-color:#AAA;color:#A00; font-weight:bold;"
			if food_ratio < 0.75:
				food_style = "background-color:#000;color:#F00; font-weight:bold;"
		else:
			food_style = ""
			if food_ratio > 1.5:
				food_style = "background-color:#AFA;color:#000; font-weight:bold;"
		
		output.append("""
		<tr class="row%(row)d" id="%(team_id)d">
			<td>%(name)s</td>
			<td style="%(material_style)s">%(materials)s</td>
			<td style="%(food_style)s">%(food)s</td>
			<td>%(morale)s</td>
		</tr>
		""" % {
				'row': (count % 2),
				'board_url': common.data['board_url'],
				
				'team_id':			the_team.id,
				'name':		the_team.name,
				"materials":		material_amount,
				"material_style":	material_style,
				"food":				food_ratio,
				"food_style":		food_style,
				
				"morale":			team_rules.define_nation_morale(team_rules.nation_morale(cursor, the_team)),
		})
	
	output.append("</table>")
	
	return "".join(output)
Exemplo n.º 19
0
def _draw_map(cursor, build, centre, centre_radius):
	the_map = mapper.Map_maker()
	the_map.gm = True
	the_map.personalise = []
	for t in team_q.get_real_active_teams(cursor, skip_irs=False).keys():
		the_map.personalise.append(t)
	
	if centre != "":
		centre = centre.split(",")
		the_map.centre = (int(centre[0]), int(centre[1]))
		
		if centre_radius > 0:
			the_map.centre_radius = centre_radius
	
	if build != 0:# Remote mode
		the_map.icon_path = 'images/teamIcons/'
	
	onclick_js = """
	var map_x = parseInt(document.getElementById('labelHideX').innerHTML);
	var map_y = parseInt(document.getElementById('labelHideY').innerHTML);
	
	use_map_xy(map_x, map_y);"""
	
	# new_mode is used when we want to select a location for something
	new_mode = common.get_val('new_mode', "")
	new_mode_form_fields = ""
	
	if new_mode == "edit_city":
		new_mode_form_fields = '<input type="hidden" name="city" value="%s" />' % int(common.get_val('city', ""))
		map_click_handler = "$('#new_mode_form').submit();"
	
	elif new_mode == "edit_army":
		new_mode_form_fields = '<input type="hidden" name="army" value="%s" />' % int(common.get_val('army', ""))
		map_click_handler = "$('#new_mode_form').submit();"
	
	elif new_mode =="list_armies" or new_mode =="list_cities":
		new_mode_form_fields = '<input type="hidden" name="team" value="%s" />' % int(common.get_val('team', ""))
		map_click_handler = "$('#new_mode_form').submit();"
	
	elif new_mode == "edit_battle":
		new_mode_form_fields = '<input type="hidden" name="battle" value="%s" />' % int(common.get_val('battle', ""))
		map_click_handler = "$('#new_mode_form').submit();"
	
	else:
		if new_mode != '':
			print("No handler for new_mode of '%s' in web.map.view_map" % new_mode)
			exit()
	
	source_dict = {
		"build":				build,
		"onclick_js":			onclick_js,
		
		"new_mode":				new_mode,
		# "map_click_handler":	map_click_handler,
		"new_mode_form_fields": new_mode_form_fields,
		
		"output":				the_map.map_grid(cursor),
		"title":				"GM Map",
	}
	
	if centre != "":
		source_dict['map_legend']	= ''
		
		source_dict["left"]			= the_map.left
		source_dict["right"]		= the_map.right
		source_dict["top"]			= the_map.top
		source_dict["bottom"]		= the_map.bottom
		
		source_dict["map_width"]	= the_map.width*2.5
		source_dict["map_height"]	= the_map.height*2.5
		
		x_diff = map_data.dimensions['left'] - the_map.left
		y_diff = map_data.dimensions['top'] - the_map.top
		source_dict["margin_left"]	= (x_diff + map_data.dimensions['margin_left'])*2.5
		source_dict["margin_top"]	= (y_diff + map_data.dimensions['margin_top'])*2.5
		
	try:
		if map_click_handler:
			source_dict['map_click_handler'] = map_click_handler
	except Exception:
		pass
	
	return mapper.map_source(source_dict)