def _wrap_template(source, title): output = [] output.append(common.headers(title, css="", javascript="", local_path=False, js_libs=[], tiers=2, content_div=False)) output.append(nav_bar) output.append("<div class='content'>") output.append(source) output.append("</div>") output.append(common.footers(with_analytics=True)) return "".join(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 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]'))
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 make_wh(self, team_id): the_team = self.the_world.teams()[team_id] tabs = """ <div id="tabs" style="border-bottom: 3px solid #EEE; height: 30px;"> <div class="ti_tab" id="overview_tab" onclick="switch_to('overview');"> Overview </div> <div class="ti_tab" id="units_tab" onclick="switch_to('units');"> Units </div> <div class="ti_tab" id="plan_tab" onclick="switch_to('plan');"> Plan </div> <div class="ti_tab" id="feedback_tab" onclick="switch_to('feedback');"> Feedback </div> </div> """ output = [tabs] load_java = [] run_java = [] # OVERVIEW additions = self.overview_block(the_team) output.append(additions[0]) load_java.append(additions[1]) run_java.append(additions[2]) # UNITS additions = self.units_block(the_team) output.append(additions[0]) load_java.append(additions[1]) run_java.append(additions[2]) # PLAN additions = self.plan_block(the_team) output.append(additions[0]) load_java.append(additions[1]) run_java.append(additions[2]) # FEEDBACK additions = self.feedback_block(the_team) output.append(additions[0]) load_java.append(additions[1]) run_java.append(additions[2]) # bytes = len("".join(output)) # print("") # print("<span style='background-color:#FFF;'>Bytes: %s</span>" % format(round(bytes/1000), ',')) # Setup output.append(common.onload("on_load_setup();")) # JAVASCRIPT #------------------------ javascript = wh_f.javascript("".join(load_java), "".join(run_java)) # HEADER AND FOOTER #------------------------ # 892px for .content # container has 10px padding so left with 872px # 872/2 = 436 # order_box has 5px side margin, becomes 426 yet somehow only 414 works... css = """ .order_box, .order_box_half { border:1px solid #600; background-color:#FFEFEF; margin:10px 5px; padding:5px; } .order_box_half { width: 414px; float: left; } """ output.insert(0, common.headers(title_name="%s war helper" % the_team.name, css=css, javascript=javascript, local_path=self.local_path)) tabs = tabs.replace('id="', 'id="bottom_') output.append(""" %s <br /><hr /> <div style="padding: 5px;"> <input type="button" id="build_button" value="Create orders" onclick="build_orders();"/><br /><br /> <strong>Complete orders</strong><br /> <textarea id="final_output" style="width:99%%;" rows="20"></textarea> </div>""" % "")#tabs) output.append(common.footers()) # Compress some output final_output = "".join(output)#.replace(" ", "").replace(" ", " ").replace(" ", " ") return final_output
def make_oh(self, team_id): the_team = self.the_world.teams()[team_id] tabs = """ <div id="tabs" style="border-bottom: 3px solid #EEE; height: 30px;"> <div class="ti_tab" id="construction_tab" onclick="switch_to('construction');"> Cities </div> <div class="ti_tab" id="military_tab" onclick="switch_to('military');"> Military </div> <!-- <div class="ti_tab" id="monsters_tab" onclick="switch_to('monsters');"> Monsters </div> --> <div class="ti_tab" id="research_tab" onclick="switch_to('research');"> Research </div> <div class="ti_tab" id="operative_tab" onclick="switch_to('operative');"> Operatives </div> <div class="ti_tab" id="trade_tab" onclick="switch_to('trade');"> Trades </div> <div class="ti_tab" id="diplomacy_tab" onclick="switch_to('diplomacy');"> Diplomacy </div> <div class="ti_tab" id="advanced_tab" onclick="switch_to('advanced');"> Advanced </div> <div class="ti_tab" id="command_tab" onclick="switch_to('command');"> Commands </div> </div> """ output = [tabs] loader_src = '../images/other/loading.gif' output.append(""" <div id='loading_div' style='text-align:center;padding-top:20px;'> Loading... <br /><br /> <img src='%s'/> </div>""" % loader_src) load_java = [] run_java = [] # CONSTRUCTION - 111 additions = self.construction_block(the_team) output.append(additions[0]) load_java.append(additions[1]) run_java.append(additions[2]) # MILITARY - 498 additions = self.military_block(the_team) output.append(additions[0]) load_java.append(additions[1]) run_java.append(additions[2]) # MONSTERS # additions = self.monsters_block(the_team) # output.append(additions[0]) # load_java.append(additions[1]) # run_java.append(additions[2]) # RESEARCH - 52 additions = self.research_block(the_team) output.append(additions[0]) load_java.append(additions[1]) run_java.append(additions[2]) # OPERATIVES - 221 additions = self.operative_block(the_team) output.append(additions[0]) load_java.append(additions[1]) run_java.append(additions[2]) # TRADE - 19 additions = self.trade_block(the_team) output.append(additions[0]) load_java.append(additions[1]) run_java.append(additions[2]) # DIPLOMACY - 12 additions = self.diplomacy_block(the_team) output.append(additions[0]) load_java.append(additions[1]) run_java.append(additions[2]) # ADVANCED additions = self.advanced_block(the_team) output.append(additions[0]) load_java.append(additions[1]) run_java.append(additions[2]) # COMMANDS additions = self.command_block(the_team) output.append(additions[0]) load_java.append(additions[1]) run_java.append(additions[2]) # bytes = len("".join(output)) # print("") # print("<span style='background-color:#FFF;'>Bytes: %s</span>" % format(round(bytes/1000), ',')) # Setup output.append(common.onload("on_load_setup();")) # JAVASCRIPT #------------------------ javascript = oh_f.javascript("".join(load_java), "".join(run_java)) # HEADER AND FOOTER #------------------------ # 892px for .content # container has 10px padding so left with 872px # 872/2 = 436 # order_box has 5px side margin, becomes 426 yet somehow only 414 works... css = """ .order_box, .order_box_half { border:1px solid #600; background-color:#FFEFEF; margin:10px 5px; padding:5px; } .order_box_half { width: 414px; float: left; } """ output.insert(0, common.headers(title_name="%s order creation form" % the_team.name, css=css, javascript=javascript, local_path=self.local_path)) tabs = tabs.replace('id="', 'id="bottom_') output.append(""" %s <br /><hr /> <div style="padding: 5px;"> <input type="button" id="build_button" value="Create orders" onclick="build_orders();"/><br /><br /> <strong>Complete orders</strong><br /> <textarea id="final_output" style="width:100%%;" rows="20"></textarea> </div>""" % tabs) output.append(common.footers()) # Compress some output final_output = "".join(output)#.replace(" ", "").replace(" ", " ").replace(" ", " ") return final_output
def make_oh(self, team_id): the_team = self.the_world.teams()[team_id] output = [tabs] # loader_src = '../images/other/loading.gif' # output.append(""" # <div id='loading_div' style='text-align:center;padding-top:20px;'> # Loading... # <br /><br /> # <img src='%s'/> # </div>""" % loader_src) js_data = [] # CONSTRUCTION js_data.append(self.city_tab(the_team)) # MILITARY - 498 js_data.append(self.military_tab(the_team)) # RESEARCH - 52 js_data.append(self.research_tab(the_team)) # OPERATIVES - 221 js_data.append(self.operative_tab(the_team)) # TRADE - 19 js_data.append(self.trade_tab(the_team)) # DIPLOMACY - 12 js_data.append(self.diplomacy_tab(the_team)) """ # ADVANCED additions = self.advanced_block(the_team) output.append(additions[0]) load_java.append(additions[1]) run_java.append(additions[2]) # COMMANDS additions = self.command_block(the_team) output.append(additions[0]) load_java.append(additions[1]) run_java.append(additions[2]) """ # JAVASCRIPT #------------------------ # javascript = oh_f.javascript javascript = "" if self.local_path: data_lib = 'http://woarl.com/data/oh_data.js' data_lib = 'oh_data.js' else: data_lib = '../data/oh_data.js' # HEADER AND FOOTER #------------------------ css = """ .order_box, .order_box_half { border:1px solid #600; background-color:#FFEFEF; margin:10px 5px; padding:5px; } .order_box_half { width: 414px; float: left; }""" output.insert(0, common.headers(title_name="%s order creation form" % the_team.name, css=css, javascript=javascript, local_path=self.local_path)) output.append(wrappers) output.append(""" <div id='loading_div' style='text-align:center;padding-top:20px;'> Loading... </div> %s <br /><hr /> <div style="padding: 5px;"> <input type="button" id="build_button" value="Create orders" onclick="build_orders();"/><br /><br /> <strong>Complete orders</strong><br /> <textarea id="final_output" style="width:100%%;" rows="20"></textarea> </div>""" % tabs.replace('id="', 'id="bottom_')) # JS libs output.append(""" <script type="text/javascript" charset="utf-8" src="%s"></script> <script type="text/javascript" charset="utf-8"> %s </script> <script type="text/javascript" charset="utf-8" src="oh_new.js"></script> """ % ( data_lib, "".join(js_data), )) # And to get the ball rolling! output.append(common.onload("on_load_setup();")) output.append(common.footers()) # Compress some output final_output = "".join(output)#.replace(" ", "").replace(" ", " ").replace(" ", " ") return final_output
</div> <div style="clear:both"> </div> </div> %(holders)s <script type="text/javascript" charset="utf-8"> $('#combat_tab').addClass('selected_equ_tab'); </script> <!-- <script type="text/javascript" charset="utf-8"> setTimeout($('html, body').animate({scrollTop: 200}),0); </script> --> """ % { "combat_div": "".join(combat_output), "ranged_div": "".join(ranged_output), "armour_div": "".join(armour_output), "shields_div": "".join(shields_output), "beasts_div": "".join(beasts_output), "mounts_div": "".join(mounts_output), "holders": "".join(item_holders), } ) # $('html, body').animate({scrollTop: $('#compact_link').offset().top-($(window).height()/2)}); print common.headers("Unit designer", css, "".join(javascript), local_path=1) print "".join(output) print common.footers()
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 make_map_select(cursor, dev_mode=False): output = [] # DEV MODE #------------------------ if dev_mode: with_analytics = False local_path = True thumb_path = "http://localhost/woa/map/images/regions" else: with_analytics = True local_path = False thumb_path = "images/regions" # HEADER #------------------------ output.append(common.headers(title_name="World of Arl: Map select", css="", javascript="", local_path=local_path)) output.append("<div style='width:790px;margin:0 auto;'>") # CORE OUTPUT #------------------------ output.append(""" <div style="margin-top: 10px;"> <div style="height: 275px; float: left; margin: 5px;"> <div style="text-align:center;font-weight:bold;font-size:1.1em;">Full map</div> <a href="latest.html"> <img src="%(thumb_path)s/full_thumb.png" width="250" height="250" /> </a> </div> <br /> Warning: The full sized map is very large in terms of image size and also loading time due to all the cities that will be displayed. <br /><br /> If you are after a specific section of the map you will find that the sections listed below will both load faster and display at a higher quality. Most of the sections overlap their neighbours so it doesn't matter if you cannot find one centred on your nation. </div> <div style="clear: left;"> </div> """ % { "thumb_path": thumb_path, }) grid_mode = True if not grid_mode: for r in region_data.region_list: if dev_mode: link = "http://localhost/rob2/web.py?mode=view_region®ion=%s" % r.name.lower() else: link = "http://woarl.com/map/latest_%s.html" % r.name.lower() output.append(""" <div style="width: 250px; height: 275px; float: left; margin: 5px;"> <div style="text-align:center;font-weight:bold;font-size:1.1em;">%(name)s</div> <a href="%(link)s"> <img src="%(thumb_path)s/%(lower_name)s_thumb.png" width="250" height="250" /> </a> </div> """ % { "thumb_path": thumb_path, "lower_name": r.name.lower(), "name": r.name, "link": link, }) else: link = "http://woarl.com/map/latest_" # if dev_mode: # link = "http://localhost/rob2/web.py?mode=view_region®ion=" # else: # link = "http://woarl.com/map/latest_" output.append(""" <table border="0" cellspacing="0" cellpadding="3"> <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> <a href="%(link)sbazniraz.html"> <img src="%(thumb_path)s/bazniraz_thumb.png" /> </a> </td> <td> </td> <td> <a href="%(link)srayti.html"> <img src="%(thumb_path)s/rayti_thumb.png" /> </a> </td> <td> </td> <td> </td> <td> <a href="%(link)skilpellershe.html"> <img src="%(thumb_path)s/kilpellershe_thumb.png" /> </a> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> <a href="%(link)shumyti.html"> <img src="%(thumb_path)s/humyti_thumb.png" /> </a> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> <a href="%(link)stishrashi.html"> <img src="%(thumb_path)s/tishrashi_thumb.png" /> </a> </td> <td> <a href="%(link)smesmelamls.html"> <img src="%(thumb_path)s/mesmelamls_thumb.png" /> </a> </td> <td> </td> <td> </td> </tr> <tr> <td> <a href="%(link)scarippi.html"> <img src="%(thumb_path)s/carippi_thumb.png" /> </a> </td> <td> </td> <td> <a href="%(link)suxebrith.html"> <img src="%(thumb_path)s/uxebrith_thumb.png" /> </a> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> <a href="%(link)shetayze.html"> <img src="%(thumb_path)s/hetayze_thumb.png" /> </a> </td> <td> </td> <td> </td> <td> </td> </tr> </table> """ % { "link": link, "thumb_path": thumb_path, }) # FOOTER #------------------------ output.append("</div>") output.append(common.footers(with_analytics)) return "".join(output)
if team_id <= 0: print """<div style="padding: 5px;"> <form style="padding: 5px;" action="web.py" method="get" accept-charset="utf-8"> <input type="hidden" name="mode" id="mode" value="team_stats" /> <table border="0" cellspacing="5" cellpadding="5"> <tr> <td><label for="team">Team:</label></td> <td>%(team_option_box)s</td> <td width="10"> </td> <td><input type="submit" value="Get Stats" /></td> </tr> </table> </form>""" % { "team_option_box": team_f.structured_list(default=team_id), "last_id": team_q.get_latest_active_team_id(skip_irs = True), } if team_id > 0: the_team = team.Team(team_q.get_one_team(team_id)) md5_name = the_team.get_hash() output = graph_stats_f.make_graphs(the_team) headers = common.headers("%s stats" % the_team.name, css="", javascript="", local_path=True) footers = common.footers(with_analytics=False) # print headers print output # print footers # print "</div>"