コード例 #1
0
def write_ipuz(f):
    puzzle = {'version': "http://ipuz.org/v1", 'kind': ["http://ipuz.org/crossword#1"], 'title': f.title, 'author': f.author, 'copyright': f.cpyrt, 'notes':f.notes};
    puzzle['dimensions']={}
    puzzle['dimensions']['height']=f.height
    puzzle['dimensions']['width']=f.width
    puzzle['clues']={}
    puzzle['clues']['Across']=f.across
    puzzle['clues']['Down']=f.down
    for i in range(0,f.height):
        for j in range(0,f.width):
            if f.solnblock[i][j]==".":
                f.solnblock[i][j]="#"
    puzzle['solution']=f.solnblock
    temp=[]
    for i in range(0,f.height):
        temp.append([])
        for j in range(0,f.width):
            if f.solnblock[i][j]=="#":
                temp[i].append("#")
            else:
                temp[i].append(f.cellno[i][j])
    puzzle['puzzle']=temp
    data = ipuz.write(puzzle, jsonp=True, callback_name="ipuz_function")
    ofile=open(f.loc,mode='w')
    ofile.write(data)
    ofile.close()    
コード例 #2
0
ファイル: test_ipuz.py プロジェクト: maiamcc/ipuz
 def test_write_supports_different_callback_name(self):
     json_data = {}
     result = ipuz.write(json_data,
                         jsonp=True,
                         callback_name="ipuz_function")
     expected = ''.join(['ipuz_function(', json.dumps(json_data), ')'])
     self.assertEqual(result, expected)
コード例 #3
0
    def test_example_ipuz_file_with_jsonp(self):
        with open("fixtures/example.ipuz") as f:
            data = f.read()

        output = ipuz.read(data)
        output_string = ipuz.write(output, jsonp=True)
        second_output = ipuz.read(output_string)
        self.assertEqual(output, second_output)
コード例 #4
0
    def test_first_ipuz_file_with_json(self):
        with open("fixtures/first.ipuz") as f:
            data = f.read()

        output = ipuz.read(data)
        output_string = ipuz.write(output)
        second_output = ipuz.read(output_string)
        self.assertEqual(output, second_output)
コード例 #5
0
 def test_ignores_callback_name_when_json_only(self):
     json_data = {}
     result = ipuz.write(
         json_data,
         callback_name="ipuz_function"
     )
     expected = json.dumps(json_data)
     self.assertEqual(result, expected)
コード例 #6
0
    def test_crossword_v2(self):
        with open("fixtures/crossword_v2.ipuz") as f:
            data = f.read()

        output = ipuz.read(data)
        output_string = ipuz.write(output)
        second_output = ipuz.read(output_string)
        self.assertEqual(output, second_output)
コード例 #7
0
def save_sol():
        temp_l=[]
        for i in range(0,height):
            if 'saved' not in puzzle:
                temp_l.append([])            
            for j in range(0,width):
                if cellblock[i][j]==".":
                    if 'saved' in puzzle:
                        if isinstance(puzzle['saved'][i][j],dict):
                            puzzle['saved'][i][j]['value']=block
                        else:
                            puzzle['saved'][i][j]=block
                    else:
                        temp_l[i].append(block)
                elif cellblock[i][j]=="-":
                    if 'saved' in puzzle:
                        if isinstance(puzzle['saved'][i][j],dict):
                            puzzle['saved'][i][j]['value']=empty
                        else:
                            puzzle['saved'][i][j]=empty 
                    else:
                        temp_l[i].append(empty)
                else:
                    if 'saved' in puzzle:
                        if isinstance(puzzle['saved'][i][j],dict):
                            puzzle['saved'][i][j]['value']=cellblock[i][j]
                        else:
                            puzzle['saved'][i][j]=cellblock[i][j] 
                    else:
                        temp_l[i].append(cellblock[i][j])
        if 'saved' not in puzzle:
            puzzle['saved']=temp_l
        data = ipuz.write(puzzle, jsonp=True, callback_name="ipuz_function")
        ofile=open(ifil,mode='w')
        ofile.write(data)
        ofile.close()
コード例 #8
0
 def test_write_produces_jsonp_with_jsonp_flag(self):
     json_data = {}
     result = ipuz.write(json_data, jsonp=True)
     expected = ''.join(['ipuz(', json.dumps(json_data), ')'])
     self.assertEqual(result, expected)
コード例 #9
0
 def test_write_produces_json_string_by_default(self):
     json_data = {}
     result = ipuz.write(json_data)
     expected = json.dumps(json_data)
     self.assertEqual(result, expected)
コード例 #10
0
ファイル: crossword_puzzle.py プロジェクト: mainakk/crossword
def writeIpuzFile(puzzle, filename):
    ipuz_dict = crossword.to_ipuz(puzzle)
    with open(filename, 'w') as f:
        f.write(ipuz.write(ipuz_dict))