File indexing completed on 2024-04-28 15:14:13
0001 #! /usr/bin/env python 0002 # -*- coding: iso-8859-1 -*- 0003 0004 import urllib, re 0005 0006 class AppURLopener(urllib.FancyURLopener): 0007 version = "Mozilla/5.0" 0008 urllib._urlopener = AppURLopener() 0009 0010 def suche( source , country, code ): 0011 for line in source: 0012 result = re.match ( '(.*)(upload.wikimedia)(.*)'+ country +'(.*)', line ) 0013 if result > -1 : 0014 svgurl = line[ line.find("http") : line.find(".svg") + 4 ].strip() 0015 if svgurl.find('thumb') == -1 and len(svgurl) > 3 : 0016 svgsource = urllib.urlopen(svgurl) 0017 data = svgsource.read() 0018 svgsource.close() 0019 0020 out_file = open('flag_' + code.strip().lower() + '.svg','w') 0021 out_file.write(data) 0022 out_file.close() 0023 print svgurl 0024 break 0025 0026 0027 0028 isourlstring = 'http://www.iso.org/' + 'iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1-semic.txt' 0029 isosource = urllib.urlopen(isourlstring).readlines() 0030 0031 for line in isosource: 0032 if len(line) < 80 and len(line) > 5 : 0033 print line 0034 linelist = line.split(';') 0035 linelist[0] = linelist[0].replace("KOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF","NORTH KOREA") 0036 linelist[0] = linelist[0].replace("KOREA, REPUBLIC OF","SOUTH KOREA") 0037 linelist[0] = linelist[0].replace("CONGO","REPUBLIC OF THE CONGO") 0038 linelist[0] = linelist[0].replace("REPUBLIC OF THE CONGO, THE DEMOCRATIC REPUBLIC OF THE","DEMOCRATIC REPUBLIC OF THE CONGO") 0039 linelist[0] = linelist[0].replace("KOREA, REPUBLIC OF","SOUTH KOREA") 0040 linelist[0] = linelist[0].replace('VIRGIN ISLANDS, BRITISH','BRITISH VIRGIN ISLANDS') 0041 linelist[0] = linelist[0].replace('VIRGIN ISLANDS, U.S.','UNITED STATES VIRGIN ISLANDS') 0042 0043 linelist[0] = linelist[0].split(',')[0].rstrip() 0044 linelist[0] = linelist[0].split('(')[0].rstrip() 0045 0046 namelist = linelist[0].split(' ') 0047 fullname = "" 0048 for word in namelist: 0049 if fullname != "" : 0050 fullname = fullname + "_" 0051 if word == 'AND' or word == 'THE' or word == 'OF' or word.find('D\'') > -1: 0052 word = word.lower() 0053 else : 0054 word = word.capitalize() 0055 if word.find('\'') > -1 : 0056 word = word.split('\'')[0] + '%27' + word.split('\'')[1].capitalize() 0057 if word.find('-') > -1 : 0058 word = word.split('-')[0] + '-' + word.split('-')[1].capitalize() 0059 fullname = fullname + word 0060 0061 fullname.strip() 0062 if fullname.find('Islands') > -1 or fullname.find('United') > -1 or fullname.find('Antilles') > -1 or fullname.find('Seychelles') > -1 or fullname.find('Philippines') > -1 or fullname.find('Republic') > -1 or fullname.find('Bahamas') > -1 or fullname.find('Territory') > -1 or fullname.find('Comoros') > -1 or fullname.find('Netherlands') > -1 or fullname.find('Isle') > -1: 0063 fullname = 'the_' + fullname 0064 0065 if fullname.find("land_Islands") > -1 : 0066 fullname ='Aaland' 0067 0068 fullname = fullname.replace('Timor-Leste','East_Timor') 0069 fullname = fullname.replace('the_Syrian_Arab_Republic','Syria') 0070 fullname = fullname.replace('Svalbard_and_Jan_Mayen','Norway') 0071 fullname = fullname.replace('Saint_Pierre','Saint-Pierre') 0072 fullname = fullname.replace('Russian_Federation','Russia') 0073 fullname = fullname.replace('Libyan_Arab_Jamahiriya','Libya') 0074 fullname = fullname.replace('the_Lao_People\'S_Democratic_Republic','Laos') 0075 fullname = fullname.replace('Holy_See','') 0076 fullname = fullname.replace('the_Heard_Island_and_Mcdonald_Islands','Australia') 0077 fullname = fullname.replace('French_Southern_Territories','France') 0078 fullname = fullname.replace('Mayotte','France') 0079 fullname = fullname.replace('Guadeloupe','France') 0080 fullname = fullname.replace('Reunion','France') 0081 fullname = fullname.replace('Gambia','The_Gambia') 0082 fullname = fullname.replace('Tokelau','New_Zealand') 0083 fullname = fullname.replace('Taiwan','the_Republic_of_China') 0084 fullname = fullname.replace('Viet_Nam','Vietnam') 0085 fullname = fullname.replace('French_Guiana','France') 0086 fullname = fullname.replace('Brunei_Darussalam','Brunei') 0087 fullname = fullname.replace('Pitcairn','the_Pitcairn_Islands') 0088 fullname = fullname.replace('Macao','Macau') 0089 fullname = fullname.replace('Bouvet_Island','Norway') 0090 fullname = fullname.replace('the_Palestinian_Territory','Palestine') 0091 fullname = fullname.replace('the_United_States_Minor_Outlying_Islands','the_United_States') 0092 fullname = fullname.replace('the_South_Georgia_and_the_South_Sandwich_Islands','South_Georgia_and_the_South_Sandwich_Islands') 0093 fullname = fullname.replace('Cocos','the_Cocos_%28Keeling%29_Islands') 0094 0095 wpurlstring = 'http://de.wikipedia.org/wiki/Bild:Flag_of_'.strip() + fullname.strip() + '.svg'.strip() 0096 0097 wpsource = urllib.urlopen(wpurlstring).readlines() 0098 if fullname !='' : 0099 print wpurlstring 0100 suche( wpsource, fullname, linelist[1] )