無題

133565, 39302, 33134, 38327, 32709, 79486, 141338, 29224, 67390, 33156, 135192, 144337, 154547, 21212, 5610, 105208, 21821, 139964, 115775, 30189, 159181, 130547, 125287, 74453, 55876, 133762, 80912, 6067, 79578, 27557, 129153, 138025, 114769, 154497, 140840, 159900, 126286, 42271, 66379, 68012, 36996, 66001, 118864, 48626, 102740, 159973, 8286, 123763, 131668, 23535, 81349, 106040, 147948, 159900, 49912, 146801, 156242, 58531, 35122, 130937, 27382, 65529, 152765, 155236, 132217, 28150, 81048, 74596, 150708, 159973, 21732, 88284, 142556, 18318, 22208, 114975, 67522, 694, 78986, 82151, 23030, 38561, 40287, 61505, 19801, 37301, 79072, 124490, 29043, 10878, 80203, 83226, 30154, 151910, 148669, 18713, 82050, 14420, 87625, 159020, 19723, 25978, 61403, 72963, 158603, 119404, 44367, 154893, 58283, 76993, 103941, 154031, 83569, 32324, 136716, 24366, 70680, 28614, 84925, 149951, 15188, 82340, 74612, 135269, 44609, 68240, 66945, 146670, 28010, 18276, 139655
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
import requests
from bs4 import BeautifulSoup
from collections import defaultdict
from random import choice

def main():
    from argparse import ArgumentParser
    parser = ArgumentParser()
    parser.add_argument('-d', '--decrypt', action='store_true')
    parser.add_argument('-u', '--aozora-url', nargs='?', type=str, default='')
    parser.add_argument('-i', '--aozora-file', nargs='?', type=str, default='')
    parser.add_argument('file', nargs=None, type=str)
    args = parser.parse_args()

    if bool(args.aozora_url) == bool(args.aozora_file):
        sys.exit(1)
    soup = None
    ENCODING = 'sjis'
    if args.aozora_url:
        req = requests.get(args.aozora_url)
        req.raise_for_status()
        soup = BeautifulSoup(req.content, 'lxml', from_encoding=ENCODING)
    else:
        with open(args.aozora_file, 'rb') as f:
            soup = BeautifulSoup(f.read(), 'lxml', from_encoding=ENCODING)
    texts = []
    for node in soup.find_all('div', class_='main_text'):
        for tag in node.find_all(['rp', 'rt']):
            tag.decompose()
        for tag in node.find_all('span', class_='notes'):
            tag.decompose()
        texts.append(node.get_text().replace('\n', '').replace(' ', ''))
    text = ''.join(texts)
    input_text = None
    with open(args.file) as f:
        input_text = f.read()
    if args.decrypt:
        print(''.join(text[int(e.strip())] for e in input_text.split(',')))
    else:
        table = defaultdict(list)
        for i, ch in enumerate(text):
            table[ch].append(i)
        print(', '.join(str(choice(table[ch])) for ch in input_text if ch in table))

if __name__ == '__main__':
    main()

SKB