| 1 | import axios from 'axios'; |
| 2 | |
| 3 | export const getDddsData = async () => { |
| 4 | const url = |
| 5 | 'https://www.anatel.gov.br/dadosabertos/PDA/Codigo_Nacional/PGCN.csv'; |
| 6 | const LINE_BREAK = '\r\n'; |
| 7 | |
| 8 | const { data: reponseData } = await axios({ |
| 9 | url, |
| 10 | method: 'get', |
| 11 | responseEncoding: 'binary', |
| 12 | }); |
| 13 | |
| 14 | const body = reponseData.toString('binary'); |
| 15 | |
| 16 | const lines = body.split(LINE_BREAK); |
| 17 | |
| 18 | lines.shift(); |
| 19 | |
| 20 | return lines |
| 21 | .map((line) => line.split(';')) |
| 22 | .map(([ibgeCode, state, city, ddd]) => { |
| 23 | return { |
| 24 | ibgeCode, |
| 25 | state, |
| 26 | city, |
| 27 | ddd, |
| 28 | }; |
| 29 | }); |
| 30 | }; |