diff --git a/scripts/06_execution_time.py b/scripts/06_execution_time.py index 9614bbd..4040dd2 100755 --- a/scripts/06_execution_time.py +++ b/scripts/06_execution_time.py @@ -1,34 +1,23 @@ -""" -ExecutionTime - -This class is used for timing execution of code. - -For example: - - timer = ExecutionTime() - print 'Hello world!' - print 'Finished in {} seconds.'.format(timer.duration()) - -""" - - -import time -import random - - -class ExecutionTime: - def __init__(self): - self.start_time = time.time() - - def duration(self): - return time.time() - self.start_time - - -# ---- run code ---- # - - -timer = ExecutionTime() -sample_list = list() -my_list = [random.randint(1, 888898) for num in - range(1, 1000000) if num % 2 == 0] -print('Finished in {} seconds.'.format(timer.duration())) +import time +import random + + +class ExecutionTime: + def __init__(self): + self.start_time = time.time() + + def duration(self): + return time.time() - self.start_time + + +timer = ExecutionTime() +sample_list = [] + +for i in range (1,1000000): + if i % 2 == 0: + sample_list.append(random.randint(1,888888)) + +for i in range(10): + print(11111) + +print("finished in {}seconds.".format(timer.duration())) \ No newline at end of file diff --git a/scripts/08_basic_email_web_crawler.py b/scripts/08_basic_email_web_crawler.py index b56c747..34ca38c 100755 --- a/scripts/08_basic_email_web_crawler.py +++ b/scripts/08_basic_email_web_crawler.py @@ -1,21 +1,17 @@ -import requests -import re - -# get url -url = input('Enter a URL (include `http://`): ') - -# connect to the url -website = requests.get(url) - -# read html -html = website.text - -# use re.findall to grab all the links -links = re.findall('"((http|ftp)s?://.*?)"', html) -emails = re.findall('([\w\.,]+@[\w\.,]+\.\w+)', html) - - -# print the number of links in the list -print("\nFound {} links".format(len(links))) -for email in emails: - print(email) +from bs4 import BeautifulSoup +import requests + + + + +url = input('Enter a URL (include `http://`): ') + +response = requests.get(url) +html = response.text +soup = BeautifulSoup(html,"html.parser") +print(html) + +list = [] +for i in soup.find_all("a",href=True): + list.append(i) + print("leited kink: ", i) diff --git a/scripts/18_zipper.py b/scripts/18_zipper.py index 43c956d..239ddf5 100755 --- a/scripts/18_zipper.py +++ b/scripts/18_zipper.py @@ -9,12 +9,27 @@ dir_name = 'tmp/' # update path -def zipdir(path, zip): +# def zipdir(path, zip): +# for root, dirs, files in os.walk(path): +# for file in files: +# zip.write(os.path.join(root, file)) +# +# if __name__ == '__main__': +# zipfile = ZipFile(file_name, 'w') +# zipdir(dir_name, zipfile) +# zipfile.close() + + +today = datetime.now() +file_name = 'zipper_' + today.strftime('%Y.%m.%dh%H%M') + '.zip' +dir_name = 'tmp/' # update path + +def add_folder_to_zip(folderPath,zipFile): for root, dirs, files in os.walk(path): for file in files: - zip.write(os.path.join(root, file)) + print(root) + full_path = os.path.join(root,file) + zipfile.write(full_path) -if __name__ == '__main__': - zipfile = ZipFile(file_name, 'w') - zipdir(dir_name, zipfile) - zipfile.close() +with ZioFile("test_zip.zip","w") as my_zip: + add_folder_to_zip("testFoler8",my_zip) diff --git a/scripts/33_country_codes.json b/scripts/33_country_codes.json index 4ec79e6..a03544e 100644 --- a/scripts/33_country_codes.json +++ b/scripts/33_country_codes.json @@ -1,1254 +1,62 @@ -{ - "country": [ - { - "countryCode": "AD", - "countryName": "Andorra", - "continentName": "Europe" - }, - { - "countryCode": "AE", - "countryName": "United Arab Emirates", - "continentName": "Asia" - }, - { - "countryCode": "AF", - "countryName": "Afghanistan", - "continentName": "Asia" - }, - { - "countryCode": "AG", - "countryName": "Antigua and Barbuda", - "continentName": "North America" - }, - { - "countryCode": "AI", - "countryName": "Anguilla", - "continentName": "North America" - }, - { - "countryCode": "AL", - "countryName": "Albania", - "continentName": "Europe" - }, - { - "countryCode": "AM", - "countryName": "Armenia", - "continentName": "Asia" - }, - { - "countryCode": "AO", - "countryName": "Angola", - "continentName": "Africa" - }, - { - "countryCode": "AQ", - "countryName": "Antarctica", - "continentName": "Antarctica" - }, - { - "countryCode": "AR", - "countryName": "Argentina", - "continentName": "South America" - }, - { - "countryCode": "AS", - "countryName": "American Samoa", - "continentName": "Oceania" - }, - { - "countryCode": "AT", - "countryName": "Austria", - "continentName": "Europe" - }, - { - "countryCode": "AU", - "countryName": "Australia", - "continentName": "Oceania" - }, - { - "countryCode": "AW", - "countryName": "Aruba", - "continentName": "North America" - }, - { - "countryCode": "AX", - "countryName": "Åland", - "continentName": "Europe" - }, - { - "countryCode": "AZ", - "countryName": "Azerbaijan", - "continentName": "Asia" - }, - { - "countryCode": "BA", - "countryName": "Bosnia and Herzegovina", - "continentName": "Europe" - }, - { - "countryCode": "BB", - "countryName": "Barbados", - "continentName": "North America" - }, - { - "countryCode": "BD", - "countryName": "Bangladesh", - "continentName": "Asia" - }, - { - "countryCode": "BE", - "countryName": "Belgium", - "continentName": "Europe" - }, - { - "countryCode": "BF", - "countryName": "Burkina Faso", - "continentName": "Africa" - }, - { - "countryCode": "BG", - "countryName": "Bulgaria", - "continentName": "Europe" - }, - { - "countryCode": "BH", - "countryName": "Bahrain", - "continentName": "Asia" - }, - { - "countryCode": "BI", - "countryName": "Burundi", - "continentName": "Africa" - }, - { - "countryCode": "BJ", - "countryName": "Benin", - "continentName": "Africa" - }, - { - "countryCode": "BL", - "countryName": "Saint Barthélemy", - "continentName": "North America" - }, - { - "countryCode": "BM", - "countryName": "Bermuda", - "continentName": "North America" - }, - { - "countryCode": "BN", - "countryName": "Brunei", - "continentName": "Asia" - }, - { - "countryCode": "BO", - "countryName": "Bolivia", - "continentName": "South America" - }, - { - "countryCode": "BQ", - "countryName": "Bonaire", - "continentName": "North America" - }, - { - "countryCode": "BR", - "countryName": "Brazil", - "continentName": "South America" - }, - { - "countryCode": "BS", - "countryName": "Bahamas", - "continentName": "North America" - }, - { - "countryCode": "BT", - "countryName": "Bhutan", - "continentName": "Asia" - }, - { - "countryCode": "BV", - "countryName": "Bouvet Island", - "continentName": "Antarctica" - }, - { - "countryCode": "BW", - "countryName": "Botswana", - "continentName": "Africa" - }, - { - "countryCode": "BY", - "countryName": "Belarus", - "continentName": "Europe" - }, - { - "countryCode": "BZ", - "countryName": "Belize", - "continentName": "North America" - }, - { - "countryCode": "CA", - "countryName": "Canada", - "continentName": "North America" - }, - { - "countryCode": "CC", - "countryName": "Cocos [Keeling] Islands", - "continentName": "Asia" - }, - { - "countryCode": "CD", - "countryName": "Democratic Republic of the Congo", - "continentName": "Africa" - }, - { - "countryCode": "CF", - "countryName": "Central African Republic", - "continentName": "Africa" - }, - { - "countryCode": "CG", - "countryName": "Republic of the Congo", - "continentName": "Africa" - }, - { - "countryCode": "CH", - "countryName": "Switzerland", - "continentName": "Europe" - }, - { - "countryCode": "CI", - "countryName": "Ivory Coast", - "continentName": "Africa" - }, - { - "countryCode": "CK", - "countryName": "Cook Islands", - "continentName": "Oceania" - }, - { - "countryCode": "CL", - "countryName": "Chile", - "continentName": "South America" - }, - { - "countryCode": "CM", - "countryName": "Cameroon", - "continentName": "Africa" - }, - { - "countryCode": "CN", - "countryName": "China", - "continentName": "Asia" - }, - { - "countryCode": "CO", - "countryName": "Colombia", - "continentName": "South America" - }, - { - "countryCode": "CR", - "countryName": "Costa Rica", - "continentName": "North America" - }, - { - "countryCode": "CU", - "countryName": "Cuba", - "continentName": "North America" - }, - { - "countryCode": "CV", - "countryName": "Cape Verde", - "continentName": "Africa" - }, - { - "countryCode": "CW", - "countryName": "Curacao", - "continentName": "North America" - }, - { - "countryCode": "CX", - "countryName": "Christmas Island", - "continentName": "Asia" - }, - { - "countryCode": "CY", - "countryName": "Cyprus", - "continentName": "Europe" - }, - { - "countryCode": "CZ", - "countryName": "Czechia", - "continentName": "Europe" - }, - { - "countryCode": "DE", - "countryName": "Germany", - "continentName": "Europe" - }, - { - "countryCode": "DJ", - "countryName": "Djibouti", - "continentName": "Africa" - }, - { - "countryCode": "DK", - "countryName": "Denmark", - "continentName": "Europe" - }, - { - "countryCode": "DM", - "countryName": "Dominica", - "continentName": "North America" - }, - { - "countryCode": "DO", - "countryName": "Dominican Republic", - "continentName": "North America" - }, - { - "countryCode": "DZ", - "countryName": "Algeria", - "continentName": "Africa" - }, - { - "countryCode": "EC", - "countryName": "Ecuador", - "continentName": "South America" - }, - { - "countryCode": "EE", - "countryName": "Estonia", - "continentName": "Europe" - }, - { - "countryCode": "EG", - "countryName": "Egypt", - "continentName": "Africa" - }, - { - "countryCode": "EH", - "countryName": "Western Sahara", - "continentName": "Africa" - }, - { - "countryCode": "ER", - "countryName": "Eritrea", - "continentName": "Africa" - }, - { - "countryCode": "ES", - "countryName": "Spain", - "continentName": "Europe" - }, - { - "countryCode": "ET", - "countryName": "Ethiopia", - "continentName": "Africa" - }, - { - "countryCode": "FI", - "countryName": "Finland", - "continentName": "Europe" - }, - { - "countryCode": "FJ", - "countryName": "Fiji", - "continentName": "Oceania" - }, - { - "countryCode": "FK", - "countryName": "Falkland Islands", - "continentName": "South America" - }, - { - "countryCode": "FM", - "countryName": "Micronesia", - "continentName": "Oceania" - }, - { - "countryCode": "FO", - "countryName": "Faroe Islands", - "continentName": "Europe" - }, - { - "countryCode": "FR", - "countryName": "France", - "continentName": "Europe" - }, - { - "countryCode": "GA", - "countryName": "Gabon", - "continentName": "Africa" - }, - { - "countryCode": "GB", - "countryName": "United Kingdom", - "continentName": "Europe" - }, - { - "countryCode": "GD", - "countryName": "Grenada", - "continentName": "North America" - }, - { - "countryCode": "GE", - "countryName": "Georgia", - "continentName": "Asia" - }, - { - "countryCode": "GF", - "countryName": "French Guiana", - "continentName": "South America" - }, - { - "countryCode": "GG", - "countryName": "Guernsey", - "continentName": "Europe" - }, - { - "countryCode": "GH", - "countryName": "Ghana", - "continentName": "Africa" - }, - { - "countryCode": "GI", - "countryName": "Gibraltar", - "continentName": "Europe" - }, - { - "countryCode": "GL", - "countryName": "Greenland", - "continentName": "North America" - }, - { - "countryCode": "GM", - "countryName": "Gambia", - "continentName": "Africa" - }, - { - "countryCode": "GN", - "countryName": "Guinea", - "continentName": "Africa" - }, - { - "countryCode": "GP", - "countryName": "Guadeloupe", - "continentName": "North America" - }, - { - "countryCode": "GQ", - "countryName": "Equatorial Guinea", - "continentName": "Africa" - }, - { - "countryCode": "GR", - "countryName": "Greece", - "continentName": "Europe" - }, - { - "countryCode": "GS", - "countryName": "South Georgia and the South Sandwich Islands", - "continentName": "Antarctica" - }, - { - "countryCode": "GT", - "countryName": "Guatemala", - "continentName": "North America" - }, - { - "countryCode": "GU", - "countryName": "Guam", - "continentName": "Oceania" - }, - { - "countryCode": "GW", - "countryName": "Guinea-Bissau", - "continentName": "Africa" - }, - { - "countryCode": "GY", - "countryName": "Guyana", - "continentName": "South America" - }, - { - "countryCode": "HK", - "countryName": "Hong Kong", - "continentName": "Asia" - }, - { - "countryCode": "HM", - "countryName": "Heard Island and McDonald Islands", - "continentName": "Antarctica" - }, - { - "countryCode": "HN", - "countryName": "Honduras", - "continentName": "North America" - }, - { - "countryCode": "HR", - "countryName": "Croatia", - "continentName": "Europe" - }, - { - "countryCode": "HT", - "countryName": "Haiti", - "continentName": "North America" - }, - { - "countryCode": "HU", - "countryName": "Hungary", - "continentName": "Europe" - }, - { - "countryCode": "ID", - "countryName": "Indonesia", - "continentName": "Asia" - }, - { - "countryCode": "IE", - "countryName": "Ireland", - "continentName": "Europe" - }, - { - "countryCode": "IL", - "countryName": "Israel", - "continentName": "Asia" - }, - { - "countryCode": "IM", - "countryName": "Isle of Man", - "continentName": "Europe" - }, - { - "countryCode": "IN", - "countryName": "India", - "continentName": "Asia" - }, - { - "countryCode": "IO", - "countryName": "British Indian Ocean Territory", - "continentName": "Asia" - }, - { - "countryCode": "IQ", - "countryName": "Iraq", - "continentName": "Asia" - }, - { - "countryCode": "IR", - "countryName": "Iran", - "continentName": "Asia" - }, - { - "countryCode": "IS", - "countryName": "Iceland", - "continentName": "Europe" - }, - { - "countryCode": "IT", - "countryName": "Italy", - "continentName": "Europe" - }, - { - "countryCode": "JE", - "countryName": "Jersey", - "continentName": "Europe" - }, - { - "countryCode": "JM", - "countryName": "Jamaica", - "continentName": "North America" - }, - { - "countryCode": "JO", - "countryName": "Jordan", - "continentName": "Asia" - }, - { - "countryCode": "JP", - "countryName": "Japan", - "continentName": "Asia" - }, - { - "countryCode": "KE", - "countryName": "Kenya", - "continentName": "Africa" - }, - { - "countryCode": "KG", - "countryName": "Kyrgyzstan", - "continentName": "Asia" - }, - { - "countryCode": "KH", - "countryName": "Cambodia", - "continentName": "Asia" - }, - { - "countryCode": "KI", - "countryName": "Kiribati", - "continentName": "Oceania" - }, - { - "countryCode": "KM", - "countryName": "Comoros", - "continentName": "Africa" - }, - { - "countryCode": "KN", - "countryName": "Saint Kitts and Nevis", - "continentName": "North America" - }, - { - "countryCode": "KP", - "countryName": "North Korea", - "continentName": "Asia" - }, - { - "countryCode": "KR", - "countryName": "South Korea", - "continentName": "Asia" - }, - { - "countryCode": "KW", - "countryName": "Kuwait", - "continentName": "Asia" - }, - { - "countryCode": "KY", - "countryName": "Cayman Islands", - "continentName": "North America" - }, - { - "countryCode": "KZ", - "countryName": "Kazakhstan", - "continentName": "Asia" - }, - { - "countryCode": "LA", - "countryName": "Laos", - "continentName": "Asia" - }, - { - "countryCode": "LB", - "countryName": "Lebanon", - "continentName": "Asia" - }, - { - "countryCode": "LC", - "countryName": "Saint Lucia", - "continentName": "North America" - }, - { - "countryCode": "LI", - "countryName": "Liechtenstein", - "continentName": "Europe" - }, - { - "countryCode": "LK", - "countryName": "Sri Lanka", - "continentName": "Asia" - }, - { - "countryCode": "LR", - "countryName": "Liberia", - "continentName": "Africa" - }, - { - "countryCode": "LS", - "countryName": "Lesotho", - "continentName": "Africa" - }, - { - "countryCode": "LT", - "countryName": "Lithuania", - "continentName": "Europe" - }, - { - "countryCode": "LU", - "countryName": "Luxembourg", - "continentName": "Europe" - }, - { - "countryCode": "LV", - "countryName": "Latvia", - "continentName": "Europe" - }, - { - "countryCode": "LY", - "countryName": "Libya", - "continentName": "Africa" - }, - { - "countryCode": "MA", - "countryName": "Morocco", - "continentName": "Africa" - }, - { - "countryCode": "MC", - "countryName": "Monaco", - "continentName": "Europe" - }, - { - "countryCode": "MD", - "countryName": "Moldova", - "continentName": "Europe" - }, - { - "countryCode": "ME", - "countryName": "Montenegro", - "continentName": "Europe" - }, - { - "countryCode": "MF", - "countryName": "Saint Martin", - "continentName": "North America" - }, - { - "countryCode": "MG", - "countryName": "Madagascar", - "continentName": "Africa" - }, - { - "countryCode": "MH", - "countryName": "Marshall Islands", - "continentName": "Oceania" - }, - { - "countryCode": "MK", - "countryName": "Macedonia", - "continentName": "Europe" - }, - { - "countryCode": "ML", - "countryName": "Mali", - "continentName": "Africa" - }, - { - "countryCode": "MM", - "countryName": "Myanmar [Burma]", - "continentName": "Asia" - }, - { - "countryCode": "MN", - "countryName": "Mongolia", - "continentName": "Asia" - }, - { - "countryCode": "MO", - "countryName": "Macao", - "continentName": "Asia" - }, - { - "countryCode": "MP", - "countryName": "Northern Mariana Islands", - "continentName": "Oceania" - }, - { - "countryCode": "MQ", - "countryName": "Martinique", - "continentName": "North America" - }, - { - "countryCode": "MR", - "countryName": "Mauritania", - "continentName": "Africa" - }, - { - "countryCode": "MS", - "countryName": "Montserrat", - "continentName": "North America" - }, - { - "countryCode": "MT", - "countryName": "Malta", - "continentName": "Europe" - }, - { - "countryCode": "MU", - "countryName": "Mauritius", - "continentName": "Africa" - }, - { - "countryCode": "MV", - "countryName": "Maldives", - "continentName": "Asia" - }, - { - "countryCode": "MW", - "countryName": "Malawi", - "continentName": "Africa" - }, - { - "countryCode": "MX", - "countryName": "Mexico", - "continentName": "North America" - }, - { - "countryCode": "MY", - "countryName": "Malaysia", - "continentName": "Asia" - }, - { - "countryCode": "MZ", - "countryName": "Mozambique", - "continentName": "Africa" - }, - { - "countryCode": "NA", - "countryName": "Namibia", - "continentName": "Africa" - }, - { - "countryCode": "NC", - "countryName": "New Caledonia", - "continentName": "Oceania" - }, - { - "countryCode": "NE", - "countryName": "Niger", - "continentName": "Africa" - }, - { - "countryCode": "NF", - "countryName": "Norfolk Island", - "continentName": "Oceania" - }, - { - "countryCode": "NG", - "countryName": "Nigeria", - "continentName": "Africa" - }, - { - "countryCode": "NI", - "countryName": "Nicaragua", - "continentName": "North America" - }, - { - "countryCode": "NL", - "countryName": "Netherlands", - "continentName": "Europe" - }, - { - "countryCode": "NO", - "countryName": "Norway", - "continentName": "Europe" - }, - { - "countryCode": "NP", - "countryName": "Nepal", - "continentName": "Asia" - }, - { - "countryCode": "NR", - "countryName": "Nauru", - "continentName": "Oceania" - }, - { - "countryCode": "NU", - "countryName": "Niue", - "continentName": "Oceania" - }, - { - "countryCode": "NZ", - "countryName": "New Zealand", - "continentName": "Oceania" - }, - { - "countryCode": "OM", - "countryName": "Oman", - "continentName": "Asia" - }, - { - "countryCode": "PA", - "countryName": "Panama", - "continentName": "North America" - }, - { - "countryCode": "PE", - "countryName": "Peru", - "continentName": "South America" - }, - { - "countryCode": "PF", - "countryName": "French Polynesia", - "continentName": "Oceania" - }, - { - "countryCode": "PG", - "countryName": "Papua New Guinea", - "continentName": "Oceania" - }, - { - "countryCode": "PH", - "countryName": "Philippines", - "continentName": "Asia" - }, - { - "countryCode": "PK", - "countryName": "Pakistan", - "continentName": "Asia" - }, - { - "countryCode": "PL", - "countryName": "Poland", - "continentName": "Europe" - }, - { - "countryCode": "PM", - "countryName": "Saint Pierre and Miquelon", - "continentName": "North America" - }, - { - "countryCode": "PN", - "countryName": "Pitcairn Islands", - "continentName": "Oceania" - }, - { - "countryCode": "PR", - "countryName": "Puerto Rico", - "continentName": "North America" - }, - { - "countryCode": "PS", - "countryName": "Palestine", - "continentName": "Asia" - }, - { - "countryCode": "PT", - "countryName": "Portugal", - "continentName": "Europe" - }, - { - "countryCode": "PW", - "countryName": "Palau", - "continentName": "Oceania" - }, - { - "countryCode": "PY", - "countryName": "Paraguay", - "continentName": "South America" - }, - { - "countryCode": "QA", - "countryName": "Qatar", - "continentName": "Asia" - }, - { - "countryCode": "RE", - "countryName": "Réunion", - "continentName": "Africa" - }, - { - "countryCode": "RO", - "countryName": "Romania", - "continentName": "Europe" - }, - { - "countryCode": "RS", - "countryName": "Serbia", - "continentName": "Europe" - }, - { - "countryCode": "RU", - "countryName": "Russia", - "continentName": "Europe" - }, - { - "countryCode": "RW", - "countryName": "Rwanda", - "continentName": "Africa" - }, - { - "countryCode": "SA", - "countryName": "Saudi Arabia", - "continentName": "Asia" - }, - { - "countryCode": "SB", - "countryName": "Solomon Islands", - "continentName": "Oceania" - }, - { - "countryCode": "SC", - "countryName": "Seychelles", - "continentName": "Africa" - }, - { - "countryCode": "SD", - "countryName": "Sudan", - "continentName": "Africa" - }, - { - "countryCode": "SE", - "countryName": "Sweden", - "continentName": "Europe" - }, - { - "countryCode": "SG", - "countryName": "Singapore", - "continentName": "Asia" - }, - { - "countryCode": "SH", - "countryName": "Saint Helena", - "continentName": "Africa" - }, - { - "countryCode": "SI", - "countryName": "Slovenia", - "continentName": "Europe" - }, - { - "countryCode": "SJ", - "countryName": "Svalbard and Jan Mayen", - "continentName": "Europe" - }, - { - "countryCode": "SK", - "countryName": "Slovakia", - "continentName": "Europe" - }, - { - "countryCode": "SL", - "countryName": "Sierra Leone", - "continentName": "Africa" - }, - { - "countryCode": "SM", - "countryName": "San Marino", - "continentName": "Europe" - }, - { - "countryCode": "SN", - "countryName": "Senegal", - "continentName": "Africa" - }, - { - "countryCode": "SO", - "countryName": "Somalia", - "continentName": "Africa" - }, - { - "countryCode": "SR", - "countryName": "Suriname", - "continentName": "South America" - }, - { - "countryCode": "SS", - "countryName": "South Sudan", - "continentName": "Africa" - }, - { - "countryCode": "ST", - "countryName": "São Tomé and Príncipe", - "continentName": "Africa" - }, - { - "countryCode": "SV", - "countryName": "El Salvador", - "continentName": "North America" - }, - { - "countryCode": "SX", - "countryName": "Sint Maarten", - "continentName": "North America" - }, - { - "countryCode": "SY", - "countryName": "Syria", - "continentName": "Asia" - }, - { - "countryCode": "SZ", - "countryName": "Swaziland", - "continentName": "Africa" - }, - { - "countryCode": "TC", - "countryName": "Turks and Caicos Islands", - "continentName": "North America" - }, - { - "countryCode": "TD", - "countryName": "Chad", - "continentName": "Africa" - }, - { - "countryCode": "TF", - "countryName": "French Southern Territories", - "continentName": "Antarctica" - }, - { - "countryCode": "TG", - "countryName": "Togo", - "continentName": "Africa" - }, - { - "countryCode": "TH", - "countryName": "Thailand", - "continentName": "Asia" - }, - { - "countryCode": "TJ", - "countryName": "Tajikistan", - "continentName": "Asia" - }, - { - "countryCode": "TK", - "countryName": "Tokelau", - "continentName": "Oceania" - }, - { - "countryCode": "TL", - "countryName": "East Timor", - "continentName": "Oceania" - }, - { - "countryCode": "TM", - "countryName": "Turkmenistan", - "continentName": "Asia" - }, - { - "countryCode": "TN", - "countryName": "Tunisia", - "continentName": "Africa" - }, - { - "countryCode": "TO", - "countryName": "Tonga", - "continentName": "Oceania" - }, - { - "countryCode": "TR", - "countryName": "Turkey", - "continentName": "Asia" - }, - { - "countryCode": "TT", - "countryName": "Trinidad and Tobago", - "continentName": "North America" - }, - { - "countryCode": "TV", - "countryName": "Tuvalu", - "continentName": "Oceania" - }, - { - "countryCode": "TW", - "countryName": "Taiwan", - "continentName": "Asia" - }, - { - "countryCode": "TZ", - "countryName": "Tanzania", - "continentName": "Africa" - }, - { - "countryCode": "UA", - "countryName": "Ukraine", - "continentName": "Europe" - }, - { - "countryCode": "UG", - "countryName": "Uganda", - "continentName": "Africa" - }, - { - "countryCode": "UM", - "countryName": "U.S. Minor Outlying Islands", - "continentName": "Oceania" - }, - { - "countryCode": "US", - "countryName": "United States", - "continentName": "North America" - }, - { - "countryCode": "UY", - "countryName": "Uruguay", - "continentName": "South America" - }, - { - "countryCode": "UZ", - "countryName": "Uzbekistan", - "continentName": "Asia" - }, - { - "countryCode": "VA", - "countryName": "Vatican City", - "continentName": "Europe" - }, - { - "countryCode": "VC", - "countryName": "Saint Vincent and the Grenadines", - "continentName": "North America" - }, - { - "countryCode": "VE", - "countryName": "Venezuela", - "continentName": "South America" - }, - { - "countryCode": "VG", - "countryName": "British Virgin Islands", - "continentName": "North America" - }, - { - "countryCode": "VI", - "countryName": "U.S. Virgin Islands", - "continentName": "North America" - }, - { - "countryCode": "VN", - "countryName": "Vietnam", - "continentName": "Asia" - }, - { - "countryCode": "VU", - "countryName": "Vanuatu", - "continentName": "Oceania" - }, - { - "countryCode": "WF", - "countryName": "Wallis and Futuna", - "continentName": "Oceania" - }, - { - "countryCode": "WS", - "countryName": "Samoa", - "continentName": "Oceania" - }, - { - "countryCode": "XK", - "countryName": "Kosovo", - "continentName": "Europe" - }, - { - "countryCode": "YE", - "countryName": "Yemen", - "continentName": "Asia" - }, - { - "countryCode": "YT", - "countryName": "Mayotte", - "continentName": "Africa" - }, - { - "countryCode": "ZA", - "countryName": "South Africa", - "continentName": "Africa" - }, - { - "countryCode": "ZM", - "countryName": "Zambia", - "continentName": "Africa" - }, - { - "countryCode": "ZW", - "countryName": "Zimbabwe", - "continentName": "Africa" - } - ] -} +# import json, csv +# +# def getData(): +# with open("33_country_codes.json", "r") as file: +# data = json.load(file) +# print(data) +# +# getData() +# + + +codes = {"country": [ + { + "countryCode": "AD", + "countryName": "Andorra", + "continentName": "Europe" + }, + { + "countryCode": "AE", + "countryName": "United Arab Emirates", + "continentName": "Asia" + }, + { + "countryCode": "AF", + "countryName": "Afghanistan", + "continentName": "Asia" + } + ] + } + +codes_list = [] +countries = [] +continents = [] + +#print(codes["country"][0]["countryName"]) + +for country in codes["country"]: + codes_list.append(country["countryCode"]) + countries.append(country["countryName"]) + continents.append(country["continentName"]) + + +return countryCodes, countries, continents + + +def saveCSV(): + with open("myCSV.csv","w") as file: + writer = csv.writer(file) + writer.writerow(["coutry code","country name","continent name"]) + print(countryCodes, countries, continents) + for i in range(1,len (countries)): + writer:writerow(cointryCodes[i],countries[i],continents[i]) + + +countryCodes, countries, continents = getData() + +saveCSV(countryCodes, countries, continents) + + +# print("Country Codes:", codes_list) +# print("Countries:", countries) +# print("Continents:", continents) \ No newline at end of file