コード例 #1
0
ファイル: viewsets.py プロジェクト: fmeurou/djangophysics
 def borders(self, request, alpha_2):
     """
     Send borders for a specific country
     """
     try:
         c = CountryInfo(alpha_2)
         return Response(c.borders(), content_type="application/json")
     except KeyError:
         return Response("Unknown country or no info for this country",
                         status=HTTP_404_NOT_FOUND)
コード例 #2
0
def country_info(country_name):
    d = []
    country = CountryInfo(country_name)
    d.append(["name", country.name().capitalize()])
    d.append(["capital", country.capital().capitalize()])
    d.append(["region", country.region().capitalize()])
    d.append(["currency", country.currencies()])
    d.append(["area", country.area()])
    d.append(["population", country.population()])
    d.append(["languages", country.languages()])
    d.append(["borders", country.borders()])
    d.append(["calling code", country.calling_codes()])
    d.append(["lat/long", country.capital_latlng()])
    d.append(["code", country.iso(2)])
    return d
コード例 #3
0
def createBorderDict(countrySet):
    borderDict = {}
    borderSet = set()
    for c in countrySet:
        try:
            borders = []
            country = CountryInfo(c)
            borders_codes = country.borders()
            for b in borders_codes:
                border = pycountry.countries.get(alpha_3=b).name
                borders.append(border)
                borderSet.add(border)
            borderDict[c] = borders
        except:
            borderDict[c] = borders

    return borderDict, borderSet
コード例 #4
0
ファイル: mapcreator.py プロジェクト: maksprotsyk/FilmingMap
def bordering_countries(country_name: str) -> set:
    """
    Finds bordering countries for the given country
    """
    rename_dct = {'United States': 'USA', 'United Kingdom': 'UK'}
    try:
        country = CountryInfo(country_name)
        converter = CountryConverter(include_obsolete=True)
        countries = converter.convert(country.borders(), to='name_short')
        if type(countries) == str:
            countries = {countries}
        else:
            countries = set(countries)
            countries.add(country_name)
        for name in rename_dct:
            if name in countries:
                countries.remove(name)
                countries.add(rename_dct[name])
        return countries
    except Exception:
        print('Invalid Country')
コード例 #5
0
def trip():
    if (request.args['location'] == '' or request.args['date'] == ''):
        return redirect(url_for('index'))

    phoneValid = "none"
    print(request.args)

    if 'phone' in request.args:
        if request.args['phone'] == "valid":
            phoneValid = "true"
        else:
            phoneValid = "false"

    country = coco.convert(
        names=[request.args['location'].split(',')[-1].strip()],
        to="name_short")
    iso3_country = coco.convert(
        names=[request.args['location'].split(',')[-1].strip()], to="ISO3")
    city = request.args['location'].split(',')[0].strip()

    cinfo = CountryInfo(country)
    neighbors = cinfo.borders()

    d = datetime.datetime.strptime(request.args['date'], "%m/%d/%Y")
    dstart = d - datetime.timedelta(days=1)
    display_date = d.strftime('%d %B %Y')
    query_date_start = dstart.strftime('%Y-%m-%d')
    query_date_end = d.strftime('%Y-%m-%d')
    query_local_date = d.strftime('%-m/%-d/%Y')
    print(query_date_start)
    print(query_date_end)
    print(query_local_date)

    display_location = city + ", " + country

    locCDCThreat = 0
    neighborCDCThreat = 0

    locPredicted = 0
    dangerScore = 0
    dangerous = False

    valueLocThreatLevel = 0
    threatNeighbors = []

    with open("cdc-data.json") as file:
        data = json.load(file)
        if iso3_country in data.keys() and data[iso3_country] > 1:
            locCDCThreat = 1
            valueLocThreatLevel = data[iso3_country]

        # get neighbors in threat list
        threatNeighbors = {
            k: v
            for k, v in data.items() if k in neighbors and data[k] > 1
        }

        if len(threatNeighbors) > 0:
            print(threatNeighbors)
            neighborCDCThreat = 1

    for k in threatNeighbors.keys():
        threatNeighbors[coco.convert(names=k,
                                     to="name_short")] = threatNeighbors.pop(k)

    print(threatNeighbors)
    valueThreatNeighbors = ""

    for k in threatNeighbors.keys():
        valueThreatNeighbors += k + " - Level " + str(threatNeighbors[k])

    confirmedCaseCount = 0

    with open("data.csv") as file:
        reader = csv.reader(file, delimiter=",")
        next(reader)

        for row in reader:
            if row[9] == query_local_date and coco.convert(
                    names=[row[10]
                           ], to="name_short").lower() == country.lower():
                confirmedCaseCount = row[4]

    print(confirmedCaseCount)

    if int(confirmedCaseCount) > 25:
        locPredicted = 1

    params = [locCDCThreat, neighborCDCThreat, locPredicted]
    if params[0] == 1:
        dangerScore += 999999

    if params[1] == 1:
        dangerScore += 1

    if params[2] == 1:
        dangerScore += 1

    if dangerScore >= 2:
        dangerous = True

    return render_template('trip.html',
                           confirmedCaseCount=confirmedCaseCount,
                           query_date_start=query_date_start,
                           query_date_end=query_date_end,
                           valueLocThreatLevel=valueLocThreatLevel,
                           valueThreatNeighbors=valueThreatNeighbors,
                           locCDCThreat=locCDCThreat,
                           params=params,
                           dangerous=dangerous,
                           display_location=display_location,
                           display_date=display_date,
                           phoneValid=phoneValid)
コード例 #6
0
data1 = country.alt_spellings()
print(data1)

data2 = country.capital()
print(data2)

data3 = country.currencies()
print(data3)

data4 = country.languages()
print(data4)

data5 = country.timezones()
print(data5)

data6 = country.area()
print(data6)

data7 = country.borders()
print(data7)

data8 = country.calling_codes()
print(data8)

data9 = country.wiki()
print(data9)

data10 = country.info()
for x, y in data10.items():
    print(f'{x} --> {y}')
コード例 #7
0
    print(currency, end=', ')

country_lang = country.languages()
print('\n\nLanguages:')
for languages in country_lang:
    print(languages, end=', ')

country_timezone = country.timezones()
print('\n\nTime-Zone:')
for timezones in country_timezone:
    print(timezones, end=', ')

country_area = country.area()
print(f'\n\nCountry Area:\n{country_area}')

country_borders = country.borders()
print('\nBorders:')
for border in country_borders:
    print(border, end=', ')

calling_codes = country.calling_codes()
print('\n\nCall Code:')
for call_code in calling_codes:
    print(call_code)

country_region = country.region()
print(f'\nRegion:\n{country_region}')

sub_region = country.subregion()
print(f'\nSub-Region:\n{sub_region}')