Exemple #1
0
def createMap(countryCode, debug=False):
    print(countryCode)
    country = COUNTRIES[countryCode]

    everyOtherCountry = list(COUNTRIES.keys())
    everyOtherCountry.remove(countryCode)
    custom_style = Style(show_legend=False, colors=('#000000', '#BBBBBB'))

    worldmap = pygal.maps.world.World(show_legend=False,
                                      show_title=False,
                                      style=custom_style)
    worldmap.add(
        country,
        [countryCode],
    )

    worldmap.add(
        'everyone else',
        everyOtherCountry,
    )
    if debug:
        worldmap.render_in_browser()
    else:
        worldmap.render_to_file('%s/%s/map.svg' %
                                (config('countryDirectory'), country))
Exemple #2
0
def get_country_code(country_name):
    """根据指定的国家, 返回Pygal使用的两个字母的国别码"""
    for country_code in sorted(COUNTRIES.keys()):
        for code, name in COUNTRIES.items():
            if name == country_name:
                return code

        # 如果没有找到指定的国家, 就返回None
        return None
Exemple #3
0
# import pygal
import pygal

# import Style class from pygal.style
from pygal.style import Style
import random

import csv

from pygal.maps.world import COUNTRIES
print(COUNTRIES)
#pick a random country
countryCode = random.choice(list(COUNTRIES.keys()))
country = COUNTRIES[countryCode]
print(country)
print(countryCode)

everyOtherCountry = list(COUNTRIES.keys())
everyOtherCountry.remove(countryCode)
print(everyOtherCountry)
# create a world map,
# Style class is used for using
# the custom colours in the map,
from pygal.style import Style
#custom_style = Style(
#  colors=('#FF00000', '#000000'))
custom_style = Style(show_legend=False, colors=('#000000', '#BBBBBB'))

worldmap = pygal.maps.world.World(show_legend=False,
                                  show_title=False,
                                  style=custom_style)
from pygal.maps.world import COUNTRIES
for country_code in sorted(COUNTRIES.keys()):
    print(country_code, COUNTRIES[country_code])
from google_images_search import GoogleImagesSearch
from decouple import config
import os
from PIL import Image
from mapCreator import *
from pygal.maps.world import COUNTRIES
import random
import urllib

# you can provide API key and CX using arguments,
# or you can set environment variables: GCS_DEVELOPER_KEY, GCS_CX
gis = GoogleImagesSearch(config('API_KEY'), config('CX'))

countryCode = random.choice(list(COUNTRIES.keys()))
country = COUNTRIES[countryCode]
print(country)
print(countryCode)

try:
    os.mkdir(config('countryDirectory'))
except:
    pass

try:
    os.mkdir("%s/%s" % (config('countryDirectory'), country))
except:
    pass

createMap(countryCode)

terms = [
Exemple #6
0
from pygal.maps.world import COUNTRIES

for country_code in sorted(COUNTRIES.keys()):
	print(country_code, COUNTRIES[country_code])
Exemple #7
0
def get_country_code(country_name):
    for country_code in COUNTRIES.keys():
        if COUNTRIES[country_code] == country_name:
            return country_code
    return None
Exemple #8
0
 def print_countries(self):
     ''' prints out each of the country codes
     along side each of the country names'''
     for code in sorted(COUNTRIES.keys()):
         print(code, COUNTRIES[code])
import json
from country_codes import get_country_code
from pygal.maps.world import COUNTRIES

filename = 'population_data.json'
with open(filename) as f:
    data = json.load(f)
    for item in data:
        country = item['Country Name']
        code = get_country_code(country)
        if len(str(code)) > 2:
            item['Country Code'] = item['Country Code'].replace(
                str(code), str(COUNTRIES.keys()))
with open(filename) as r:
    json.dump(f, r, indent=2)

print(data)
Exemple #10
0
from country_codes import get_country_code
import datetime

now = datetime.datetime.now()

# Make an API call and store the response
url = 'https://api.covid19api.com/summary'
r = requests.get(url)

# Store API reponse in a variable
response_dict = r.json()
countries_list = response_dict['Countries']
global_data = response_dict['Global']

# Get country codes from COUNTRIES
country_codes = [code for code in COUNTRIES.keys()]

corona_virus = {}
for country in countries_list:
    country_code = country['CountryCode'].lower()
    # total_deaths = country['TotalDeaths']
    if country_code in country_codes:
        total_confirmed = country['TotalConfirmed']
        corona_virus[country_code] = total_confirmed

# Group the countries into 3 levels
cv1, cv2, cv3 = {}, {}, {}
for cd, cv in corona_virus.items():
    if cv < 1000:
        cv1[cd] = cv
    elif cv < 100000:
from pygal.maps.world import COUNTRIES



for country_code in COUNTRIES.keys():
    print(country_code,COUNTRIES[country_code])