Skip to content

Instantly share code, notes, and snippets.

@dbalduini
Created August 10, 2019 16:41
Show Gist options
  • Save dbalduini/737c1762f3e985df3f0df7bd0b78a247 to your computer and use it in GitHub Desktop.
Save dbalduini/737c1762f3e985df3f0df7bd0b78a247 to your computer and use it in GitHub Desktop.
Gera lista de cidades do Brasil e copia para a area de transferencia
/**
* Generated from Wikipedia.
* Link: https://pt.wikipedia.org/wiki/Lista_de_munic%C3%ADpios_do_Brasil
*/
var xs = [];
$('.mw-parser-output li').each(function() {
xs.push($(this).text());
});
function extract(cidade) {
var re = /^([A-Z].*) \(([A-Z]{2})\)/;
var a = re.exec(cidade);
if (a && a.length > 0) {
return {
cidade: a[1],
uf: a[2]
};
}
return null;
}
// Copy to clipboard
copy(xs.map(x => extract(x)).filter(a => a !== null));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment