def __init__(self, language_file, forbidden_file = None, min_syl=2, max_syl=4):
		self.min_syl = min_syl
		self.max_syl = max_syl
		
		#load language file
		with open(util.data_dir(language_file), 'r') as f:
			lines = [line.strip() for line in f.readlines()]
			
			self.syllables = lines[0].split(',')  #first line, list of syllables
			
			starts_ids = [int(n) for n in lines[1].split(',')]  #next 2 lines, start syllable indexes and counts
			starts_counts = [int(n) for n in lines[2].split(',')]
			self.starts = zip(starts_ids, starts_counts)  #zip into a list of tuples
			
			ends_ids = [int(n) for n in lines[3].split(',')]  #next 2, same for syllable ends
			ends_counts = [int(n) for n in lines[4].split(',')]
			self.ends = zip(ends_ids, ends_counts)
			
			#starting with the 6th and 7th lines, each pair of lines holds ids and counts
			#of the "next syllables" for a previous syllable.
			self.combinations = []
			for (ids_str, counts_str) in zip(lines[5:None:2], lines[6:None:2]):
				if len(ids_str) == 0 or len(counts_str) == 0:  #empty lines
					self.combinations.append([])
				else:
					line_ids = [int(n) for n in ids_str.split(',')]
					line_counts = [int(n) for n in counts_str.split(',')]
					self.combinations.append(zip(line_ids, line_counts))
		
		#load forbidden words file if needed
		if forbidden_file is None:
			self.forbidden = ''
		else:
			self.forbidden = _load_sample(forbidden_file)
Example #2
0
	def __init__(self, language_file, forbidden_file = None, min_syl=2, max_syl=4):
		self.min_syl = min_syl
		self.max_syl = max_syl
		
		#load language file
		with open(util.data_dir(language_file), 'r') as f:
			lines = [line.strip() for line in f.readlines()]
			
			self.syllables = lines[0].split(',')  #first line, list of syllables
			
			starts_ids = [int(n) for n in lines[1].split(',')]  #next 2 lines, start syllable indexes and counts
			starts_counts = [int(n) for n in lines[2].split(',')]
			self.starts = zip(starts_ids, starts_counts)  #zip into a list of tuples
			
			ends_ids = [int(n) for n in lines[3].split(',')]  #next 2, same for syllable ends
			ends_counts = [int(n) for n in lines[4].split(',')]
			self.ends = zip(ends_ids, ends_counts)
			
			#starting with the 6th and 7th lines, each pair of lines holds ids and counts
			#of the "next syllables" for a previous syllable.
			self.combinations = []
			for (ids_str, counts_str) in zip(lines[5:None:2], lines[6:None:2]):
				if len(ids_str) == 0 or len(counts_str) == 0:  #empty lines
					self.combinations.append([])
				else:
					line_ids = [int(n) for n in ids_str.split(',')]
					line_counts = [int(n) for n in counts_str.split(',')]
					self.combinations.append(zip(line_ids, line_counts))
		
		#load forbidden words file if needed
		if forbidden_file is None:
			self.forbidden = ''
		else:
			self.forbidden = _load_sample(forbidden_file)
Example #3
0
def load_sdl_colors_txt(filename=util.data_dir("sdl_colors.txt")):
    global colors, personal, mecha

    if colors is not None:
        return
    colors = {}
    personal = [], [], []
    mecha = [], [], []
    color_re = re.compile(r"^([-+]+):([A-Za-z0-9 ]*[A-Za-z0-9]) *< *([0-9]+) +([0-9]+) +([0-9]+) *>")
    f = open(filename,"rt")
    l = f.readline()
    if not l.startswith("% Standard Color List"):
        raise ValueError("%s does not appear to be in the correct format" % filename)

    for c in f.readlines():
        if not c:
            continue
        m = color_re.search(c)
        if not m:
            raise ValueError("Line from %s does not appear to specify a color: %s" % (filename, c))
        name = m.group(2)
        r, g, b = int(m.group(3)), int(m.group(4)), int(m.group(5))
        colors[name] = r, g, b
        flags = m.group(1)
        for i in range(3):
            if flags[i]=="+":
                personal[i].append(name)
            else:
                assert flags[i]=="-"
            if flags[i+3]=="+":
                mecha[i].append(name)
            else:
                assert flags[i+3]=="-"
Example #4
0
 def new_game(self):
     gb = game.Gameboard()
     gb.gamemap = gamemap.load_ascii_map(util.data_dir("testmap2.txt"))
     gb.PC = game.PC()
     gb.PC.coords = (10,5)
     gb.gamemap.objects[gb.PC.coords].append(gb.PC)
     ui.UI.new_game(self, gb)
     
     self.layers = [MapLayer(gamemap.Map(gb.gamemap.size), gb.gamemap, self), HUDLayer(gb,self)]
Example #5
0
def _load_sample(filename):
    #get sample text
    with open(util.data_dir(filename), 'r') as f:
        sample = ''.join(f.readlines()).lower()

    #convert accented characters to non-accented characters
    sample = locale.strxfrm(sample)

    #remove all characters except letters from A to Z
    a = ord('a')
    z = ord('z')
    sample = ''.join(
        [c if (ord(c) >= a and ord(c) <= z) else ' ' for c in sample])

    return sample
