def main(): global server, port, ssl config = fhutils.GameConfig() data_dir = config.gameslist[0]['datadir'] #only support one game now game_stub = config.gameslist[0]['stub'] try: game = fhutils.Game() except IOError: print "Could not read fh_names" sys.exit(2) if not os.path.isdir(data_dir): print "Sorry data directory %s does not exist." % (data_dir) sys.exit(2) longest_name = len(max([x['name'] for x in game.players], key=len)) for player in game.players: name = player['name'].center(longest_name) orders = "%s/sp%s.ord" % (data_dir, player['num']) try: with file(orders, "r+") as f: p = subprocess.Popen([ "/usr/bin/perl", "/home/ramblurr/src/fh/engine/bash/orders.pl" ], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE) verify = p.communicate(input=f.read())[0] if "No errors found" in verify: print "%s - %s - Ready" % (player['num'], name) else: print "%s - %s - Errors" % (player['num'], name) except IOError: print "%s - %s - No Orders" % (player['num'], name)
def main(): global server, port, ssl config = fhutils.GameConfig() data_dir = config.gameslist[0]['datadir'] #only support one game now game_stub = config.gameslist[0]['stub'] try: game = fhutils.Game() except IOError: print("Could not read fh_names") sys.exit(2) if not os.path.isdir(data_dir): print("Sorry data directory %s does not exist." % (data_dir)) sys.exit(2) for player in game.players: orders = "%s/sp%s.ord" % (data_dir, player['num']) try: with file(orders, "r+") as f: text = f.read() text2 = os.linesep.join([s for s in text.splitlines() if s]) f.seek(0) f.write(text2) except IOError: print("Couldn't open %s" % (orders))
def main(argv): config_file = None test_flag = False try: opts, args = getopt.getopt(argv, "hc:t", ["help", "config=", "test"]) except getopt.GetoptError: print(__doc__) sys.exit(2) for opt, arg in opts: if opt in ("-h", "--help"): print(__doc__) sys.exit(0) elif opt in ("-c", "--config"): config_file = arg elif opt in ("-t", "--test"): test_flag = True if config_file: config = fhutils.GameConfig(config_file) else: config = fhutils.GameConfig() game = config.gameslist[0] # for now we only support a single game game_name = game['name'] game_stub = game['stub'] deadline_rule = game['deadline'] data_dir = game['datadir'] bin_dir = config.bindir players = fhutils.Game().players if not os.path.isdir(data_dir): print("Sorry data directory %s does not exist." % (data_dir)) sys.exit(2) if not os.path.isdir(bin_dir): print("Sorry bin directory %s does not exist." % (bin_dir)) sys.exit(2) turn = fhutils.run(bin_dir, "TurnNumber").strip() inject = sys.stdin.read() for player in players: inject_p = inject.replace("SP_NAME", player['name']) report_name = "%s/sp%s.rpt.t%s" % (data_dir, player['num'], turn) with open(report_name, 'r') as original: report = original.read() if test_flag: print(inject_p + "\n\n" + report) else: with open(report_name, 'w') as modified: modified.write(inject_p + "\n\n" + report)
def main(argv): config_file = None discard = False try: opts, args = getopt.getopt(argv, "hc:", ["help", "config="]) except getopt.GetoptError: print __doc__ sys.exit(2) for opt, arg in opts: if opt in ("-h", "--help"): print __doc__ sys.exit(0) elif opt in ("-c", "--config"): config_file = arg if config_file: config = fhutils.GameConfig(config_file) else: config = fhutils.GameConfig() game = config.gameslist[0] # for now we only support a single game game_name = game['name'] data_dir = game['datadir'] bin_dir = config.bindir os.chdir(data_dir) # prepare galaxy list output = fhutils.run(bin_dir, "ListGalaxy", ["-p"]) with open("galaxy.list.txt", "w") as f: f.write(output) players = fhutils.Game().players for p in players: try: subprocess.check_call([ "zip", "sp%s.zip" % (p['num']), "sp%s.rpt.t1" % (p['num']), "galaxy.map.pdf", "galaxy.map.txt", "game_policies.pdf", "galaxy.list.txt" ]) except CalledProcessError: print "ERROR making zip: sp%s.zip" % (p['num'])
def main(): global server, port, ssl config = fhutils.GameConfig() data_dir = config.gameslist[0]['datadir'] #only support one game now game_stub = config.gameslist[0]['stub'] try: game = fhutils.Game() except IOError: print("Could not read fh_names") sys.exit(2) if not os.path.isdir(data_dir): print("Sorry data directory %s does not exist." % (data_dir)) sys.exit(2) server = IMAPClient(server, use_uid=True, ssl=ssl) server.login(config.user, config.password) select_info = server.select_folder('INBOX') messages = server.search(['UNSEEN', 'SUBJECT "FH Orders"']) response = server.fetch(messages, ['RFC822']) for k in response: mail = email.message_from_string(response[k]['RFC822']) addressor = mail.get("From") from_address = email.utils.parseaddr(addressor)[1] if 'wait' in mail.get("Subject"): wait = True else: wait = False for player in game.players: if from_address == player['email']: orders_file = "%s/sp%s.ord" % (data_dir, player['num']) fd = codecs.open(orders_file, 'w', 'utf-8') orders = None if mail.is_multipart(): print( "Multipart Message detected, searching for plain text payload!" ) for part in mail.walk(): # multipart/* are just containers if part.get_content_maintype() == 'multipart': continue filename = part.get_filename() if not filename: continue if part.get_content_type() != "text/plain": print( "Error: attachment found, but not a plain text file for " + from_address) else: print("found orders in attachment") orders = part.get_payload(decode=True) if orders is None: # ok, no attachment, lets try the actual content payloads = mail.get_payload() try: found = False for loads in payloads: if loads.get_content_type() == "text/plain": mail = loads found = True print("found orders in multipart payload") orders = loads.get_payload(decode=True) break if not found: raise email.errors.MessageError except email.errors.MessageError: print("Could not find text/plain payload for " + from_address) else: print("using orders in plain body") orders = mail.get_payload(decode=True) orders = orders.replace('\r\n', '\n').replace('\r', '\n') orders = str(orders, 'utf-8') orders = orders.replace("\u00A0", " ").encode('utf-8') fd.write(orders) fd.close() p = subprocess.Popen([ "/usr/bin/perl", "/home/ramblurr/src/fh/engine/bash/orders.pl" ], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE) verify = p.communicate(input=orders)[0] subject = "FH Orders, %s received" % (game_stub) if wait: subject += " - wait set" else: subject += " - wait not set" config.send_mail(subject, from_address, verify, orders_file) print("Retrieved orders %s for sp%s - %s - %s" % ("[WAIT]" if wait else "", player['num'], player['name'], from_address))
def main(argv): config_file = None test_flag = False species_num = None file_name = None subject = None try: opts, args = getopt.getopt( argv, "hc:ts:f:u:", ["help", "config=", "test", "species", "file", "subject"]) except getopt.GetoptError: print(__doc__) sys.exit(2) for opt, arg in opts: if opt in ("-h", "--help"): print(__doc__) sys.exit(0) elif opt in ("-c", "--config"): config_file = arg elif opt in ("-t", "--test"): test_flag = True elif opt in ("-s", "--species"): species_num = arg elif opt in ("-f", "--file"): file_name = arg elif opt in ("-u", "--subject"): subject = arg if (file_name != None and subject == None) or (file_name == None and subject != None): print("if you specify file_name, you must specify subject.") sys.exit(1) if config_file: config = fhutils.GameConfig(config_file) else: config = fhutils.GameConfig() game = config.gameslist[0] # for now we only support a single game game_name = game['name'] game_stub = game['stub'] deadline_rule = game['deadline'] data_dir = game['datadir'] bin_dir = config.bindir players = fhutils.Game().players if not os.path.isdir(data_dir): print("Sorry data directory %s does not exist." % (data_dir)) sys.exit(2) if not os.path.isdir(bin_dir): print("Sorry bin directory %s does not exist." % (bin_dir)) sys.exit(2) turn = fhutils.run(bin_dir, "TurnNumber").strip() global message, deadline_msg, start_msg next_deadline = deadline_rule.after(datetime.now(dateutil.tz.tzutc())) est = zoneinfo.gettz('America/New_York') pst = zoneinfo.gettz('America/Los_Angeles') day = next_deadline.strftime("%A %B %d") time = next_deadline.strftime("%H:%M (%I:%M %p) %Z") time += "\n= " + next_deadline.astimezone(est).strftime("%I:%M %p %Z") time += "\n= " + next_deadline.astimezone(pst).strftime("%I:%M %p %Z") deadline_msg = deadline_msg % (day, time, game_stub, game_stub) msg = start_msg % (game_name, deadline_msg) if turn == "1" else message % ( game_name, deadline_msg) for player in players: if species_num != None and species_num != player['num']: print("skipping %s - %s" % (player['num'], player['name'])) continue if player['email'] == "player_dropped": print("skipping dropped player %s - %s" % (player['num'], player['name'])) continue if file_name != None: report = "%s/%s" % (data_dir, file_name) elif turn == "1": report = "%s/sp%s.zip" % (data_dir, player['num']) subject = "FH %s Game Start - %s" % (game_stub, player['name']) else: report = "%s/sp%s.rpt.t%s" % (data_dir, player['num'], turn) subject = "FH %s Turn Results - %s turn %s" % ( game_stub, player['name'], turn) if not test_flag: print("Mailing %s to %s (sp %s)" % (report, player['email'], player['name'])) config.send_mail(subject, player['email'], msg, report) else: print("Writing .test file") with open(report + ".test", "w") as f: f.write("To: %s\n" % (player['email'])) f.write("Subject: %s\n" % (subject)) f.write(msg) f.write("Attached: %s\n" % (report))
def main(argv): config_file = None test_flag = False species_num = None try: opts, args = getopt.getopt(argv, "hc:ts:", ["help", "config=", "test", "species"]) except getopt.GetoptError: print __doc__ sys.exit(2) for opt, arg in opts: if opt in ("-h", "--help"): print __doc__ sys.exit(0) elif opt in ("-c", "--config"): config_file = arg elif opt in ("-t", "--test"): test_flag = True elif opt in ("-s", "--species"): species_num = arg if config_file: config = fhutils.GameConfig(config_file) else: config = fhutils.GameConfig() game = config.gameslist[0] # for now we only support a single game game_name = game['name'] game_stub = game['stub'] deadline_rule = game['deadline'] data_dir = game['datadir'] bin_dir = config.bindir players = fhutils.Game().players if not os.path.isdir(data_dir): print "Sorry data directory %s does not exist." % (data_dir) sys.exit(2) if not os.path.isdir(bin_dir): print "Sorry bin directory %s does not exist." % (bin_dir) sys.exit(2) turn = fhutils.run(bin_dir, "TurnNumber").strip() global message, deadline_msg, start_msg next_deadline = deadline_rule.after(datetime.now(dateutil.tz.tzutc())) est = zoneinfo.gettz('America/New_York') pst = zoneinfo.gettz('America/Los_Angeles') poland = zoneinfo.gettz('Europe/Warsaw') day = next_deadline.strftime("%A %B %d") time = next_deadline.strftime("%H:%M (%I:%M %p) %Z") time += "\n= %s" % (next_deadline.astimezone(est).strftime("%I:%M %p %Z")) time += "\n= %s" % (next_deadline.astimezone(pst).strftime("%I:%M %p %Z")) time += "\n= %s" % (next_deadline.astimezone(poland).strftime("%H:%M %Z")) deadline_msg = deadline_msg % (day, time, game_stub, game_stub) msg = message % (game_name, deadline_msg) for player in players: if species_num != None and species_num != player['num']: print "skipping %s - %s" % (player['num'], player['name']) continue orders = "%s/sp%s.ord" % (data_dir, player['num']) if os.path.isfile(orders): print "found orders for %s" % (player['name']) continue subject = "FH %s Orders Reminder - %s" % (game_stub, player['name']) if not test_flag: print "Mailing reminder to %s (sp %s)" % (player['email'], player['name']) config.send_mail(subject, player['email'], msg) else: print "Writing .test file" with open("sp%s.test" % (player['num']), "w") as f: f.write("To: %s\n" % (player['email'])) f.write("Subject: %s\n" % (subject)) f.write(msg)