LoginSignup
24
12

More than 5 years have passed since last update.

ls よりも役に立つ loコマンドを作った

Last updated at Posted at 2017-09-07

ls の時代は終わった

ターミナルに触れるととりあえず ls と打ってしまう人は多いと思いますが、この行為は時間の浪費でしかないことには既に周知の事実であり、もっと有意義な時間の使い方をすべきです。
見知ったファイル一覧を見たところで得になることなどただの一つもありませんよね。

そこで私は ls よりも有用な lo コマンドを作りました。
その名の通り最新の COMIC LO のタイトルを取得して艶やかなピンク色で出力してくれるlsよりも有用なコマンドです。
ping 代わりにも使えます()

下記のpythonスクリプトをPATHが通っている場所にloとして置きましょう。

#! /usr/bin/env python3
from urllib.request import urlopen
import re

with urlopen("http://www.akaneshinsha.co.jp/category/item/itemgenre/itemad/magazine-ad/comic-lo/") as res:
    html = res.read().decode("utf-8")
urlprefix = "http://www.akaneshinsha.co.jp/item/"
founds = re.findall(r'<a href="{}(\d+?)/?".+?>'.format(urlprefix), html)
if not founds:
    quit()

with urlopen(urlprefix + founds[0]) as res:
    html = res.read().decode("utf-8").replace("\n", " ")
founds = re.findall(
    r'<div class="freetxt">\s*<p>.+?</p>\s*<p>(.+?)</p>', html)
if not founds:
    quit()
founds = re.findall(r'「(.+?)」', founds[0])
color = 202
for i, found in enumerate(founds):
    print('\033[38;5;%dm%s\033[0m' % (color, found))
    if (i + 1) % (max(4, len(founds)) // 4) == 0:
        color += 1

まとめ

COMIC LO is god

TODO

-l -a -h オプションつけたい

24
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
24
12