def show_ships(self): print("@ game::show_ships()") print print("+---------+------------------+-----------------+----------+------------+----------------------------+-------+-------+") print("| ship_id | name | owner | status | coords | destination | speed | turns |") print("+---------+------------------+-----------------+----------+------------+----------------------------+-------+-------+") for ship_id, ship in self.__ships.items(): if ship.exists(): dest = ship.get_destination() dest_name = self.__stars[dest].get_name() dest_x, dest_y = self.__stars[dest].get_coords() print("| %7i | %16s | %15s | %8s | %4i, %4i | [%3i, %3i] %15s | %5i | %5i |" % (ship_id, ship.get_name(), self.__players[ship.get_owner()].get_race_name(), ship.get_status_text(), ship.get_x(), ship.get_y(), dest_x, dest_y, dest_name, ship.get_travelling_speed(), ship.get_turns_left())) print("+---------+------------------+-----------------+----------+------------+----------------------------+-------+-------+") print DICT = dictionary.get_dictionary() for ship_id, ship in self.__ships.items(): design = ship.get_design() print(" === ship_id # %i ===" % ship_id) # print(design) for dev_id in design['special_devices']: print(" special device: %2i ... %s" % (dev_id, DICT['SHIP_SPECIALS'][dev_id])) print # i = 0 # print("<?xml version=\"1.0\"?>") # for name in DICT['SHIP_SPECIALS']: # print("<device id=\"%i\">\n\t<name>%s</name>\n</device>\n" % (i, name)) # i += 1
def do_GET(self): body = self.path.split('/')[-1].split('?')[-1] if self.path != '/': filepath = self.path.split("?")[0] else: filepath = '/index' if self.path.split('?')[0] == '/search': response = get_search(body) else: try: response = open(f'./res/pages{filepath}.html', 'r', encoding='utf-8').read() except FileNotFoundError: response = "<h1>404 Not Found" reload_strings() response = response.replace('[|LANGUAGE_NAME|]', get_language_name()) \ .replace('[|SEARCH|]', get_search_string()) \ .replace('[|THERE_IS_AMOUNT_OF_WORDS|]', get_there_is_amount_of_words_string()) \ .replace('[|AMOUNT|]', str(len(get_dictionary()))) self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() self.wfile.write(response.encode())
def test_generate_translator_from_option(): options = { 'name': 'test.ko.to.en', 'url': 'http://test.com', 'path': 'div#content > span' } t = get_dictionary(**options) t.word = 'echo' assert 'echo' == t.word
def draw(self): ME = networking.Client.get_me() DISPLAY = gui.GUI.get_display() DICTIONARY = dictionary.get_dictionary() font3 = gui.GUI.get_font('font3') font4 = gui.GUI.get_font('font4') tech_palette = [0x0, 0x082808, 0x0c840c] DISPLAY.fill((0, 0, 0)) DISPLAY.blit(self.get_image('info_screen', 'panel'), (0, 0)) DISPLAY.blit(self.get_image('info_screen', 'button', 'history_graph', 'off'), (21, 50)) DISPLAY.blit(self.get_image('info_screen', 'button', 'tech_review', 'off'), (21, 77)) DISPLAY.blit(self.get_image('info_screen', 'button', 'race_statistics', 'off'), (21, 102)) DISPLAY.blit(self.get_image('info_screen', 'button', 'turn_summary', 'off'), (21, 128)) DISPLAY.blit(self.get_image('info_screen', 'button', 'reference', 'off'), (21, 154)) # grid behind DISPLAY.blit(self.get_image('app_pic', 0), (433, 115)) # app image DISPLAY.blit(self.get_image('app_pic', 155), (433, 115)) tech_carrets = [] if self.__tech_review == "achievements": # New Construction Types items = [] for tech_id in [TECH_PLANET_CONSTRUCTION, TECH_TITAN_CONTRUCTION, TECH_TRANSPORT, TECH_OUTPOST_SHIP, TECH_FREIGHTERS, TECH_COLONY_SHIP, TECH_COLONY_BASE]: if tech_id in ME.get_known_techs(): items.append(tech_id) if len(items): tech_carrets.append({'title': "New Construction Types", 'items': items}) # Spies items = [] for tech_id in [TECH_TELEPATHIC_TRAINING, TECH_NEURAL_SCANNER, TECH_SPY_NETWORK]: if tech_id in ME.get_known_techs(): items.append(tech_id) if len(items): tech_carrets.append({'title': "Spies", 'items': items}) y = 64 for carret in tech_carrets: if len(carret['items']): font4.write_text(DISPLAY, 223, y, carret['title'], tech_palette, 2) y += 16 for item in carret['items']: font3.write_text(DISPLAY, 233, y, DICTIONARY['TECH_LIST'][item]['name'], tech_palette, 2) y += 13 y += 6
def test_naver_dictionary(): options = { 'name': 'naver.ko.to.en', 'url': u'http://endic.naver.com/search.nhn?query={0}', 'path': '//dt[contains(@class, \'mean_on\')]//em//span[@class=\'EQUIV\']' } t = get_dictionary(**options) t.word = u'안녕' res = t.word.split(', ') assert res assert 'hello' in res
def show_ships(self): print("@ game::show_ships()") print print( "+---------+------------------+-----------------+----------+------------+----------------------------+-------+-------+" ) print( "| ship_id | name | owner | status | coords | destination | speed | turns |" ) print( "+---------+------------------+-----------------+----------+------------+----------------------------+-------+-------+" ) for ship_id, ship in self.__ships.items(): if ship.exists(): dest = ship.get_destination() dest_name = self.__stars[dest].get_name() dest_x, dest_y = self.__stars[dest].get_coords() print( "| %7i | %16s | %15s | %8s | %4i, %4i | [%3i, %3i] %15s | %5i | %5i |" % (ship_id, ship.get_name(), self.__players[ship.get_owner()].get_race_name(), ship.get_status_text(), ship.get_x(), ship.get_y(), dest_x, dest_y, dest_name, ship.get_travelling_speed(), ship.get_turns_left())) print( "+---------+------------------+-----------------+----------+------------+----------------------------+-------+-------+" ) print DICT = dictionary.get_dictionary() for ship_id, ship in self.__ships.items(): design = ship.get_design() print(" === ship_id # %i ===" % ship_id) # print(design) for dev_id in design['special_devices']: print(" special device: %2i ... %s" % (dev_id, DICT['SHIP_SPECIALS'][dev_id])) print # i = 0 # print("<?xml version=\"1.0\"?>") # for name in DICT['SHIP_SPECIALS']: # print("<device id=\"%i\">\n\t<name>%s</name>\n</device>\n" % (i, name)) # i += 1
def get_search(query): keyword = parse_query(query)['keyword'] words = search_for_keys(keyword) result = open('./res/pages/search.html', 'r', encoding='utf-8').read() \ .replace('[|KEYWORD|]', keyword) meanings = '' dictionary = get_dictionary() for word in words: meaning = dictionary[word].split('\n') for i in range(len(meaning)): meaning[i] = f'<p>{meaning[i]}</p>\n' meaning = ''.join(meaning) meanings += open('./res/pages/word_template.html', 'r', encoding='utf-8').read().replace('[|WORD|]', word).replace( '[|MEANING|]', meaning) + '\n' result = result.replace('[|RESULT|]', meanings) return result
def __init__(self): screen.Screen.__init__(self) self.__num_fleets = 0 self.__dict = dictionary.get_dictionary() self.__fleet_shown = -1
def draw(self): DISPLAY = gui.GUI.get_display() DICTIONARY = dictionary.get_dictionary() PLAYERS = networking.Client.list_players() PLANETS = networking.Client.list_planets() font2 = gui.GUI.get_font('font2') font3 = gui.GUI.get_font('font3') font5 = gui.GUI.get_font('font5') star = self.__star planet = self.__planet colony = self.__colony DISPLAY.blit(self.get_image('background', 'starfield'), (0, 0)) DISPLAY.blit( gui.GUI.get_planet_background(planet.get_terrain(), planet.get_picture()), (0, 0)) DISPLAY.blit(self.get_image('colony_screen', 'panel'), (0, 0)) colony_id = colony.get_id() self.reset_triggers_list() self.add_trigger({ 'action': "screen", 'screen': "colony_production", 'colony_id': colony_id, 'rect': pygame.Rect((519, 123), (61, 22)) }) schemes_font_palette = [0x0, 0x141420, 0x6c688c] for i in range(5): object_id = star.get_objects()[i] if object_id != 0xFFFF: object = PLANETS[object_id] print "type: %i" % object.get_type() if object.is_asteroid_belt(): x = 6 y = 22 + (24 * i) DISPLAY.blit( self.get_image('colony_screen', 'asteroids_scheme'), (x, y)) font2.write_text(DISPLAY, x + 29, y + 9, "Asteroids", schemes_font_palette, 1) if object.is_gas_giant(): x = 11 y = 27 + (24 * i) DISPLAY.blit( self.get_image('colony_screen', 'gasgiant_scheme'), (x, y)) font2.write_text(DISPLAY, x + 24, y + 4, "Gas Giant -", schemes_font_palette, 1) font2.write_text(DISPLAY, x + 24, y + 15, "uninhabitable", schemes_font_palette, 1) elif object.is_planet(): terrain = object.get_terrain() size = object.get_size() x = 10 + [6, 4, 3, 1, 0][size] y = 26 + (24 * i) + [6, 4, 2, 1, 0][size] DISPLAY.blit( self.get_image('planet_scheme', terrain, size), (x, y)) DISPLAY.blit(self.get_image('colony_screen', 'scheme_arrow'), (6, 31 + (24 * i))) title = "%s of %s" % (DICTIONARY['COLONY_ASSIGNMENT'][ colony.assignment], colony.get_name()) title_palette = [0x0, 0x141420, 0x6c688c, 0x605c80] title_surface = font5.render(title, title_palette, 2) (tw, th) = title_surface.get_size() DISPLAY.blit(title_surface, (320 - (tw / 2), 1)) # total_population = (1000 * colony['population']) + colony['pop_raised'] # print # print " Colony: %s" % colony.name # print " Population: %i (+%i)" % (total_population, colony['pop_grow']) # print " Industry: %i" % colony.industry() # print " Research: %i" % colony.research() # print " Food (result): %i (%i)" % (colony.food(), colony.food() - colony.population) # print " Colonists:" player_government_id = PLAYERS[colony.get_owner()].get_racepick_item( 'goverment') DISPLAY.blit( self.get_image('government', 'icon', player_government_id), (310, 32)) # TODO: implement negative morale gui.GUI.repeat_draw(DISPLAY, 340, 35, self.get_image('morale_icon', 'good'), colony.morale() // 10, 30, 7, 155) x = 10 + gui.GUI.repeat_draw(DISPLAY, 128, 64, self.get_image('production_10food'), colony.get_food() // 10, 20, 6, 98) gui.GUI.repeat_draw(DISPLAY, x, 64, self.get_image('production_1food'), colony.get_food() % 10, 20, 6, 98) # industry icons number = (colony.get_industry() // 10) + (colony.get_industry() % 10) xx = min(int(round(160 / max(1, number))), 20) print "### colony_screen::draw ... industry icons ... number = %i, xx = %i" % ( number, xx) x = gui.GUI.repeat_draw(DISPLAY, 128, 94, self.get_image('production_10industry'), colony.get_industry() // 10, xx, 99, 162) gui.GUI.repeat_draw(DISPLAY, x, 94, self.get_image('production_1industry'), colony.get_industry() % 10, xx, 99, 162) # research icons number = (colony.get_research() // 10) + (colony.get_research() % 10) xx = min(int(round(160 / max(1, number))), 20) print "### colony_screen::draw ... research icons ... number = %i, xx = %i" % ( number, xx) x = gui.GUI.repeat_draw(DISPLAY, 128, 124, self.get_image('production_10research'), colony.get_research() // 10, xx, 99, 162) gui.GUI.repeat_draw(DISPLAY, x, 124, self.get_image('production_1research'), colony.get_research() % 10, xx, 99, 162) for t in (FARMER, WORKER, SCIENTIST): c = len(colony.colonists[t]) if c < 7: xx = 30 else: xx = 190 / c if t == 0x02: icon = 1 y = 62 elif t == 0x82: icon = 3 y = 92 elif t == 0x03: icon = 5 y = 122 for i in range(c): Colonist = colony.colonists[t][i] race = Colonist['race'] picture = PLAYERS[race].get_picture() x = 310 + xx * i # DISPLAY.blit(self.get_race_icon(picture, icon), (x, y)) DISPLAY.blit(self.get_image('race_icon', picture, icon), (x, y)) if i == (c - 1): xx = 28 # enlarge the Rect of last icon (no other icon is drawn over it...) self.add_trigger({ 'action': "pick-colonist:%.2x:%i" % (t, (c - i)), 'rect': pygame.Rect((x, y), (xx, 28)) }) x = 0 for i in range(colony.marines): # DISPLAY.blit(self.get_race_icon(picture, 0x07), (x, 450)) DISPLAY.blit(self.get_image('race_icon', picture, 0x07), (x, 450)) x += 30 # TODO: count in all races not just owner! total_population = (1000 * colony.total_population()) + sum( colony.pop_raised()) pop_s = "Pop %i,%.3i k (+%i)" % ( (total_population // 1000), (total_population % 1000), sum(colony.pop_grow())) population_palette = [0x0, 0x141420, 0x6c688c] population = font3.render(pop_s, population_palette, 2) (tw, th) = population.get_size() DISPLAY.blit(population, (529, 3))
def draw(self): DISPLAY = gui.GUI.get_display() DICTIONARY = dictionary.get_dictionary() PLAYERS = networking.Client.list_players() PLANETS = networking.Client.list_planets() font2 = gui.GUI.get_font("font2") font3 = gui.GUI.get_font("font3") font5 = gui.GUI.get_font("font5") star = self.__star planet = self.__planet colony = self.__colony DISPLAY.blit(self.get_image("background", "starfield"), (0, 0)) DISPLAY.blit(gui.GUI.get_planet_background(planet.get_terrain(), planet.get_picture()), (0, 0)) DISPLAY.blit(self.get_image("colony_screen", "panel"), (0, 0)) colony_id = colony.get_id() self.reset_triggers_list() self.add_trigger( { "action": "screen", "screen": "colony_production", "colony_id": colony_id, "rect": pygame.Rect((519, 123), (61, 22)), } ) schemes_font_palette = [0x0, 0x141420, 0x6C688C] for i in range(5): object_id = star.get_objects()[i] if object_id != 0xFFFF: object = PLANETS[object_id] print "type: %i" % object.get_type() if object.is_asteroid_belt(): x = 6 y = 22 + (24 * i) DISPLAY.blit(self.get_image("colony_screen", "asteroids_scheme"), (x, y)) font2.write_text(DISPLAY, x + 29, y + 9, "Asteroids", schemes_font_palette, 1) if object.is_gas_giant(): x = 11 y = 27 + (24 * i) DISPLAY.blit(self.get_image("colony_screen", "gasgiant_scheme"), (x, y)) font2.write_text(DISPLAY, x + 24, y + 4, "Gas Giant -", schemes_font_palette, 1) font2.write_text(DISPLAY, x + 24, y + 15, "uninhabitable", schemes_font_palette, 1) elif object.is_planet(): terrain = object.get_terrain() size = object.get_size() x = 10 + [6, 4, 3, 1, 0][size] y = 26 + (24 * i) + [6, 4, 2, 1, 0][size] DISPLAY.blit(self.get_image("planet_scheme", terrain, size), (x, y)) DISPLAY.blit(self.get_image("colony_screen", "scheme_arrow"), (6, 31 + (24 * i))) title = "%s of %s" % (DICTIONARY["COLONY_ASSIGNMENT"][colony.assignment], colony.get_name()) title_palette = [0x0, 0x141420, 0x6C688C, 0x605C80] title_surface = font5.render(title, title_palette, 2) (tw, th) = title_surface.get_size() DISPLAY.blit(title_surface, (320 - (tw / 2), 1)) # total_population = (1000 * colony['population']) + colony['pop_raised'] # print # print " Colony: %s" % colony.name # print " Population: %i (+%i)" % (total_population, colony['pop_grow']) # print " Industry: %i" % colony.industry() # print " Research: %i" % colony.research() # print " Food (result): %i (%i)" % (colony.food(), colony.food() - colony.population) # print " Colonists:" player_government_id = PLAYERS[colony.get_owner()].get_racepick_item("goverment") DISPLAY.blit(self.get_image("government", "icon", player_government_id), (310, 32)) # TODO: implement negative morale gui.GUI.repeat_draw(DISPLAY, 340, 35, self.get_image("morale_icon", "good"), colony.morale() // 10, 30, 7, 155) x = 10 + gui.GUI.repeat_draw( DISPLAY, 128, 64, self.get_image("production_10food"), colony.get_food() // 10, 20, 6, 98 ) gui.GUI.repeat_draw(DISPLAY, x, 64, self.get_image("production_1food"), colony.get_food() % 10, 20, 6, 98) # industry icons number = (colony.get_industry() // 10) + (colony.get_industry() % 10) xx = min(int(round(160 / max(1, number))), 20) print "### colony_screen::draw ... industry icons ... number = %i, xx = %i" % (number, xx) x = gui.GUI.repeat_draw( DISPLAY, 128, 94, self.get_image("production_10industry"), colony.get_industry() // 10, xx, 99, 162 ) gui.GUI.repeat_draw( DISPLAY, x, 94, self.get_image("production_1industry"), colony.get_industry() % 10, xx, 99, 162 ) # research icons number = (colony.get_research() // 10) + (colony.get_research() % 10) xx = min(int(round(160 / max(1, number))), 20) print "### colony_screen::draw ... research icons ... number = %i, xx = %i" % (number, xx) x = gui.GUI.repeat_draw( DISPLAY, 128, 124, self.get_image("production_10research"), colony.get_research() // 10, xx, 99, 162 ) gui.GUI.repeat_draw( DISPLAY, x, 124, self.get_image("production_1research"), colony.get_research() % 10, xx, 99, 162 ) for t in (FARMER, WORKER, SCIENTIST): c = len(colony.colonists[t]) if c < 7: xx = 30 else: xx = 190 / c if t == 0x02: icon = 1 y = 62 elif t == 0x82: icon = 3 y = 92 elif t == 0x03: icon = 5 y = 122 for i in range(c): Colonist = colony.colonists[t][i] race = Colonist["race"] picture = PLAYERS[race].get_picture() x = 310 + xx * i # DISPLAY.blit(self.get_race_icon(picture, icon), (x, y)) DISPLAY.blit(self.get_image("race_icon", picture, icon), (x, y)) if i == (c - 1): xx = 28 # enlarge the Rect of last icon (no other icon is drawn over it...) self.add_trigger( {"action": "pick-colonist:%.2x:%i" % (t, (c - i)), "rect": pygame.Rect((x, y), (xx, 28))} ) x = 0 for i in range(colony.marines): # DISPLAY.blit(self.get_race_icon(picture, 0x07), (x, 450)) DISPLAY.blit(self.get_image("race_icon", picture, 0x07), (x, 450)) x += 30 # TODO: count in all races not just owner! total_population = (1000 * colony.total_population()) + sum(colony.pop_raised()) pop_s = "Pop %i,%.3i k (+%i)" % ((total_population // 1000), (total_population % 1000), sum(colony.pop_grow())) population_palette = [0x0, 0x141420, 0x6C688C] population = font3.render(pop_s, population_palette, 2) (tw, th) = population.get_size() DISPLAY.blit(population, (529, 3))
import translator import dictionary input_str = input("Введите число: ") from_ = int(input("Введите систему счисления введенного Вами числа: ")) to_ = int(input("Введите систему счисления, в которую необходимо перевести введенное Вами число: ")) input_str = input_str.upper() #creating the dictionary for translating dictionary = dictionary.Dictionary("base.csv", "r", ",") #creating the translator translator = translator.Translator(dictionary.get_dictionary(from_), input_str) if translator.get_collection() == None: print("Некорректные данные!") else: print(translator.translate_from_to(from_, to_, translator.get_collection()))
# data_train = open("data/train/" + name_file, "w", encoding="utf-8") # list_data_f_train = data_f_train.split("\n") # # xử lý từng văn bản trong mỗi nhãn # for i_data_f_train in list_data_f_train : # text = "" # list_i_data_f_train = i_data_f_train.split(" ") # for word in list_i_data_f_train : # if word not in stopword and word not in lower_word : # text += word + " " # data_train.write(text + "\n") # print("done! " + name_file) def print_dictionary(dictionary): f = open("dictionary.txt", "w", encoding="utf-8") for word in dictionary: f.write(word + " " + str(dictionary.get(word)) + "\n") if __name__ == "__main__": dictionary = {} dictionary = get_dictionary("clean-data") print("size of dictionary before remove stop word and lower word : " + str(len(dictionary))) dictionary = remove_stopword(dictionary) dictionary = remove_lower_word(dictionary) print_dictionary(dictionary)