Last active
August 29, 2015 14:23
-
-
Save inky/10a14ceecb1c41d7c7c8 to your computer and use it in GitHub Desktop.
Revisions
-
ljcooke revised this gist
Jun 14, 2015 . 1 changed file with 9 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,9 +9,15 @@ OFFSET = ord('A') def flag(code): """ Return the Unicode flag emoji for a two-letter country code. """ if len(code) != 2: raise ValueError('country code must be two letters long') if not all(c in string.ascii_letters for c in code): raise ValueError('country code must only contain letters A-Z') return ''.join(CHARS[ord(c) - OFFSET] for c in code.upper()) def main(): -
ljcooke created this gist
Jun 14, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ #!/usr/bin/env python3 import argparse import string import sys CHARS = ("๐ฆ", "๐ง", "๐จ", "๐ฉ", "๐ช", "๐ซ", "๐ฌ", "๐ญ", "๐ฎ", "๐ฏ", "๐ฐ", "๐ฑ", "๐ฒ", "๐ณ", "๐ด", "๐ต", "๐ถ", "๐ท", "๐ธ", "๐น", "๐บ", "๐ป", "๐ผ", "๐ฝ", "๐พ", "๐ฟ") OFFSET = ord('A') def flag(code): """Return the Unicode flag emoji for a two-letter country code.""" assert len(code) == 2 assert all(c in string.ascii_letters for c in code) return ''.join(CHARS[ord(c) - OFFSET] for c in code.upper()) def main(): parser = argparse.ArgumentParser() parser.add_argument('country_code', nargs='*', help='a two-letter country code (ISO 3166-1)') parser.add_argument('-s', '--sep', help='separator') args = parser.parse_args() if args.country_code: flags = (flag(code) for code in args.country_code) else: parser.print_help() return 1 sep = ' ' if args.sep is None else args.sep print(sep.join(flags)) if __name__ == '__main__': sys.exit(main())