Skip to content

Instantly share code, notes, and snippets.

@jhidajat
Created November 26, 2020 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhidajat/b98f333f3e5c5a0ce397ff54b3ac626d to your computer and use it in GitHub Desktop.
Save jhidajat/b98f333f3e5c5a0ce397ff54b3ac626d to your computer and use it in GitHub Desktop.
Download flags locally
import urllib
import os
country_codes = ['ad',
'ae',
'af',
'ag',
'ai',
'al',
'am',
'an',
'ao',
'ar',
'at',
'au',
'aw',
'az',
'ba',
'bb',
'bd',
'be',
'bf',
'bg',
'bh',
'bi',
'bj',
'bm',
'bn',
'bo',
'br',
'bs',
'bt',
'bw',
'by',
'bz',
'ca',
'cc',
'cd',
'cf',
'cg',
'ch',
'ci',
'ck',
'cl',
'cm',
'cn',
'co',
'cr',
'cu',
'cv',
'cx',
'cy',
'cz',
'de',
'dj',
'dk',
'dm',
'do',
'dz',
'ec',
'ee',
'eg',
'eh',
'er',
'es',
'et',
'fi',
'fj',
'fk',
'fm',
'fo',
'fr',
'ga',
'gb',
'gd',
'ge',
'gf',
'gg',
'gh',
'gi',
'gl',
'gm',
'gn',
'gp',
'gq',
'gr',
'gs',
'gt',
'gw',
'gy',
'hk',
'hn',
'hr',
'ht',
'hu',
'id',
'ie',
'il',
'in',
'iq',
'ir',
'is',
'it',
'jm',
'jo',
'jp',
'ke',
'kg',
'kh',
'ki',
'km',
'kn',
'kp',
'kr',
'kw',
'ky',
'kz',
'la',
'lb',
'lc',
'li',
'lk',
'lr',
'ls',
'lt',
'lu',
'lv',
'ly',
'ma',
'mc',
'md',
'mg',
'mh',
'mk',
'ml',
'mm',
'mn',
'mo',
'mp',
'mq',
'mr',
'ms',
'mt',
'mu',
'mv',
'mw',
'mx',
'my',
'mz',
'na',
'nc',
'ne',
'nf',
'ng',
'ni',
'nl',
'no',
'np',
'nr',
'nu',
'nz',
'om',
'pa',
'pe',
'pf',
'pg',
'ph',
'pk',
'pl',
'pm',
'pn',
'ps',
'pt',
'pw',
'py',
'qa',
're',
'ro',
'ru',
'rw',
'sa',
'sb',
'sc',
'sd',
'se',
'sg',
'sh',
'si',
'sj',
'sk',
'sl',
'sm',
'sn',
'so',
'sr',
'st',
'sv',
'sy',
'sz',
'tc',
'td',
'tf',
'tg',
'th',
'tj',
'tk',
'tm',
'tn',
'to',
'tr',
'tt',
'tv',
'tw',
'tz',
'ua',
'ug',
'uy',
'uz',
'vc',
've',
'vg',
'vi',
'vn',
'vu',
'wf',
'ws',
'ye',
'yt',
'za',
'zm',
'zr',
'zw',
'us']
styles = ['flat','shiny']
sizes = [16, 24, 32, 48, 64]
for style in styles:
for country_code in country_codes:
for size in sizes:
current_directory = '~/Desktop/flags/{0}/{1}'.format(style, size)
if not os.path.exists(current_directory):
os.makedirs(current_directory)
url = 'https://www.countryflags.io/{0}/{1}/{2}.png'.format(country_code, style, size)
destination_url = '~/Desktop/flags/{0}/{1}/{2}.png'.format(style, size, country_code)
urllib.urlretrieve(url, destination_url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment