Add `-a' option to print only main translation categories. - wr - Translate a term via WordReference.com
 (HTM) hg clone https://bitbucket.org/iamleot/wr
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
       ---
 (DIR) changeset 89a8d712bafdcb642ebf85ff0ea6313c98ebc2b7
 (DIR) parent 989c07e5bcc152c90ee1643b6d4e93b44d93e3a1
 (HTM) Author: Rocky Hotas <rockyhotas@firemail.cc>
       Date:   Wed, 27 Nov 2019 22:42:55 
       
       Add `-a' option to print only main translation categories.
       
       Modified the argument parsing procedure, now handled by
       ArgumentParser.  Added support to print `Principal Translations'
       and `Additional Translations' only (default option), or the
       whole output with all the categories (`-a' option).
       
       Diffstat:
        wr.py |  20 ++++++++++----------
        1 files changed, 10 insertions(+), 10 deletions(-)
       ---
       diff -r 989c07e5bcc1 -r 89a8d712bafd wr.py
       --- a/wr.py     Thu Nov 21 17:02:22 2019 +0100
       +++ b/wr.py     Wed Nov 27 22:42:55 2019 +0100
       @@ -209,20 +209,20 @@
        
        
        if __name__ == '__main__':
       -    import sys
       -
       -    def usage():
       -        print('usage: {} dict term'.format(sys.argv[0]))
       -        sys.exit(1)
       +    import argparse
        
       -    if len(sys.argv) != 3:
       -        usage()
       +    parser = argparse.ArgumentParser(description="WordReference cli interface")
       +    parser.add_argument("dictionary", type=str, help="specify the dictionaries to be used: e.g., enit")
       +    parser.add_argument("term", type=str, help="specify the term to be translated")
       +    parser.add_argument("-a", action="store_true", help="show all the translation categories", default=False)
       +    args = parser.parse_args()
        
       -    dictionary = sys.argv[1]
       -    term = sys.argv[2]
       +    mcats = ('Principal Translations', 'Additional Translations')
        
            pcat = ''
       -    for i, t in enumerate(translate(dictionary, term)):
       +    for i, t in enumerate(translate(args.dictionary, args.term)):
       +        if not args.a and t.term_category not in mcats:
       +            continue
                if i > 0:
                    print()
                if t.term_category != pcat: