もた日記

くだらないことを真面目にやる

CSVの処理で使えそうなコマンドラインツール(column, textql, csvkit, xsv, visidata, csvtotable, daff, tabview)

  • column
  • textql
  • csvkit
  • xsv
  • visidata
  • csvtotable
  • daff
  • tabview

CSV(またはTSV)を処理するときにはcut, sort, awk, paste, joinといったコマンドを使うことが多いが、CSVの処理で使えそうなコマンドラインツールを簡単に試してみる。
テスト用のCSVデータは下記ページで作成した。
Mockaroo - Random Data Generator and API Mocking Tool | JSON / CSV / SQL / Excel

column以外はGitHubのスター順で紹介している。

column

stackoverflow.com

columnはLinuxコマンドだが検索で結構ひっかかったので紹介。
以下のように見やすいように揃えて出力してくれる。

$ head -n5 test.csv
id,first_name,last_name,email,gender,ip_address
1,Zacharie,Huge,zhuge0@homestead.com,Male,184.185.151.7
2,Simonne,Byllam,sbyllam1@mtv.com,Female,145.149.190.149
3,Richart,Llewellyn,rllewellyn2@netvibes.com,Male,239.93.62.128
4,Esme,Paulitschke,epaulitschke3@who.int,Female,12.66.148.81

$ head -n5 test.csv | column -s, -t
id  first_name  last_name    email                     gender  ip_address
1   Zacharie    Huge         zhuge0@homestead.com      Male    184.185.151.7
2   Simonne     Byllam       sbyllam1@mtv.com          Female  145.149.190.149
3   Richart     Llewellyn    rllewellyn2@netvibes.com  Male    239.93.62.128
4   Esme        Paulitschke  epaulitschke3@who.int     Female  12.66.148.81
続きを読む

JSONの処理で使えそうなコマンドラインツール(json.tool, jo, jq, jid, gron, jp, json-server, json2csv, jsondiffpatch)

  • python -m json.tool
  • jo
  • jq
  • jid
  • gron
  • jp
  • json-server
  • json2csv
  • jsondiffpatch

JSONの処理で使えそうなコマンドラインツールを簡単に試してみる。

python -m json.tool

19.2. json — JSON エンコーダおよびデコーダ — Python 3.6.5 ドキュメント

Pythonのjson.toolモジュールは JSON オブジェクトの検証と整形出力ができる。infileoutfile引数を指定しない場合は、それぞれ標準入力、標準出力が使われる。

$ python -m json.tool --help
usage: python -m json.tool [-h] [--sort-keys] [infile] [outfile]

A simple command line interface for json module to validate and pretty-print
JSON objects.

positional arguments:
  infile       a JSON file to be validated or pretty-printed
  outfile      write the output of infile to outfile

optional arguments:
  -h, --help   show this help message and exit
  --sort-keys  sort the output of dictionaries alphabetically by key
続きを読む

Linuxメモ : cheat.shでチートシートを表示

  • cheat.sh
  • 使い方
  • コマンドラインクライアント

cheat.sh

github.com

cheat.shを使うとコマンド等のチートシートを表示することができるので試してみる。
似たようなコマンドにtldrがあるがCheat sheets sourcesによるとtldrのリポジトリ等もソースとして利用している模様。

使い方

コマンドをインストールする必要はなくcurlコマンドでcheat.shを指定すればよい(ブラウザでhttps://cheat.sh/にアクセスしても使える)。

f:id:wonder-wall:20180718195806p:plain

続きを読む

Djangoメモ : django-silkで時間のかかるリクエスト、SQLを計測

  • django-silk
  • インストール
  • 計測結果ページ
    • Summary
    • Requests
    • Details
    • SQL
    • Profiling
  • 認証、認可
  • リクエストログ削除

django-silk

github.com

django-silkを使うと時間のかかるリクエスト、SQLを計測することができるので試してみる。 以下のバージョンでテスト済みということなので今回はDjango 2.0.2, Python 3.6.4を使用する。

  • Django: 1.11, 2.0
  • Python: 2.7, 3.4, 3.5, 3.6


インストール

まずpipコマンドでdjango-silkをインストールする。

$ pip install django-silk
続きを読む

Djangoメモ : データベースをSQLiteからPostgreSQLに変更する

  • PostgreSQLの設定
  • Djangoの設定
  • (参考)django.db.utils.OperationalError: FATAL: Ident authentication failed for user
  • (参考)AssertionError: database connection isn't set to UTC
  • (参考)UserWarning: The psycopg2 wheel package will be renamed from release 2.8
  • まとめ

Python 3.6.4 Django 2.0.2

A Complete Beginner's Guide to Djangoのチュートリアルを参考にデータベースをSQLiteからPostgreSQLに変更してみる。


PostgreSQLの設定

PostgreSQLはインストールしてあるものとして話を進める。

$ psql --version
psql (PostgreSQL) 10.1
続きを読む