Skip to content

Instantly share code, notes, and snippets.

@zealot128
Last active September 24, 2018 09:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zealot128/9c950b6431f1bd4a8aed74657532c81d to your computer and use it in GitHub Desktop.
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.
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