Ejemplo n.º 1
0
def get_stat_core(cursor, team_id, recache, ajax):
	output = []
	
	the_world = world.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('%sstat_%s.html' % (common.data['cache_path'], md5_name))
			content = f.read()
			f.close()
			return content
			return '''<a href="web.py?mode=stat&amp;team=%d&amp;recache=True" class="block_link">Recache</a>%s''' % (team_id, content)
		except IOError as e:
			pass
		except Exception as e:
			raise
	
	# Some caching stuff
	the_world.prep_for_stats()
	
	# Start of output related stuff
	headers = stat_f.headers(the_team.name, True)#common.headers("%s stats" % the_team.name, css="", javascript=stat_f.javascript, local_path=True, js_libs=[])#stat_f.headers(the_team)
	footers = common.footers()
	
	stat_output = stat_f.make_team_stats(cursor, the_world, the_team)
	
	if ajax:	output.append(headers)
	else:		output.append("""
	<script type="text/javascript" charset="utf-8">
		%s
	</script>
	""" % stat_f.javascript)
	
	output.append(stat_output)
	
	if ajax:	output.append(footers)
	
	output = "".join(output)
	
	# If we can't cache it, no big deal
	try:
		f = open('%sstat_%s.html' % (common.data['cache_path'], md5_name), 'w')
		f.write(output)
		f.close()
	except Exception as e:
		pass
	
	return output
Ejemplo n.º 2
0
def output_stats(options, the_world=None, skip_upload=False):
	from functions import stat_f
	
	if not the_world:
		cursor = database.get_cursor()
		the_world = world.World(cursor)
	else:
		cursor = the_world.cursor
	
	the_world.prep_for_stats()
	
	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 team_dict.keys():
	for team_id in progressbar(team_dict.keys(), "Creating Stats: ", 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 = stat_f.headers(the_team.name, False)
			footers = common.footers()
			
			output = stat_f.make_team_stats(cursor, the_world, the_team)
			
			f = open('%s/stats/%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/stats/%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['stats'], files, options.delay, options.verbose)
		print(database.shell_text('[g]Team stats uploaded[/g]'))