Beispiel #1
0
 def _get_multi_name(self, road_name_list, road_number_list, lang_code):
     '''取得多语言多个名称的名称'''
     multi_name = None
     # ## 名称
     for name in road_name_list:
         if not multi_name:
             multi_name = MultiLangName(lang_code, name, NAME_TYPE_OFFICIAL)
         else:
             alte_name = MultiLangName(lang_code, name, NAME_TYPE_ALTER)
             multi_name.add_alter(alte_name)
     # ## 番号
     for shieldid, number in road_number_list:
         # ## 把番号添加名称
         if number in road_name_list:
             continue
         if not multi_name:
             multi_name = MultiLangName(lang_code, number,
                                        NAME_TYPE_ROUTE_NUM)
         else:
             alte_name = MultiLangName(lang_code, number,
                                       NAME_TYPE_ROUTE_NUM)
             multi_name.add_alter(alte_name)
     return multi_name
Beispiel #2
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 ..')