示例#1
0
文件: ti.py 项目: Teifion/Rob3
def get_ti_core(cursor, team_id, recache, ajax):
	output = []
	
	the_world = spy_world.Spy_world(cursor)
	the_team = the_world.teams()[team_id]
	md5_name = team_f.team_hash(the_team.name)
	
	# Cache it?
	if not recache:
		try:
			# f = open('%s/ti/%s.html' % (common.data['woa_folder'], md5_name))
			f = open('%sti_%s.html' % (common.data['cache_path'], md5_name))
			content = f.read()
			f.close()
			return content
			return '''<a href="web.py?mode=ti&amp;team=%d&amp;recache=True" class="block_link">Recache</a>%s''' % (team_id, content)
		except IOError as e:
			# print(e)
			pass
		except Exception as e:
			raise
	
	# Some caching stuff
	the_world.prep_for_ti()

	# Start of output related stuff
	headers = ti_f.headers(the_team)
	footers = ti_f.footers(the_team)
	js = ti_f.javascript(the_team)
	
	ti_output = ti_f.make_ti(cursor, the_world, the_team)
	
	if ajax:	output.append(headers)
	else:		output.append(js)
	
	output.append(ti_output)
	
	if ajax:	output.append(footers)
	
	output = "".join(output)
	
	# If we can't cache it, no big deal
	try:
		f = open('%sti_%s.html' % (common.data['cache_path'], md5_name), 'w')
		f.write(output)
		f.close()
	except Exception as e:
		pass
	
	return output
示例#2
0
文件: cli_f.py 项目: Teifion/Rob3
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]'))
示例#3
0
def main(cursor, options):
	the_world = world.World(cursor)
	team_dict = the_world.teams()
	
	team_list = []
	
	# Work out our team
	try:
		t = options.team
		
		if t != "":
			for t, the_team in team_dict.items():
				if the_team.name.lower() == options.team.lower():
					team_list = [t]
			
			if team_list == []:
				raise Exception()
		else:
			raise Exception()
	except Exception as e:
		team_list = [t for t in team_dict.keys() if (team_dict[t].active and not team_dict[t].ir)]
	
	# Some caching stuff
	the_world.cities()
	the_world.armies()
	the_world.players()
	the_world.units()
	
	player_q.mass_get_player_powers(cursor, the_world._players)
	
	team_q.mass_get_team_deities(cursor, the_world._teams)
	team_q.mass_get_team_spells(cursor, the_world._teams)
	team_q.mass_get_team_techs(cursor, the_world._teams)
	team_q.mass_get_team_resources(cursor, the_world._teams)
	team_q.mass_get_team_evolutions(cursor, the_world._teams)
	
	city_q.mass_get_city_buildings(cursor, the_world._cities)
	city_q.mass_get_city_artefacts(cursor, the_world._cities)
	city_q.mass_get_city_wonders(cursor, the_world._cities)
	
	unit_q.mass_get_unit_equipment(cursor, the_world._units)
	
	squad_q.mass_get_squads(cursor, the_world._armies)
	
	print("Caches setup")
	
	t_output = []
	for t in team_list:
		the_team = the_world._teams[t]
		
		headers = ti_f.headers(the_team)
		footers = ti_f.footers(the_team)
		js = ti_f.javascript(the_team)
		
		try:
			team_start = time.time()
			
			ti_output = ti_f.make_ti(cursor, the_world, the_team)
			
			output = "".join([js, ti_output])
			
			md5_name = team_f.team_hash(the_team.name)
			try:
				f = open('%sti_%s.html' % (common.data['cache_path'], md5_name), 'w')
				f.write(output)
				f.close()
			except Exception as e:
				pass
			
			t_output.append(output)
			
			print("Made for %s in %s" % (the_world._teams[t].name, round(time.time() - team_start, 3)))
		except Exception as e:
			print("Error in making TI for team '%s'" % the_world._teams[t].name)
			raise
		
	
	return "".join(t_output)