- Copy the output of
saying listfrom the source saying command. - Run the following command with pasting the copied outputs
$ python saying_migrate.py --from-saying foo --to-saying bar - <<EOM
(paste the copied text here)
EOM
| # phonics | |
| ph = {"a": "アッ", "b": "バッ", "c": "カッ", "d": "ダッ", "e": "エ", "f": "フッ", "g": "グッ", "h": "ハッ", "i": "イ", "j": "ジャ", "k": "クッ", "l": "ル", "m": "ム", "n": "ヌ", "o": "オ", "p": "パッ", "q": "カッ", "r": "ル", "s": "ス", "t": "ツ", "u": "ウッ", "v": "ヴッ", "w": "ウッ", "x": "クス", "y": "ヤッ", "z": "ズ"} | |
| arr = [] | |
| for a,b in ph.items(): | |
| arr.append(f'rsub("{a}", "{b}",') | |
| result = ''.join(arr) + "{@1}"" + ')' * len(arr) | |
| result | |
| # upper | |
| d = {} |
| # -*- coding: utf-8 -*- | |
| # Reference: Python Cookbook 2nd Ed. p.188 | |
| import random | |
| def random_pick(item_list, probabilities): | |
| """ return a random item in a list, which has different probability. |
| # -*- coding: utf-8 -*- | |
| # Reference: Python Cookbook 2 Ed. p.198 | |
| def get_sorted_dict_values(d): | |
| keys = d.keys() | |
| keys.sort() | |
| return [d[key] for key in keys] |
| import datetime | |
| def convert_to_datetime(date_string): | |
| """ input: %Y-%m-%d %H:%M:%S,%f | |
| example: 2014-01-05 22:20:50,307 | |
| return: datetime object | |
| """ | |
| date_format = "%Y-%m-%d %H:%M:%S,%f" |
| def print_arr_right_aligned(arr): | |
| """ input: string array ['a', 'ab', 'abc'] | |
| output: None. print with right aligned. | |
| a: | |
| ab: | |
| abc: | |
| """ | |
| len_a = max(map(lambda x: len(x), arr)) | |
| for i in arr: | |
| print("{0:>{1}}: ".format(i, len_a)) |
| # sample of ast module | |
| # reference: | |
| # http://docs.python.jp/2.7/library/ast.html | |
| # http://stackoverflow.com/questions/1515357/simple-example-of-how-to-use-ast-nodevisitor | |
| import ast | |
| import sys | |
| import logging | |
| from convert_to_datetime import convert_to_datetime | |
| def add_date_to_log(line): | |
| """ add YYMMDDhh to the beginning of the log. | |
| Argument: | |
| line (hadoop log line) | |
| """ | |
| arr = line.rstrip().split() | |
| date_string = ' '.join(arr[0:2]) |
| # -*- coding: utf-8 -*- | |
| import hypchat | |
| import ConfigParser | |
| import time | |
| import random | |
| import re | |
| import sqlite3 | |
| # 設定のロード |
| import argparse | |
| import random | |
| from datetime import date, timedelta | |
| from random import shuffle | |
| # option settings | |
| parser = argparse.ArgumentParser(description='retail data generator') | |
| parser.add_argument('--no-file', type=int, default=1, help='number of files. default is 1.') | |
| parser.add_argument('--no-line', type=int, default=10000, help='number of lines. default is 10000.') |