CLI tool that just outputs a list of prefectures quickly

It is a script to generate a list quickly when you want a list of prefectures in web development.

prefecture


#!/usr/bin/env python
# -*- coding: utf-8 -*-

import argparse

FORMAT_DEFAULT = '%s';

DATA = """Hokkaido
Aomori Prefecture
Iwate Prefecture
Miyagi Prefecture
Akita
Yamagata Prefecture
Fukushima Prefecture
Ibaraki Prefecture
Tochigi Prefecture
Gunma Prefecture
Saitama
Chiba
Tokyo
Kanagawa Prefecture
Niigata Prefecture
Toyama Prefecture
Ishikawa Prefecture
Fukui prefecture
Yamanashi Prefecture
Nagano Prefecture
Gifu Prefecture
Shizuoka Prefecture
Aichi prefecture
Mie Prefecture
Shiga Prefecture
Kyoto
Osaka
Hyogo prefecture
Nara Prefecture
Wakayama Prefecture
Tottori prefecture
Shimane Prefecture
Okayama Prefecture
Hiroshima Prefecture
Yamaguchi Prefecture
Tokushima Prefecture
Kagawa Prefecture
Ehime Prefecture
Kochi Prefecture
Fukuoka Prefecture
Saga Prefecture
Nagasaki Prefecture
Kumamoto Prefecture
Oita Prefecture
Miyazaki prefecture
Kagoshima prefecture
Okinawa Prefecture"""

def main():

	parser = argparse.ArgumentParser(description='Print prefectures')
	parser.add_argument('-f', '--format', metavar="format", type=str, help="line format" , default=FORMAT_DEFAULT)
	parser.add_argument('-n', '--no-line-break',  help="if add this, print all in one line", action='store_true')

	args = parser.parse_args()
	
	lines = []
	
	if args.no_line_break is False:
		line_break = "\n"
	else:
		line_break = ""
	
	for line in DATA.split("\n"):
		lines.append(args.format % line)
		
	print line_break.join(lines)


if __name__ == "__main__":
	main()

How to use

For now, just list:

$ prefecture 
Hokkaido
Aomori Prefecture
(Abbreviation)
Kagoshima prefecture
Okinawa Prefecture

Separated by commas:

$ prefecture -f "%s,"
Hokkaido,
Aomori Prefecture,
(Abbreviation)
Kagoshima prefecture,
Okinawa Prefecture,

Separate with commas and put out in one line:

$ prefecture -f "%s," --no-line-break
Hokkaido,Aomori Prefecture,...,Kagoshima prefecture,Okinawa Prefecture,

Enclose in quotes and put out with commas:

$ prefecture -f "'%s',"
'Hokkaido',
'Aomori Prefecture',
(Abbreviation)
'Kagoshima prefecture',
'Okinawa Prefecture',

etc

Recommended Posts

CLI tool that just outputs a list of prefectures quickly
A script that outputs a list of SoftLayer portal users
[Linux] A list of Linux commands that beginners should know
A tool that automatically turns the gacha of a social game
Introduction of ls command lsix that can display a list of images
[Python] A program that rotates the contents of the list to the left
Generate a list of consecutive characters
I made a tool that makes decompression a little easier with CLI (Python3)
Display a list of alphabets in Python 3
[python] Get a list of instance variables
String conversion of a list containing numbers
[Python] Get a list of folders only
[Linux] A list of unique command selections that are convenient but unexpectedly unknown