55
66times = {}
77
8- def fetch (iso_cc ):
9- resp = requests .get (cf .flag_url (iso_cc ))
8+ def fetch (iso_cc , source ):
9+ resp = requests .get (cf .flag_url (iso_cc , source ))
1010 if resp .status_code != 200 :
1111 resp .raise_for_status ()
1212 file_name = cf .iso_file_name (iso_cc )
1313 with open (file_name , 'wb' ) as img :
1414 written = img .write (resp .content )
1515 return written , file_name
1616
17- def main ():
17+ def main (source ):
1818 pending = sorted (cf .cc2name )
1919 to_download = len (pending )
2020 downloaded = 0
@@ -23,7 +23,7 @@ def main():
2323 print ('get:' , iso_cc )
2424 try :
2525 times [iso_cc ] = [time .time () - t0 ]
26- octets , file_name = fetch (iso_cc )
26+ octets , file_name = fetch (iso_cc , source )
2727 times [iso_cc ].append (time .time () - t0 )
2828 downloaded += 1
2929 print ('\t --> {}: {:5d} bytes' .format (file_name , octets ))
@@ -36,7 +36,14 @@ def main():
3636 print ('{}\t {:.6g}\t {:.6g}' .format (iso_cc , start , end ))
3737
3838if __name__ == '__main__' :
39- main ()
39+ import argparse
40+
41+ source_names = ', ' .join (sorted (cf .SOURCE_URLS ))
42+ parser = argparse .ArgumentParser (description = 'Download flag images.' )
43+ parser .add_argument ('source' , help = 'one of: ' + source_names )
44+
45+ args = parser .parse_args ()
46+ main (args .source )
4047
4148"""
4249From cia.gov:
@@ -53,4 +60,4 @@ def main():
5360real 1m40.519s
5461user 0m1.103s
5562sys 0m0.243s
56- """
63+ """
0 commit comments