#!/usr/bin/python

""" Downloading country flags from Wikimedia Commons

Copyright: (C) 2014 Michael Bemmerl
License: MIT License (see COPYING)

Requirements:
- Python (well, obviously ;-)
- simplemediawiki (https://pypi.python.org/pypi/simplemediawiki)

Tested with Python 2.7.6 and simplemediawiki 1.2.0b2
"""

import argparse
import sys
from WikimediaCommons import WikimediaCommons
from TLDResolver import TLDResolver
from CountryNameResolver import CountryNameResolver
from ISO31661Resolver import ISO31661Resolver

parser = argparse.ArgumentParser(description="A tool for downloading country flags from Wikimedia Commons")
parser.add_argument('LIST')
group = parser.add_mutually_exclusive_group()
group.add_argument('--tld', action='store_true', help="Interpret LIST as Top Level Domain (e.g. '.de')")
group.add_argument('--name', action='store_true', help="Interpret LIST as official english country name (e.g. 'Germany')")
group.add_argument('--iso-3166-1', action='store_true', help="Interpret LIST as ISO 3166-1 alpha-2 code (e.g. 'DE')")

# More to come: http://www.statoids.com/wab.html

parser.add_argument('--png', action='store_true', help="Download a PNG image instead of a SVG")
parser.add_argument('--png-width', help="Width of that PNG")
parser.add_argument('--url', action='store_true', help="Do not download, print URL only")

args = parser.parse_args()

if args.tld:
    resolver = TLDResolver()
elif args.name:
    resolver = CountryNameResolver()
elif args.iso_3166_1:
    resolver = ISO31661Resolver()
else:
    parser.error("Too few arguments. At least one of the optional arguments ('--tld', '--name', etc.) must be given.")

flag = resolver.get_flag(args.LIST)

if flag is None:
    parser.exit(status=1, message="No flag found for '{0}' found..".format(args.LIST))

wmc = WikimediaCommons()
flag_url = wmc.get_image_url(flag)

if args.url:
    print flag_url
else:
    print "Downloading '{0}'...".format(flag)
    # Insert downloading routine here
    print "Done."

@@ -670,16 +670,84 @@
 t('LIST'
+, nargs='+', help=%22List of data separated by a space (e.g. 'DE AU')%22
 )%0D%0Agroup
@@ -1759,16 +1759,45 @@
 n.%22)%0D%0A%0D%0A
+for entry in args.LIST:%0D%0A    
 flag = r
@@ -1817,22 +1817,22 @@
 lag(
-args.LIST
+entry
 )%0D%0A%0D%0A
+    
 if f
@@ -1841,32 +1841,36 @@
 g is None:%0D%0A    
+  
+  
 parser.exit(stat
@@ -1928,23 +1928,23 @@
 mat(
-args.LIST
+entry
 ))%0D%0A%0D%0A
+    
 wmc 
@@ -1965,16 +1965,20 @@
 mons()%0D%0A
+    
 flag_url
@@ -2003,24 +2003,28 @@
 rl(flag)%0D%0A%0D%0A
+    
 if args.url:
@@ -2025,24 +2025,28 @@
 s.url:%0D%0A    
+   
+ 
 print flag_u
@@ -2049,16 +2049,20 @@
 ag_url%0D%0A
+    
 else:%0D%0A 
@@ -2060,24 +2060,28 @@
  else:%0D%0A    
+ 
+   
 print %22Downl
@@ -2111,16 +2111,20 @@
 (flag)%0D%0A
+    
     # In
@@ -2154,16 +2154,20 @@
 e here%0D%0A
+    
     prin

Support for multiple codes