def main(cursor): # Get team Id team_id = int(common.get_val('team', 0)) post_output = common.get_val('post_output', '') auto_jump = int(common.get_val('auto_jump', 0)) recache = common.get_val('recache', 1) ajax = common.get_val('ajax', 0) output = [] if team_id < 1: raise Exception("No team selected") the_world = spy_world.Spy_world(cursor) the_team = the_world.teams()[team_id] md5_name = team_f.team_hash(the_team.name) if not recache: try: f = open('%sspyrep_%s.html' % (common.data['cache_path'], md5_name)) content = f.read() f.close() return '''<a href="web.py?mode=spyrep&team=%d&recache=True" class="block_link">Recache</a>%s''' % (team_id, content) except IOError as e: pass except Exception as e: raise # Start of output related stuff js = spyrep_f.javascript(the_team) headers = common.headers("%s spy reports" % the_team.name, local_path=True, javascript=js) footers = common.footers(the_team) report_output = spyrep_f.make_report(the_world, the_team) if ajax: output.append(headers) # else: output.append(js) output.append(report_output) if ajax: output.append(footers) output.append("</div>") output = "".join(output) # If we can't cache it, no big deal try: f = open('%sspyrep_%s.html' % (common.data['cache_path'], md5_name), 'w') f.write(output) f.close() except Exception as e: pass # Inject a recache link here so it's not cached and thus picked up by the batch script recache_link = """<div style="padding: 5px;"> <a href="web.py?mode=spyrep&team=%(team_id)s&recache=True" class="block_link">Recache</a> <br />""" % { "team_id": team_id, } return "%s%s" % (recache_link, output)
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]'))