x, y = (-1, -1) for row in range(1, len(puzzle)+1): line = layout['Line'+str(row)] try: pairs = re.findall('..', line) x = pairs.index(number) y = row - 1 break; except ValueError: pass # read puzzle text from (x,y) in the given direction # until we hit a block text = '' if direction == 'A': try: x_limit = puzzle[y].index(xdfile.BLOCK_CHAR, x) except ValueError: x_limit = len(puzzle[y]) text = ''.join(puzzle[y][x:x_limit]) elif direction == 'D': for row in range(y, len(puzzle)): char = puzzle[row][x] if char == xdfile.BLOCK_CHAR: break text += char return text if __name__ == "__main__": xdfile.main_parse(parse_ujson)
for clue in clues.xpath('./puzzle:clue', namespaces=ns): word_id = clue.attrib['word'] number = int(clue.attrib['number']) text = "|".join(clue.itertext()).strip() solution = get_solution(word_id, word_map, puzzle) xd.clues.append(((type, number), text, solution)) return xd def get_solution(word_id, word_map, puzzle): def get_numbers_in_range(range_as_string, separator): start, end = (int(num) for num in range_as_string.split(separator)) # reduce 1 to stick to a 0-based index list start = start - 1 end = end - 1 return range(start, end+1) x, y = word_map[word_id] word = '' if '-' in x: word = (puzzle[int(y)-1][i] for i in get_numbers_in_range(x, '-')) elif '-' in y: word = (puzzle[i][int(x)-1] for i in get_numbers_in_range(y, '-')) else: word = (puzzle[int(x)-1][int(y)-1]) return ''.join(word) if __name__ == "__main__": xdfile.main_parse(parse_ccxml)
for item in POSSIBLE_META_DATA: try: text = root.xpath('//crossword/' + item)[0].attrib['v'] if text: xd.headers.append((item, unquote(text))) except: pass # add puzzle all_answers = root.xpath('//crossword/AllAnswer')[0].attrib['v'] all_answers = all_answers.replace('-', xdfile.BLOCK_CHAR) index = 0 while index < len(all_answers): row = all_answers[index:index+cols] xd.grid.append(u"".join(row)) index += cols # add clues for clue_type in ('across', 'down'): for clue in root.xpath('//crossword/'+clue_type)[0].getchildren(): number = int(clue.attrib['cn']) text = udecode(clue.attrib['c'].strip()) solution = clue.attrib['a'].strip() xd.clues.append(((clue_type[0].upper(), number), text, solution)) return xd if __name__ == "__main__": xdfile.main_parse(parse_uxml)
number = int(clue.attrib['number']) text = "|".join(clue.itertext()).strip() text = escape(text, rev_xml_escape_table) solution = get_solution(word_id, word_map, puzzle) xd.clues.append(((type, number), text, solution)) return xd def get_solution(word_id, word_map, puzzle): def get_numbers_in_range(range_as_string, separator): start, end = (int(num) for num in range_as_string.split(separator)) # reduce 1 to stick to a 0-based index list start = start - 1 end = end - 1 return list(range(start, end + 1)) x, y = word_map[word_id] word = '' if '-' in x: word = (puzzle[int(y) - 1][i] for i in get_numbers_in_range(x, '-')) elif '-' in y: word = (puzzle[i][int(x) - 1] for i in get_numbers_in_range(y, '-')) else: word = (puzzle[int(x) - 1][int(y) - 1]) return ''.join(word) if __name__ == "__main__": xdfile.main_parse(parse_ccxml)
if len(answer) > 1: new_clue = True answers["A"+str(clue_num)] = answer if is_block(puzzle, c, r-1): # down clue start j = 0 answer = "" while not is_block(puzzle, c, r+j): answer += puzzle[c, r+j].solution j += 1 if len(answer) > 1: new_clue = True answers["D"+str(clue_num)] = answer if new_clue: clue_num += 1 xd.grid.append(rowstr) for number, clue in puzzle.clues.across(): xd.clues.append((("A", number), decode(clue), answers["A"+str(number)])) for number, clue in puzzle.clues.down(): xd.clues.append((("D", number), decode(clue), answers["D"+str(number)])) return xd if __name__ == "__main__": xdfile.main_parse(parse_puz)
elem = root.xpath('//crossword/' + item) if elem: text = elem[0].attrib['v'] if text: text = escape(text, rev_xml_escape_table) xd.set_header(item, unquote(text)) # add puzzle all_answers = root.xpath('//crossword/AllAnswer')[0].attrib['v'] all_answers = all_answers.replace('-', xdfile.BLOCK_CHAR) index = 0 while index < len(all_answers): row = all_answers[index:index + cols] xd.grid.append("".join(row)) index += cols # add clues for clue_type in ('across', 'down'): for clue in root.xpath('//crossword/' + clue_type)[0].getchildren(): number = int(clue.attrib['cn']) text = udecode(clue.attrib['c'].strip()) text = escape(text, rev_xml_escape_table) solution = clue.attrib['a'].strip() xd.clues.append(((clue_type[0].upper(), number), text, solution)) return xd if __name__ == "__main__": xdfile.main_parse(parse_uxml)
solution = content # replace rebuses with appropriate identifiers (numbers) for item in rebus: if item in content: content = content.replace(item, str(index+1)) solution = content xd.clues.append(((clueprefix, number), text, solution)) text = number = solution = None answer_next = False else: if content[-2:] == " :": answer_next = True content = content[:-2] match = re.match(PT_CLUE, content) if match: number = int(match.group(1)) text = match.group(2) else: if text is None: # a special one number = content text = "" else: text += " " + content if __name__ == "__main__": xdfile.main_parse(parse_xwordinfo)