以下のVagrantfileでcsvkitとMariaDBをインストールした仮想マシン(Ubuntu16.04)を構築する事ができます。
Vagrantfile
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "bento/ubuntu-16.04"
config.vm.hostname = "ub1604csvkitmariadb"
config.vm.provider :virtualbox do |vbox|
vbox.name = "ub1604csvkitmariadb"
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 mariadb
echo "mariadb-server-10.0 mysql-server/root_password password root" | sudo debconf-set-selections
echo "mariadb-server-10.0 mysql-server/root_password_again password root" | sudo debconf-set-selections
apt-get -y install mariadb-server
mysql -uroot -proot -e "CREATE DATABASE test DEFAULT CHARACTER SET utf8;"
mysql -uroot -proot -e "CREATE USER test@localhost IDENTIFIED BY 'test';"
mysql -uroot -proot -e "GRANT ALL PRIVILEGES ON test.* TO 'test'@'localhost';"
mysql -uroot -proot -e "FLUSH PRIVILEGES;"
# 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 mysql -e utf8 airports.csv >> airports.sql
# import airports data.
cat << EOF | mysql -h localhost -u test -ptest test
source airports.sql
LOAD DATA LOCAL INFILE 'airports.csv'
INTO TABLE airports
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;
select distinct type from airports;
EOF
SHELL
end
〇空港情報
ここで使用しているデータはOurAirportsのデータです。以下のページから空港に関するデータをダウンロードできます(License:Public Domain)。
http://ourairports.com/data/
○関連情報
・csvkitに関する他の記事はこちらを参照してください。
0 件のコメント:
コメントを投稿