Last active
September 24, 2018 09:53
-
-
Save zealot128/9c950b6431f1bd4a8aed74657532c81d to your computer and use it in GitHub Desktop.
Vornamen finder - Populaere Vornamen (Berliner OpenData) greppen nach Namensbestandteilen, z.B. `ruby vornamen.rb m scha` alle Namen mit scha im Namen.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'csv' | |
unless ARGV.count == 2 | |
puts "USAGE: #{__FILE__} [GENDER: m|f] SEARCH" | |
end | |
gender = ARGV[0] | |
require 'open-uri' | |
all = [] | |
[ | |
'https://www.berlin.de/daten/liste-der-vornamen-2017/mitte.csv', | |
'https://www.berlin.de/daten/liste-der-vornamen-2017/pankow.csv', | |
'https://www.berlin.de/daten/liste-der-vornamen-2017/friedrichshain-kreuzberg.csv' | |
].each do |file| | |
all += CSV.read(Kernel.open(file), col_sep: ';').select { |_, _, g| g == gender } | |
end | |
names = all.map { |a, b| [a, b.to_i] }.group_by { |a, b| a }.map { |k, v| [k, v.map(&:last).reduce(&:+)] } | |
rx = Regexp.new(ARGV[1], 'i') | |
names.select { |name, _| | |
name && name[rx] | |
}.take(20).map do |name, count| | |
puts " #{name}: #{count}x" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment