もた日記

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

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
続きを読む

Djangoメモ : python-decouple, django-environで設定情報を管理

  • python-decouple
    • インストール
    • 使い方
  • django-environ
    • インストール
    • 使い方
  • まとめ

Python 3.6.4 Django 2.0.2

A Complete Beginner's Guide to Djangoのチュートリアルを参考にプロジェクトの設定情報を管理してみる。


python-decouple

Djangoのsettings.pyに書いてある設定情報にはSECRET_KEYやパスワード、環境に依存する設定などが含まれているのでハードコードするのは望ましくない。
この問題を解決するためにチュートリアルではpython-decoupleを紹介している。

github.com

続きを読む