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]'))
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]'))
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)] # Setup the World the_oh = oh.Oh(the_world=the_world) the_oh.local_path = True the_oh.setup(true_team_list=team_list) print("Caches setup") t_output = [] for t in team_list: the_team = the_world._teams[t] try: team_start = time.time() output = the_oh.make_oh(t) md5_name = team_f.team_hash(the_team.name) f = open('%soh_%s.html' % (common.data['cache_path'], md5_name), 'w') f.write(output) f.close() 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 OH for team '%s'" % the_world._teams[t].name) raise return "".join(t_output)
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&team=%d&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
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&team=%d&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
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]'))
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]'))
def get_bbcode_core(cursor, team_id): the_team = team_q.get_one_team(cursor, team_id) md5_name = team_f.team_hash(the_team.name) # bbcode = "".join([headers, output, footers]) bbcode = ti_f.bbcode_ti(the_team, md5_name) ti_output = common.bbcode_to_html(bbcode) # Clean it bbcode = bbcode.replace(' ', '\\ ').replace('\n', 'NEWLINE').replace('\t', '') bbcode = bbcode.replace("'", 'APOSTRAPH').replace('&', 'AMPASAND') bbcode = bbcode.replace("(", '\\(').replace(')', '\\)') # Send it getter_data = "p=%s&mode=postUpdate&post=%d&string=%s" % (common.data['getterPass'], the_team.team_info_first_post, bbcode) result = urllib.request.urlopen(common.data['getter_url'], getter_data).read().strip() return bbcode
def update_topic_old(w): output = ["[o]Campaigns[/o]\n"] for c in w.campaigns_from_turn(turn=common.current_turn()): output.append("[url=http://woarl.com/voi/%s_%d_list_battles.html]%s[/url] - " % (tk, c, w.campaigns()[c].name)) output.append("[url=http://woarl.com/voi/%s_%d_setup_campaign.html]setup[/url]" % (tk, c)) output.append("\n") output.append("\n[o]Teams[/o]\n") for t, the_team in w.active_teams().items(): if the_team.ir: continue team_hash = team_f.team_hash(the_team.name) output.append("[url=http://woarl.com/board/viewforum.php?f=%d]%s[/url] - " % (the_team.forum_url_id, the_team.name)) output.append("[url=http://woarl.com/ti/%s.html]Team Info[/url] - " % (team_hash)) output.append("[url=http://woarl.com/board/viewtopic.php?t=%d.html]Orders[/url]" % (the_team.intorders_topic)) output.append("\n") output = "".join(output) getter_data = "p=%s&mode=postUpdate&post=%d&string=%s" % (common.data['getterPass'], voi.current_turn_post, output) result = urllib.request.urlopen(common.data['getter_url'], getter_data).read().strip()
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]'))
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 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)
def main(cursor): # Get team Id team_id = int(common.get_val('team', 0)) if team_id < 1: return "No team selected" # Build team item the_team = team_q.get_one_team(cursor, team_id) # Get some properties the_team.get_population(cursor) # Lists trait_dict = trait_q.get_all_traits(cursor) deity_dict = deity_q.get_all_deities(cursor) evolution_dict = evolution_q.get_all_evolutions(cursor) # Is the join turn set? if the_team.join_turn == 0: the_team.join_turn = common.current_turn() # First row of check_boxes output = ["<div style='padding: 5px;'>"] output.append(""" <span class="stitle">%(name)s</span> Population: %(team_population)s <br /><br /> <form action="exec.py" method="post" accept-charset="utf-8"> <input type="hidden" name="mode" id="mode" value="edit_team_commit" /> <input type="hidden" name="id" id="id" value="%(team_id)d" /> <input type="hidden" name="requestTime" id="requestTime" value="' . $the_team->requestTime . '" /> <label for="active">Active:</label> %(active_check_box)s <label for="ir">IR:</label> %(ir_check_box)s <label for="hidden">Hidden:</label> %(hidden_check_box)s <label for="not_a_team">Not a team:</label> %(not_a_team_check_box)s <label for="dead">Dead:</label> %(dead_check_box)s <label for="not_in_queue">Not in queue:</label> %(not_in_queue_check_box)s <br /> """ % { 'team_id': team_id, 'name': the_team.name, 'team_population': common.number_format(the_team.population), 'active_check_box': common.check_box('active', the_team.active), 'ir_check_box': common.check_box('ir', the_team.ir), 'hidden_check_box': common.check_box('hidden', the_team.hidden), 'not_a_team_check_box': common.check_box('not_a_team', the_team.not_a_team), 'dead_check_box': common.check_box('dead', the_team.dead), 'not_in_queue_check_box': common.check_box('not_in_queue', the_team.not_in_queue), }) # Row 1 output.append(""" <table border="0" cellspacing="5" cellpadding="5" style="width:100%%;"> <tr> <td><label for="forum_url_id">Forum URL id:</label></td> <td>%(forum_text_box)s</td> <td width="5"> </td> <td><label for="orders_topic">Orders topic:</label></td> <td>%(orders_text_box)s</td> <td width="5"> </td> <td><label for="intorders_topic">Int Orders topic:</label></td> <td>%(intorders_text_box)s</td> </tr>""" % {'forum_text_box': common.text_box('forum_url_id', the_team.forum_url_id, warn_on = lambda x:(True if x < 0 else False)), 'orders_text_box': common.text_box('orders_topic', the_team.orders_topic, warn_on = lambda x:(True if x < 0 else False)), 'intorders_text_box': common.text_box('intorders_topic', the_team.intorders_topic, warn_on = lambda x:(True if x < 0 else False)), }) # Row 2 output.append(""" <tr> <td><label for="results_topic">Results topic:</label></td> <td>{results_topic}</td> <td width="5"> </td> <td><label for="teaminfo_topic">Team info topic:</label></td> <td>{teaminfo_topic}</td> <td width="5"> </td> <td><label for="team_info_first_post">Team info first post:</label></td> <td>{team_info_first_post}</td> </tr>""".format( results_topic = common.text_box('results_topic', the_team.results_topic, warn_on = lambda x:(True if x < 0 else False)), teaminfo_topic = common.text_box('teaminfo_topic', the_team.teaminfo_topic, warn_on = lambda x:(True if x < 0 else False)), team_info_first_post = common.text_box('team_info_first_post', the_team.team_info_first_post, warn_on = lambda x:(True if x < 0 else False)), )) # Row 3 output.append(""" <tr> <td><label for="request_topic">Request topic:</label></td> <td>%(request_topic)s</td> <td width="5"> </td> <td><label for="leader_id">Leader:</label></td> <td>%(leader_id)s</td> <td width="5"> </td> <td>Culture topic:</td> <td>%(culture_topic)s</td> </tr>""" % {'leader_id': common.text_box('leader_id', the_team.leader_id, warn_on = lambda x:(True if x < 1 else False)), 'request_topic': common.text_box('request_topic', the_team.request_topic, warn_on = lambda x:(True if x < 1 else False)), 'culture_topic': common.text_box('culture_topic', the_team.culture_topic, warn_on = lambda x:(True if x < 1 else False)), }) output.append(""" <tr> <td><label for="default_borders">Default borders:</label></td> <td>%(default_borders)s</td> <td width="5"> </td> <td><label for="default_taxes">Default taxes:</label></td> <td>%(default_taxes)s</td> <td width="5"> </td> <td><label for="evo_points">Evo points:</label></td> <td>%(evo_points)s</td> </tr> <tr> <td colspan="8" style="padding:0px;border-bottom:3px #EEE double;"></td> </tr> """ % { "default_borders": common.option_box("default_borders", elements=team.border_states, selected=team.border_states[the_team.default_borders]), "default_taxes": common.text_box('default_taxes', the_team.default_taxes, warn_on = lambda x:(True if int(x) < 0 else False), size=4), "evo_points": common.text_box('evo_points', the_team.evo_points, warn_on = lambda x:(True if int(x) < 0 else False)), }) output.append(""" <!-- <tr> <td>Previous resources:</td> <td>%(previous_resources)s</td> </tr> --> """ % { "previous_resources": the_team.previous_resources, }) # End row output.append(""" <tr> <td>Join turn:</td> <td>%(join_turn)s</td> <td width="5"> </td> <td>Primary:</td> <td>%(primary_colour)s</td> <td width="5"> </td> <td>Secondary:</td> <td>%(secondary_colour)s</td> </tr> </table> <br /> <input type="submit" value="Perform edit" /> <input style="float:right; margin-right:100px;" type="button" value="Purge team" onclick="setTimeout('document.location=\\'web.py?mode=purge_team&team=%(team_id)s\\'', 0);"/> <a class="block_link" href="web.py?mode=ti&post_output=1&team=%(team_id)s">Update my TI</a> <br />""" % { "team_id": team_id, 'join_turn': common.text_box('join_turn', the_team.join_turn), 'previous_resources': common.text_box('previous_resources', the_team.previous_resources, size=56), "primary_colour": common.text_box('primary_colour', the_team.primary_colour), "secondary_colour": common.text_box('secondary_colour', the_team.secondary_colour), }) # Resources #------------------------ the_team.get_resources(cursor) output.append(""" <table style="float:left; margin-right: 25px;" border="0" cellspacing="0" cellpadding="5"> <tr class="row2"> <th>Resource</th> <th>Amount</th> </tr> """) counter = -1 for res_id, the_res in resource_list.data_dict.items(): if the_res.category == resource_list.category['Map terrain feature']: continue # If it's not set then we need to give it a default if not res_id in the_team.resources.value: the_team.resources.value[res_id] = 0 counter += 1 output.append(""" <tr class="row%(row)d"> <td><label for="res_%(res_name)s">%(res_name)s</label></td> <td style="padding:1px;">%(res_amount)s</td> </tr>""" % {'row': (counter % 2), 'res_name': the_res.name, 'res_amount': resource_f.print_form_element(res_id, the_team.resources[res_id]) }) output.append("</table></form>")# Subsequent forms are for other stuff # Deities #---------------------- the_team.get_deities(cursor) output.append(""" <table style="float:left; margin-right: 25px;" border="0" cellspacing="0" cellpadding="5"> <tr class="row2"> <th>Deity</th> <th> </th> </tr> """) counter = -1 for deity_id, team_favour in the_team.deities.items(): counter += 1 output.append(""" <tr class="row%(row)d"> <td><label for="%(name)s">%(name)s</label></td> <td style="padding: 0px;"> <a class="block_link" href="exec.py?mode=remove_deity&deity=%(deity_id)d&team=%(team_id)d">Remove</a> </td> </tr>""" % {'row': (counter % 2), 'name': deity_dict[deity_id].name, 'deity_id': deity_id, 'team_id': team_id }) output.append(""" <tr class="row%(row)d"> <form id="team_add_deity_form" action="exec.py?mode=add_deity" method="post" accept-charset="utf-8"> <input type="hidden" name="mode" value="add_deity" /> <input type="hidden" name="team" value="%(team_id)s" /> <td style="padding:1px;"> <select name="deity"> %(deity_option_box)s </select> </td> <td style="padding: 2px;"> <input type="submit" value="Add" /> <!--<a href="#" onclick="$('#team_add_deity_form').submit(); return false;" class="block_link">Add</a>--> </td> </tr> </form> </table> """ % { 'row': ((counter+1) % 2), 'team_id': the_team.id, 'deity_option_box': deity_f.deity_option_list(cursor, the_team.deities)}) # Evolutions #------------------- the_team.get_evolutions(cursor) output.append(""" <table style="float:left; margin-right: 25px;" border="0" cellspacing="0" cellpadding="5"> <tr class="row2"> <th>Evolution</th> <th> </th> <th> </th> </tr> """) counter = -1 for evo_id, evo_level in the_team.evolutions.items(): counter += 1 output.append(""" <tr class="row%(row)d"> <form id="edit_evo_%(evolution_id)s" action="exec.py" method="post" accept-charset="utf-8"> <input type="hidden" name="mode" value="set_evolution" /> <input type="hidden" name="team" value="%(team_id)s" /> <input type="hidden" name="evolution" value="%(evolution_id)s" /> <td><label for="%(name)s">%(name)s</label></td> <td style="padding:1px;"> %(text_box)s </td> </form> <td style="padding: 0px;"> <a class="block_link" href="exec.py?mode=set_evolution&evolution=%(evolution_id)d&team=%(team_id)d">Remove</a> </td> </tr>""" % {'row': (counter % 2), 'name': evolution_dict[evo_id].name, 'evolution_level': evo_level, 'evolution_id': evo_id, 'team_id': team_id, "text_box": common.text_box("evolution_level", evo_level, custom_id="", size=3, warn_on = lambda e: (True if evolution_dict[evo_id].min_level > e or e > evolution_dict[evo_id].max_level else False)), }) output.append(""" <tr class="row%(row)d"> <form id="team_add_evolution_form" action="exec.py" method="post" accept-charset="utf-8"> <input type="hidden" name="mode" value="set_evolution" /> <input type="hidden" name="team" value="%(team_id)d" /> <td style="padding:1px;"> <select name="evolution"> %(evolution_option_box)s </select> </td> <td style="padding:1px;"> %(evolution_level)s </td> <td style="padding: 0px;"> <a href="#" onclick="$('#team_add_evolution_form').submit();" class="block_link">Add</a> </td> </tr> </form> </table> """ % { 'row': ((counter+1) % 2), 'team_id': the_team.id, 'evolution_level': common.text_box('evolution_level', 0, 4), 'evolution_option_box': evolution_f.evolution_option_list(cursor, the_team.evolutions)}) # Traits #---------------------- the_team.get_traits(cursor) output.append(""" <table style="float:left; margin-right: 25px;" border="0" cellspacing="0" cellpadding="5"> <tr class="row2"> <th>Trait</th> <th> </th> </tr> """) counter = -1 for trait_id in the_team.traits: counter += 1 output.append(""" <tr class="row%(row)d"> <td><label for="%(name)s">%(name)s</label></td> <td style="padding: 0px;"> <a class="block_link" href="exec.py?mode=remove_trait&trait=%(trait_id)d&team=%(team_id)d">Remove</a> </td> </tr>""" % {'row': (counter % 2), 'name': trait_dict[trait_id].name, 'trait_id': trait_id, 'team_id': team_id }) output.append(""" <tr class="row%(row)d"> <form id="team_add_trait_form" action="exec.py?mode=add_trait" method="post" accept-charset="utf-8"> <input type="hidden" name="mode" value="add_trait" /> <input type="hidden" name="team" value="%(team_id)s" /> <td style="padding:1px;"> <select name="trait"> %(trait_option_box)s </select> </td> <td style="padding: 2px;"> <input type="submit" value="Add" /> <!--<a href="#" onclick="$('#team_add_trait_form').submit(); return false;" class="block_link">Add</a>--> </td> </tr> </form> </table> """ % { 'row': ((counter+1) % 2), 'team_id': the_team.id, 'trait_option_box': trait_f.trait_option_list(cursor, the_team.traits)}) # Hashes output.append(""" <table style="float:left; margin-right: 25px;" border="0" cellspacing="0" cellpadding="5"> <tr class="row2"> <th>Turn</th> <th>Hash</th> </tr> """) for i, t in enumerate(range(common.current_turn(), common.current_turn()-5, -1)): output.append(""" <tr class="row{i}"> <td>{t}</td> <td>{hash}</td> </tr>""".format( i = i % 2, t = t, hash = team_f.team_hash(the_team.name, turn=t), )) output.append("</table>") output.append("</div>") page_data['Title'] = "Edit team (%s)" % the_team.name return "".join(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]'))
def bbcode_ti(the_team, md5_name): output = [] # Links output.append("Last updated: %s<br />" % time.strftime("%H:%M %A %d %B", time.localtime())) output.append('''[url=http://woarl.com/ti/%(md)s]Full team info[/url] - [url=http://woarl.com/orders/%(md)s]Orders helper[/url] - [url=http://woarl.com/wh/%(md)s]War helper[/url] - [url=http://woarl.com/tmap/%(md)s]Team map[/url] - [url=http://woarl.com/stats/%(md)s]Team stats[/url] - [url=http://woarl.com/spyrep/%(md)s]Spy reports[/url] '''.replace('\n', '') % {'md': "%s.html" % md5_name}) output.append("\n[b]Old spy reports[/b]") for t in range(common.current_turn()-1, max(common.current_turn()-5, 78), -1): output.append('''[url=http://woarl.com/spyrep/%(md)s]Spy report (Turn %(t)d)[/url]''' % {'md': "%s.html" % team_f.team_hash(the_team.name, turn=t), "t": t}) output.append("""\n[b]JSON data[/b] [url=http://woarl.com/ti/%(md)s]Team info[/url] - [url=http://woarl.com/map/latest.json]Map[/url] - [url=http://woarl.com/data]Data lists[/url] Secret key: %(md)s""" % {'md': "%s.json" % md5_name}) return "\n".join(output)
def run_orders(options): start_time = time.time() cursor = database.get_cursor() cursor.track_queries = True the_world = spy_world.Spy_world(cursor) team_dict = the_world.active_teams() # Run orders #------------------------ print(database.shell_text("Running orders"), end="") queries, orders, debug = [], ["Team orders\n"], [] the_world.prep_for_orders() try: player_updates = {} the_orders = order_post_f.get_turn_orders(cursor, the_world) blocks = [] # for o in the_orders: for o in cli_f.progressbar(the_orders, "Splitting: ", 60, True): o.split() blocks.extend(o.blocks) # Setup # for b in blocks: for b in cli_f.progressbar(blocks, "Setting up: ", 60, True): b.setup() b.always_debug = True # Execution, in order of priority for priority in order_block.priorities: c = 0 for b in blocks: if b.priority != priority: continue try: b.execute() except Exception as e: print("") print(b.title_name) print(the_world.teams()[b.team].name) print("\n".join(cursor.queries[-5:-1])) print("") raise # Ensure we've handled all blocks for b in blocks: if not b.handled: raise Exception("Block with priority '%s' not handled" % b.priority) team_output = {} manual_output = {} team_debug = {} team_failures = {} for b in cli_f.progressbar(blocks, "Running Blocks: ", 60, True): # for b in blocks: if b.team not in team_output: team_output[b.team] = [] if b.team not in team_debug: team_debug[b.team] = [] if b.team not in team_failures: team_failures[b.team] = [] if b.team not in manual_output: manual_output[b.team] = [] # Player activity needs to get updated player_updates[b.post.player] = b.post.team # team_output[b.team].append("[o]%s[/o]" % b.title_name) team_output[b.team].append("\n".join(b.results)) team_output[b.team].append("") if b.manual_handle: manual_output[b.team].append("\n".join(b.results)) manual_output[b.team].append("") # Failures if len(b.failures) > 0: team_failures[b.team].append("\n".join(b.failures)) team_failures[b.team].append("") # Debug team_debug[b.team].append(b.debug[0]) team_debug[b.team].append("\n---\n".join(b.debug[1:len(b.debug)])) team_debug[b.team].append("") # Foreign results for team_id, res in b.foreign_results.items(): if team_id not in team_output: team_output[team_id] = [] team_output[team_id].insert(0, "") team_output[team_id].insert(0, "\n".join(res)) # Queries for team_id, fqueries in b.foreign_queries.items(): queries.extend(fqueries) queries.extend(b.queries) for team_id, the_team in team_dict.items(): if the_team.ir: continue orders.append("""# %s ###################################################################### [fullbox=#EEF,#AAF][h4]Turn %d Results[/h4][/fullbox] [url=http://woarl.com/stats/%s.html]Rob results[/url] """ % (the_team.name, common.current_turn(), team_f.team_hash(the_team.name))) if team_id in team_output: if team_id in manual_output: # orders.extend(team_output[team_id]) orders.extend(manual_output[team_id]) if team_id in team_debug: debug.extend(team_debug[team_id]) # Update player activity database.query(cursor, player_f.update_player_activity(player_updates)) # Save results results_f.save_results(cursor, team_output) results_f.save_failures(cursor, team_failures) # Now we work out the costs team_costs = {} for t, the_team in team_dict.items(): r = res_dict.Res_dict(the_team.resources) queries.extend(r.make_set_queries(t)) # Write queries to file f = open('%s/script_output/queries.sql' % common.data['server_fpath'], 'w') f.write("\n".join(queries)) f.close() # Write orders to file f = open('%s/script_output/orders.txt' % common.data['server_fpath'], 'w') f.write("\n".join(orders)) f.close() # Write debug to file f = open('%s/script_output/debug.txt' % common.data['server_fpath'], 'w') f.write("Team orders\n\n") f.write("\n".join(debug)) f.close() except Exception as e: print(database.shell_text("[r]Failure[/r]")) print(database.shell_text("[r]Re run as 'rob3 start -l True[/r]'")) raise # print(database.shell_text(" - [g]Done[/g]")) # os.system('mate %s' % '%s/queries.sql' % common.data['server_fpath']) # os.system('mate %s' % '%s/orders.txt' % common.data['server_fpath']) # Failable orders failable = ( re.compile(r'DELETE FROM squads WHERE id = [0-9]*;?'), ) failed_queries = [] # Execute order queries #------------------------ # print(database.shell_text("Executing order queries"), end="") for q in cli_f.progressbar(queries, "Running queries: ", 60, True): # for q in queries: if q == '': continue if q[0:2] == '--': continue try: cursor.execute(q) except Exception as e: ignorable = False for f in failable: if f.search(q) != None: ignorable = True failed_queries.append(q) if not ignorable: for f in failable: print("") print(f.search(q)) print("") cursor.execute('ROLLBACK') print(database.shell_text(" - [r]Failure[/r]")) print("Query: %s\n" % q) print(database.shell_text("[r]Re run as 'rob3 start -l True'[/r]")) raise # print(database.shell_text(" - [g]Done[/g]")) if len(failed_queries) > 0: print("Failed queries") print("\n".join(failed_queries)) # Build up a dict of the queries query_dict = {} for q in cursor.queries: if q in ("BEGIN", "COMMIT", "ROLLBACK"): continue if q not in query_dict: query_dict[q] = 0 query_dict[q] += 1 # What's our most popular query? pop_count, pop_query = 0, "" for q, c in query_dict.items(): if c > pop_count: pop_count = c pop_query = q print("\n\n--- Info ---") print("Time taken: %s" % str(round(time.time() - start_time, 3))[0:5]) print("Queries: %d" % len(cursor.queries)) print("Uniques: %d" % len(set(cursor.queries))) print("Most queried: %s (%d)" % (pop_query, pop_count)) # Verbose mode #------------------------ if options.verbose: cursor.execute("ROLLBACK") print("Rolled back") else: cursor.execute("COMMIT") print("Startup scripts executed") os.system("open %s/script_output/orders.txt" % common.data['server_fpath'])
def test_known(self): for name, turn, hashstr in self.known_values: self.assertEqual(team_f.team_hash(name, turn), hashstr)