Skip to content

Instantly share code, notes, and snippets.

@mledoze mledoze/ forked from herrjemand/
Last active Aug 29, 2015

What would you like to do?
from lxml import html #pip install lxml
import requests, time, os.path, json
save_to = 'flags_new' #folder where you want to save. NO / !
temp_data, data = {}, {}
def stripper(c_name):
print('Doing: ', c_name)
page = requests.get('' + c_name + '.svg') #loads the webpage
tree = html.fromstring(page.text) #html to xpath tree
link = ''.join(tree.xpath('//*[@id="file"]/a/img/../@href')) #getting svg links
return link
def save(link,cca3):
with open(save_to + '/' + cca3.lower() + '.svg','w') as w:
w.write(requests.get('https:' + link).text) #saving image
time.sleep(1) #one second delay, to ensure that host will not think that we dos attack him
with open('countries.json') as r: #loads the countries data
temp_data = json.loads(
for i in temp_data: #restructure it from the list to dictionary
data[i['name']['common']] = i
for key in data.keys():
link = ''
for i in ['common','official']:
link = stripper(data[key]['name'][i])
if link:
print("Shit Fuck: ", '\s\s\s', data[key]['cca3'].lower(), '\s\s\s', data[key]['name']['common'],'\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.