以下のVagrantfileでcsvkitとPostgreSQLをインストールした仮想マシン(Ubuntu16.04)を構築する事ができます。
Vagrantfile
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "bento/ubuntu-16.04"
config.vm.hostname = "ub1604csvkitpg"
config.vm.provider :virtualbox do |vbox|
vbox.name = "ub1604csvkitpg"
vbox.cpus = 2
vbox.memory = 2048
vbox.customize ["modifyvm", :id, "--nicpromisc2","allow-all"]
end
config.vm.network "private_network", ip: "192.168.55.105", :netmask => "255.255.255.0"
config.vm.network "public_network", ip:"192.168.1.105", :netmask => "255.255.255.0"
config.vm.provision "shell", inline: <<-SHELL
sed -i.bak -e "s#http://archive.ubuntu.com/ubuntu/#http://ftp.riken.jp/pub/Linux/ubuntu/#g" /etc/apt/sources.list
apt-get update
apt-get -y install language-pack-ja
localectl set-locale LANG=ja_JP.UTF-8 LANGUAGE="ja_JP:ja"
localectl set-keymap jp106
#DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade
# install postgresql
apt-get -y install postgresql
echo "listen_addresses='*'" >> /etc/postgresql/9.5/main/postgresql.conf
echo "standard_conforming_strings=off" >> /etc/postgresql/9.5/main/postgresql.conf
#sed -i 's/host.*all.*all.*127.0.0.1/#host all all 127.0.0.1/g' /etc/postgresql/9.5/main/pg_hba.conf
echo "host all all 127.0.0.1/32 password" >> /etc/postgresql/9.5/main/pg_hba.conf
echo "host all all 192.168.1.0/24 password" >> /etc/postgresql/9.5/main/pg_hba.conf
echo "host all all 192.168.55.0/24 password" >> /etc/postgresql/9.5/main/pg_hba.conf
su - postgres << EOF
createdb -T template0 --locale=ja_JP.UTF-8 --encoding=UTF8 test
psql -c "
alter user postgres with password 'postgres';
create user test with password 'test';
grant all privileges on database test to test;
"
EOF
echo "postgres:postgres" | chpasswd
systemctl restart postgresql.service
# install csvkit
apt-get -y install python-pip
pip install --upgrade pip
pip install csvkit
# download airports data from Our Airports
wget http://ourairports.com/data/airports.csv
# show column names
csvcut -n airports.csv
# count number of unique values for specified column.
csvstat -c type --unique airports.csv
# show unique values for type(3rd) column.
csvsql --query "select distinct type from airports" airports.csv
# show statistics
csvstat airports.csv
# create sql scripts to create a table from specified csv file.
csvsql -i postgresql -e utf8 airports.csv >> airports.sql
# import airports data.
export PGPASSWORD=test
cat << EOF | psql -h localhost -U test test
\\i airports.sql
\\COPY airports FROM '/home/vagrant/airports.csv' WITH CSV HEADER DELIMITER AS ',';
select distinct type from airports;
EOF
SHELL
end
〇空港情報
ここで使用しているデータはOurAirportsのデータです。以下のページから空港に関するデータをダウンロードできます(License:Public Domain)。
http://ourairports.com/data/
○関連情報
・csvkitに関する他の記事はこちらを参照してください。
0 件のコメント:
コメントを投稿