commit 60b1523761b0645913353262521882ec0faf9897 Author: Alexander Popov Date: Thu Feb 9 00:19:34 2017 +0300 release diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..afed073 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.csv diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0d83115 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Alexander Popov + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/cisoc.py b/cisoc.py new file mode 100644 index 0000000..aae04ca --- /dev/null +++ b/cisoc.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 + +import urllib.request +import lxml.html as html +import re + +__author__ = 'Alexander Popov' +__version__ = '0.1.0' +__license__ = 'MIT' + + +# get countryes list +def getList(): + COUNTRY = list() + + Html = html.parse(urllib.request.urlopen('https://countrycode.org/')) + table = Html.xpath('//div[@class="visible-sm visible-xs"]//table/tbody/tr') + for item in table: + result = re.findall(r'([A-Z].*)', item.text_content()) + iso = result[1].split(' / ') + COUNTRY.append((result[0], iso[0], iso[1])) + + return(COUNTRY) + + +# save countryes list in csv file +def CSV(): + countryes = getList() + + with open('./cisoc.csv', 'w+', encoding='utf-8') as f: + for country in countryes: + f.write('%s,%s,%s\n' % (country[0], country[1], country[2],)) + + +if __name__ == '__main__': + CSV() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6fb91b8 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +lxml==3.7.2