MCPcopy Create free account
hub / github.com/brasilcep/api / PopulateZipcodes

Method PopulateZipcodes

zipcodes/zipcodes.go:116–184  ·  view source on GitHub ↗
(dnePath string)

Source from the content-addressed store, hash-verified

114}
115
116func (i *ZipCodeImporter) PopulateZipcodes(dnePath string) {
117 if dnePath == "" {
118 i.logger.Error("DNE path is empty")
119 }
120
121 i.logger.Info("Starting DNE import...")
122 start := time.Now()
123
124 var err error
125 db = database.GetDB()
126 if db == nil {
127 i.logger.Error("BadgerDB not initialized (database.GetDB() returned nil)")
128 }
129
130 i.logger.Info("Loading localities...")
131 if err := i.loadLocalities(filepath.Join(dnePath, "LOG_LOCALIDADE.TXT")); err != nil {
132 i.logger.Warn("Warning loading localities", zap.Error(err))
133 }
134 i.logger.Info("Localities loaded", zap.Int("count", len(localities)))
135
136 i.logger.Info("Loading districts...")
137 if err := i.loadDistricts(filepath.Join(dnePath, "LOG_BAIRRO.TXT")); err != nil {
138 i.logger.Warn("Warning loading districts", zap.Error(err))
139 }
140 i.logger.Info("Districts loaded", zap.Int("count", len(districts)))
141
142 i.logger.Info("Importing locality CEPs (general CEP)...")
143 if err := i.importLocalityCEPs(); err != nil {
144 i.logger.Warn("Warning while importing localities", zap.Error(err))
145 }
146
147 i.logger.Info("Importing streets by state...")
148 totalStreets := 0
149 for _, uf := range []string{"AC", "AL", "AP", "AM", "BA", "CE", "DF", "ES", "GO", "MA", "MT", "MS", "MG", "PA", "PB", "PR", "PE", "PI", "RJ", "RN", "RS", "RO", "RR", "SC", "SP", "SE", "TO"} {
150 filePath := filepath.Join(dnePath, "LOG_LOGRADOURO_"+uf+".TXT")
151 ufCount, err := i.importStreets(filePath)
152 if err != nil {
153 i.logger.Warn("Warning while importing streets for UF "+uf, zap.Error(err))
154 continue
155 }
156 totalStreets += ufCount
157 }
158 i.logger.Info("Streets imported", zap.Int("count", totalStreets))
159
160 i.logger.Info("Importing large users...")
161 countLU, err := i.importLargeUsers(filepath.Join(dnePath, "LOG_GRANDE_USUARIO.TXT"))
162 if err != nil {
163 i.logger.Warn("Warning while importing large users", zap.Error(err))
164 }
165 i.logger.Info("Large users imported", zap.Int("count", countLU))
166
167 i.logger.Info("Importing Operational Units (UOP)...")
168 countUOP, err := i.importOperationalUnits(filepath.Join(dnePath, "LOG_UNID_OPER.TXT"))
169 if err != nil {
170 i.logger.Warn("Warning while importing operational units", zap.Error(err))
171 }
172 i.logger.Info("UOPs imported", zap.Int("count", countUOP))
173

Callers 1

mainFunction · 0.95

Calls 8

loadLocalitiesMethod · 0.95
loadDistrictsMethod · 0.95
importLocalityCEPsMethod · 0.95
importStreetsMethod · 0.95
importLargeUsersMethod · 0.95
importCPCMethod · 0.95
GetDBFunction · 0.92

Tested by

no test coverage detected