Skip to content

Instantly share code, notes, and snippets.

@zealot128 zealot128/vornamen.rb
Last active Sep 24, 2018

Embed
What would you like to do?
Vornamen finder - Populaere Vornamen (Berliner OpenData) greppen nach Namensbestandteilen, z.B. `ruby vornamen.rb m scha` alle Namen mit scha im Namen.
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
You can’t perform that action at this time.