Exemplo n.º 1
0
def main(argv):
    """
        MAIN
    """

    MOO2_DIR = find_moo2_dir()

    if not MOO2_DIR:
        print("")
        print("ERROR: no MOO2 directory found")
        print(
            "    OpenMOO2 requires original Master of Orion 2 game data to run, see README.TXT for more information"
        )
        print("")
        sys.exit(1)

#    print("Found MOO2 directory: %s" % MOO2_DIR)

    default_options = {'-p': 9999, '-h': "localhost", '-player': 0}

    (OPTIONS, PARAMS) = cli.parse_cli_args(argv, default_options)

    HOST = OPTIONS['-h']
    PORT = OPTIONS['-p']
    PLAYER_ID = OPTIONS['-player']

    SOCKET_BUFFER_SIZE = 4096

    gui.GUI.init(MOO2_DIR)

    pygame.mouse.set_visible(False)
    #    gui.Input().set_display(pygame.display.get_surface())

    gui.splash_screen.Screen.draw()
    gui.GUI.flip()

    networking.Client.connect(HOST, PORT, SOCKET_BUFFER_SIZE)
    networking.Client.login(PLAYER_ID)

    #    server_status = CLIENT.get_server_status()
    #    print("# server_status = %s" % str(server_status))

    # automation for development
    #    scenario = autoplayer.AutoPlayer(CLIENT)
    #    scenario.play()

    #    sys.exit(0)

    WINDOW_CAPTION = "OpenMOO2: PLAYER_ID = %s" % PLAYER_ID

    pygame.display.set_caption(WINDOW_CAPTION)

    ICON = pygame.image.load(MOO2_DIR + "/orion2-icon.png")
    pygame.display.set_icon(ICON)

    #    CLIENT.ping()

    gui.GUI.run()

    networking.Client.disconnect()
Exemplo n.º 2
0
def main():
    # get command line args
    args = cli.parse_cli_args()

    # print canteens
    if args.canteens:
        print(enum_json_creator.enum_to_api_representation_dict(list(Canteen)))
        return

    canteen = Canteen.get_canteen_by_str(args.canteen)
    # get required parser
    parser = get_menu_parsing_strategy(canteen)

    # parse menu
    menus = parser.parse(canteen)

    # if date has been explicitly specified, try to parse it
    menu_date = None
    if args.date is not None:
        try:
            menu_date = util.parse_date(args.date)
        except ValueError:
            print(f"Error during parsing date from command line: {args.date}")
            print(f"Required format: {util.cli_date_format}")
            return

    # print menu
    if menus is None:
        print("Error. Could not retrieve menu(s)")

    # optionally translate the dish titles
    if args.language is not None and args.language.upper() != "DE":
        translated = util.translate_dishes(menus, args.language)
        if not translated:
            print("Error. The translation was not successful")

    # jsonify argument is set
    if args.jsonify is not None:
        weeks = Week.to_weeks(menus)
        if not os.path.exists(args.jsonify):
            os.makedirs(args.jsonify)
        jsonify(weeks, args.jsonify, canteen, args.combine)
    elif args.openmensa is not None:
        weeks = Week.to_weeks(menus)
        if not os.path.exists(args.openmensa):
            os.makedirs(args.openmensa)
        openmensa(weeks, args.openmensa)
    # date argument is set
    elif args.date is not None:
        if menu_date not in menus:
            print(f"There is no menu for '{canteen}' on {menu_date}!")
            return
        menu = menus[menu_date]
        print(menu)
    # else, print weeks
    elif menus is not None:
        weeks = Week.to_weeks(menus)
        for calendar_week in weeks:
            print(weeks[calendar_week])
Exemplo n.º 3
0
def main():
    # get command line args
    args = cli.parse_cli_args()

    # print canteens
    if args.locations:
        with open("canteens.json", 'r') as canteens:
            print(json.dumps(json.load(canteens)))
        return

    # get location from args
    location = args.location
    # get required parser
    parser = get_menu_parsing_strategy(location)
    if parser is None:
        print("The selected location '%s' does not exist." % location)

    # parse menu
    menus = parser.parse(location)

    # if date has been explicitly specified, try to parse it
    menu_date = None
    if args.date is not None:
        try:
            menu_date = util.parse_date(args.date)
        except ValueError as e:
            print("Error during parsing date from command line: %s" %
                  args.date)
            print("Required format: %s" % util.cli_date_format)
            return

    # print menu
    if menus is None:
        print("Error. Could not retrieve menu(s)")
    # jsonify argument is set
    elif args.jsonify is not None:
        weeks = Week.to_weeks(menus)
        if not os.path.exists(args.jsonify):
            os.makedirs(args.jsonify)
        jsonify(weeks, args.jsonify, location, args.combine)
    elif args.openmensa is not None:
        weeks = Week.to_weeks(menus)
        if not os.path.exists(args.openmensa):
            os.makedirs(args.openmensa)
        openmensa(weeks, args.openmensa)
    # date argument is set
    elif args.date is not None:
        if menu_date not in menus:
            print("There is no menu for '%s' on %s!" % (location, menu_date))
            return
        menu = menus[menu_date]
        print(menu)
    # else, print weeks
    else:
        weeks = Week.to_weeks(menus)
        for calendar_week in weeks:
            print(weeks[calendar_week])
Exemplo n.º 4
0
def main(argv):
    """
        MAIN
    """

    default_options = {
        '-p':	9999,
        '-h':	"localhost",
        '-g':   "SAVE1.GAM"
    }

    (OPTIONS, PARAMS) = cli.parse_cli_args(argv, default_options)

    LISTEN_ADDR = OPTIONS['-h']
    LISTEN_PORT = OPTIONS['-p']
    GAME_FILE	= OPTIONS['-g']

    if GAME_FILE == "":
        show_usage(argv[0], "ERROR: Missing game file to load")
        sys.exit(1)

    print("* Init...")
    GAME = game.Game(rules.DEFAULT_RULES)

    moo2_dir = find_moo2_dir()
    if moo2_dir is not None:
        print("* Loading savegame from '%s/%s'" % (moo2_dir, GAME_FILE))
        GAME.load_moo2_savegame(moo2_dir + "/" + GAME_FILE)
#        GAME.show_stars()
#        GAME.show_planets()
        GAME.show_players()
#        GAME.show_colonies()
        GAME.show_ships()

        SERVER = networking.GameServer(LISTEN_ADDR, LISTEN_PORT, GAME)
        SERVER.set_name(GAME_FILE.split("/")[-1])

        print("* Run...")
        SERVER.run()

        print("* Exit...")
        sys.exit(0)
    else:
        print "Error: MOO2 Game directory not found in ../, ../../ or ../../../"
        sys.exit(1)
Exemplo n.º 5
0
            "channelnewsasia.com",
            "straitstimes.com",
        ],
        num_pages=args.num_pages,
        page_size=args.page_size,
        start_date=args.start_date,
    ))

    # Today API Pipeline
    today_pipeline = todayonline.pipeline.TodayPipeline()
    all_articles.extend(today_pipeline.generate(args.num_pages, args.page_size))

    # Fetch existing articles and delete them
    all_articles.extend(repo.list_articles())
    repo.delete_all_articles()

    unique_articles = {}
    for a in all_articles:
        unique_articles[a.url] = a

    if args.dump_path:
        dump_articles_to_path(unique_articles.values(), args.dump_path)

    repo.bulk_insert(unique_articles.values())


if __name__ == "__main__":
    args = cli.parse_cli_args()
    config = conf.Config.from_file(args.config)
    main(args, config)
Exemplo n.º 6
0
def main(argv):
    """
        MAIN
    """

    MOO2_DIR = find_moo2_dir()
    
    if not MOO2_DIR:
        print("")
        print("ERROR: no MOO2 directory found")
        print("    OpenMOO2 requires original Master of Orion 2 game data to run, see README.TXT for more information")
        print("")
        sys.exit(1)

#    print("Found MOO2 directory: %s" % MOO2_DIR)

    default_options = {
        '-p':       	9999,
        '-h':       	"localhost",
        '-player':  	0
    }

    (OPTIONS, PARAMS) = cli.parse_cli_args(argv, default_options)

    HOST	= OPTIONS['-h']
    PORT	= OPTIONS['-p']
    PLAYER_ID	= OPTIONS['-player']

    SOCKET_BUFFER_SIZE = 4096

    gui.GUI.init(MOO2_DIR)

    pygame.mouse.set_visible(False)
#    gui.Input().set_display(pygame.display.get_surface())

    gui.splash_screen.Screen.draw()
    gui.GUI.flip()

    networking.Client.connect(HOST, PORT, SOCKET_BUFFER_SIZE)
    networking.Client.login(PLAYER_ID)

#    server_status = CLIENT.get_server_status()
#    print("# server_status = %s" % str(server_status))

    # automation for development
#    scenario = autoplayer.AutoPlayer(CLIENT)
#    scenario.play()

#    sys.exit(0)

    WINDOW_CAPTION  = "OpenMOO2: PLAYER_ID = %s" % PLAYER_ID

    pygame.display.set_caption(WINDOW_CAPTION)
    
    ICON = pygame.image.load(MOO2_DIR + "/orion2-icon.png")
    pygame.display.set_icon(ICON)

#    CLIENT.ping()

    gui.GUI.run()

    networking.Client.disconnect()