Example #6
0
def _load_sample(filename):
	#get sample text
	with open(util.data_dir(filename), 'r') as f:
		sample = ''.join(f.readlines()).lower()
	
	#convert accented characters to non-accented characters
	sample = locale.strxfrm(sample)
	
	#remove all characters except letters from A to Z
	a = ord('a')
	z = ord('z')
	sample = ''.join([
		c if (ord(c) >= a and ord(c) <= z) else ' '
			for c in sample])
	
	return sample
Example #7
0
 def __init__(self, lang=None):
     if lang in [None, '']:
         lang = i18n.language.info().get('language', 'en')
     print_error('language', lang)
     filename = filenames.get(lang[0:2], 'english.txt')
     path = os.path.join(util.data_dir(), 'wordlist', filename)
     s = open(path,'r').read().strip()
     s = unicodedata.normalize('NFKD', s.decode('utf8'))
     lines = s.split('\n')
     self.wordlist = []
     for line in lines:
         line = line.split('#')[0]
         line = line.strip(' \r')
         assert ' ' not in line
         if line:
             self.wordlist.append(line)
     print_error("wordlist has %d words" % len(self.wordlist))
Example #8
0
 def __init__(self, lang=None):
     if lang in [None, '']:
         lang = i18n.language.info().get('language', 'en')
     print_error('language', lang)
     filename = filenames.get(lang[0:2], 'english.txt')
     path = os.path.join(util.data_dir(), 'wordlist', filename)
     s = open(path, 'r').read().strip()
     s = unicodedata.normalize('NFKD', s.decode('utf8'))
     lines = s.split('\n')
     self.wordlist = []
     for line in lines:
         line = line.split('#')[0]
         line = line.strip(' \r')
         assert ' ' not in line
         if line:
             self.wordlist.append(line)
     print_error("wordlist has %d words" % len(self.wordlist))
Example #9
0
 def __init__(self, lang=None):
     if lang in [None, ""]:
         lang = i18n.language.info().get("language", "en")
     print_error("language", lang)
     filename = filenames.get(lang[0:2], "english.txt")
     path = os.path.join(util.data_dir(), "wordlist", filename)
     s = open(path, "r").read().strip()
     s = unicodedata.normalize("NFKD", s.decode("utf8"))
     lines = s.split("\n")
     self.wordlist = []
     for line in lines:
         line = line.split("#")[0]
         line = line.strip(" \r")
         assert " " not in line
         if line:
             self.wordlist.append(line)
     print_error("wordlist has %d words" % len(self.wordlist))
Example #10
0
import json
import dateutil.parser
import hashlib
import StringIO
import time

import botocore
import boto3

import db
import util
import treehash

print("AWS Photo Library")

if util.data_dir(err=False) is None:
  data_dir = os.path.join(os.getcwd(),util.dir_name)
  os.makedirs(data_dir)

db_conn = util.init()
glacier_conn = boto3.client('glacier')

accountId = '-'
vaultName = 'test'
parameters = {"Type":"inventory-retrieval"}
requestNewInventory = False
uploadNewArchive = True
showInventory = True
uploadD3JS = False
uploadD3JSTAR = True
uploadABC = True
Example #11
0
            if isinstance(obj, terrain.Terrain):
                self.map_to_draw.set_terrain(coords, obj)
                del self.map_to_draw.objects[coords][:]
        for coords, obj in things:
            if not isinstance(obj, terrain.Terrain):
                self.map_to_draw.objects[coords].append(obj)

if __name__ == '__main__':
    import sys
    
    pygame.init()
    size = width, height = 800,  600
    screen = pygame.display.set_mode(size)

    clock = pygame.time.Clock()
    M = gamemap.load_ascii_map(util.data_dir("testmap2.txt"))
    S = SDLMap(M,M)

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_UP:
                    S.view_y -= 16
                elif event.key == pygame.K_DOWN:
                    S.view_y += 16
                elif event.key == pygame.K_LEFT:
                    S.view_x -= 16
                elif event.key == pygame.K_RIGHT:
                    S.view_x += 16
Example #12
0
                    continue
                l = l_so_far + np.hypot(i,j)
                if (nbx,nby) in path_to:
                    pp, ll = path_to[nbx,nby]
                    if ll<=l:
                        continue
                    # new shortest path to this node
                    # so remove it from the queue (if it's there)
                    # and fall through to the "new node" code
                    costs = [(d,n) for (d,n) in costs if n!=(nbx,nby)]
                # this is the shortest known path to (nbx,nby)
                path_to[nbx,nby] = path_so_far + ((nbx,nby),), l

                # How promising is it?
                cost = l+dist((nbx,nby),x1y1)

                heapq.heappush(costs, (cost,(nbx,nby)))

    raise NoPathException(path_to[closest[1]])



if __name__ == '__main__':
    M = load_ascii_map(util.data_dir("testmap2.txt"))
    f = open(util.data_dir("testmap2.yaml"),"w")
    yaml.dump(M,f, encoding="UTF8", allow_unicode=True)
    f.close()
    f = open(util.data_dir("testmap2.yaml,roundtrip"),"w")
    yaml.dump(yaml.load(yaml.dump(M)),f, encoding="UTF8", allow_unicode=True)
    f.close()