Exemple #1
0
    def __DoGet_Admin_name(self, code_dict, code_country_dict):
        self.log.info('begin admin_name ..')
        sqlcmd = '''
                 select id, name,country_name
                 from
                 (   
                     select code as id, "name" as name,"name" as country_name
                     from temp_country
                     
                     union
                     
                     select a.code as id,a."name" as name,b."name" as country_name
                     from temp_state as a
                     left join temp_country as b
                     on a.country_code = b.code
                     
                     union
                     
                     select a.code as id, a."name" as name, c."name" as country_name
                     from temp_city as a
                     left join temp_state as b
                     on a.state_code = b.code
                     left join temp_country as c
                     on b.country_code = c.code
                 )as temp_all
                 where name is not null  
                 order by id, name, country_name;
                 '''
        #test set_language

        self.CreateTable2('temp_admin_name')
        MultiLangName.set_language_code(code_dict)

        temp_file_obj = cache_file.open('temp_admin_name_new')
        rows = self.get_batch_data(sqlcmd)
        for row in rows:
            id = row[0]
            name = row[1]
            country_name = row[2]

            if name:
                ml_name = MultiLangName(code_country_dict[country_name], name,
                                        NAME_TYPE_OFFICIAL)

            json_name = ml_name.json_format_dump()
            if not json_name:
                self.log.error('Json Name is null. id=%d' % id)
            else:
                self.__store_name_to_temp_file(temp_file_obj, id, json_name,
                                               code_country_dict[country_name])
        # ## 把名称导入数据库
        temp_file_obj.seek(0)
        self.pg.copy_from2(temp_file_obj, 'temp_admin_name')
        self.pg.commit2()
        # close file
        #temp_file_obj.close()
        cache_file.close(temp_file_obj, True)

        self.log.info('end admin_name ..')
Exemple #2
0
    def _name_to_json(self, strTTS):

        code_dict = dict()
        code_dict['JPN'] = None
        MultiLangName.set_language_code(code_dict)
        ml_name = MultiLangName('JPN', strTTS, NAME_TYPE_OFFICIAL)
        strTTS_json = ml_name.json_format_dump()

        return strTTS_json
Exemple #3
0
 def set_language_code(self):
     from component.default.multi_lang_name import MultiLangName
     if not MultiLangName.is_initialized():
         self.log.info('Set language Code.')
         self.pg.connect2()
         sqlcmd = """
         select language_code
            from language_tbl
            order by language_code;
         """
         code_dict = dict()
         language_codes = self.get_batch_data(sqlcmd)
         for lang_info in language_codes:
             lang_code = lang_info[0]
             code_dict[lang_code] = None
         MultiLangName.set_language_code(code_dict)
     return 0
Exemple #4
0
 def __DoGet_Admin_name(self,code_dict,code_country_dict,code_country_code):          
     self.log.info('begin admin_name ..')
     sqlcmd = '''
              select id,name,name_alt,country_name
              from
              (   
                  select id,"name" as name,"names" as name_alt,"name" as country_name
                  from 
                  (
                      select id,"name","names"
                      from org_area
                      where kind = '10'
                  )as temp
                  
                  union
                  
                  select a.id,a.stt_nme as name,a.stt_alt as name_alt,b."name" as country_name
                  from 
                  (
                      select stt_id as id,stt_nme,stt_alt,parent_id
                      from org_state_region
                      where kind = '9'
                      group by stt_id,stt_nme,stt_alt,parent_id
                      order by stt_id,stt_nme,stt_alt,parent_id
                  )as a
                  left join
                  (
                      select id,"name"
                      from org_area
                      where kind = '10'
                      group by id,"name"
                      order by id,"name"
                  )as b
                  on a.parent_id = b.id
                  
                  union
                  
                  select dst_id as id,dst_nme as name,dst_alt as name_alt,d."name" as country_name
                  from org_district_region as c
                  left join
                  (
                      select state.id,country."name"
                      from 
                      (
                          select stt_id as id,parent_id
                          from org_state_region
                          where kind = '9'
                          group by stt_id,parent_id
                          order by stt_id,parent_id
                      )as state
                      left join
                      (
                          select id,"name"
                          from org_area
                          where kind = '10'
                          group by id,"name"
                          order by id,"name"
                      )as country
                      on state.parent_id = country.id
                  )as d
                  on c.parent_id = d.id              
                  group by dst_id,dst_nme,dst_alt,d."name"
              )as temp_all
              where (name is not null) or (name_alt is not null)    
              order by id,name,name_alt,country_name;
              '''
     #test set_language
     
     MultiLangName.set_language_code(code_dict)
     
     temp_file_obj = cache_file.open('temp_admin_name_new')
     rows = self.get_batch_data(sqlcmd) 
     for row in rows:
         id = int(row[0])
         name = row[1]
         namealtes = row[2]
         country_name = row[3]
         
         if name:
             ml_name = MultiLangName(code_country_dict[country_name], name, NAME_TYPE_OFFICIAL)
         if namealtes:
             # ";" separation
             for namealte in namealtes.split(';'):
                 alt_name = MultiLangName(code_country_dict[country_name], namealte, NAME_TYPE_ALTER)
                 if ml_name:
                     ml_name.add_alter(alt_name)
                 else:
                     ml_name = alt_name
             
         json_name = ml_name.json_format_dump()
         if not json_name:
             self.log.error('Json Name is null. id=%d' % id)
         else:
             self.__store_name_to_temp_file(temp_file_obj, id, json_name,code_country_code[country_name])
     # ## 把名称导入数据库
     temp_file_obj.seek(0)
     self.pg.copy_from2(temp_file_obj, 'temp_admin_name')
     self.pg.commit2()
     # close file
     #temp_file_obj.close()
     cache_file.close(temp_file_obj,True)
     
     self.log.info('end admin_name ..')