根据iso标准3166-1,一个国家的世界(awoc)是一个功能齐全的库,它提供了一个简单的层来访问关于世界大陆和国家的多个数据。

a-world-of-countries的Python项目详细描述


一个由国家组成的世界

 src= 《国家世界》(AWOC)是一个功能齐全的库,根据ISO标准3166-1,它提供了一个方便的层来访问有关世界大陆和国家的多个数据。

注意:此库的nodejs版本在这里提供

安装

$ pip install a-world-of-countries

如何使用awoc库

# Import the AWOC package.importawoc# Initialize the AWOC class.my_world=awoc.AWOC()# Let's retrieve the full list of nations of Europe.countries_of_europe=my_world.get_countries_list_of('Europe')# It returns: [ 'Albania', 'Andorra', 'Austria', 'Belarus', 'Belgium', and so on... ]# We can get the whole country data as well.italy_data=my_world.get_country_data('Italy')"""Returns:{  'Country Name': 'Italy',  ISO2: 'IT',  ISO3: 'ITA',  TLD: 'it',  FIPS: 'IT',  'ISO Numeric': '380',  GeoNameID: '3175395',  E164: '39',  'Phone Code': '39',  'Continent Name': 'Europe',  'Continent Code': 'eu',  Capital: 'Rome',  'Time Zone in Capital': 'Europe/Rome',  'Currency Name': 'Euro',  Languages:   'Italian (official), German (parts of Trentino-Alto Adige region are predominantly German-speaking), French (small French-speaking minority in Valle d\'Aosta region), Slovene (Slovene-speaking minority in the Trieste-Gorizia area)',  'Area KM2': '301230'}"""

工作原理

一个国家的世界是一个基于world.json文件的库,它保存了我们需要的所有大陆和国家的信息。该文件正在不断演变,这个以js类形式编码的库公开了一系列方法,您可以使用这些方法访问这些数据,而无需编写数据提取代码。

data/world.json(称为global world data object,gwdo)文件中,每个国家都被编码为一个对象/w,具有以下属性:

  • 国家名称-国家的全称。例如,"意大利"
  • ISO2-ISO2/3166-1α-2国家代码。例如,"it"
  • ISO3-ISO2/3166-1α-2国家代码。例如,"ITA"
  • tld-顶级域代码。例如,"it"
  • 《联邦信息处理标准》(FIPS)规范。例如,"it"
  • ISO数字-ISO 3166-1数字代码。例如"380"
  • 地理名称id-地理名称id。例如"3175395"
  • E164-国际公共电信编号计划代码。例如,"39"
  • 电话号码-国家/地区电话号码。例如,"39"
  • 大陆名称-该国所属大陆的全称。例如"欧洲"
  • 大陆代码-该国所属的大陆代码。例如"eu"
  • 首都-国家首都。例如"罗马"
  • 首都时区-国家时区的完整定义。例如,"欧洲/罗马"
  • 货币名称-完整的货币名称。例如"欧元"
  • 语言-一个详细的口语列表。例如,"意大利语(官方)、德语(特伦蒂诺-阿尔托-阿迪奇地区的部分地区主要讲德语)、法语(奥斯塔山谷地区讲法语的少数民族)、斯洛文尼亚语(的里雅斯特-戈里兹地区讲斯洛文尼亚语的少数民族)"
  • 面积km2-以km2/mi2为单位的地理扩展面积。例如,"301230"

AWOC可用方法

整个库代码都有大量注释,因此每个类属性或方法都会公开其用途的详细说明。请随意检查代码并找到您喜欢的工作方法。以下是所有AWOC可用方法的更新列表。

世界大陆

有关世界大陆的所有awoc.js方法的列表。

获取大陆列表()

说明:以字符串形式返回大陆名称列表。

# Let's fetch a list of all continents of planet Earth.continents_list=my_world.get_continents_list()# Returns: ['Africa', 'Antarctica', 'Asia', 'Europe', 'North America', 'Oceania', 'South America']

获取_大陆()

说明:返回大陆对象列表。

# Let's fetch a list of all continents of planet Earth in form of data objects.continents_data=my_world.get_continents()""" Returns: [  { 'Continent Code': 'af', 'Continent Name': 'Africa' },  { 'Continent Code': 'an', 'Continent Name': 'Antarctica' },  { 'Continent Code': 'as', 'Continent Name': 'Asia' },  { 'Continent Code': 'eu', 'Continent Name': 'Europe' },  { 'Continent Code': 'na', 'Continent Name': 'North America' },  { 'Continent Code': 'oc', 'Continent Name': 'Oceania' },  { 'Continent Code': 'sa', 'Continent Name': 'South America' } ]"""

世界各国

获取国家(地区)

说明:此方法从gwod中提取所有国家的数据。它按国家/地区名称执行额外的排序,以确保正确的字母顺序,而不管gwod json对象的顺序(这可能会失败)。

# Let's fetch the data of all countries of the world.countries=my_world.get_countries()""" Returns the full list of country objects. [... { 'Country Name': 'Cocos Islands', ISO2: 'CC', ISO3: 'CCK', TLD: 'cc', .. }, { 'Country Name': 'Colombia', ISO2: 'CO', ISO3: 'COL', TLD: 'co', ... }, ... ]"""

获取国家数据(国家名称,字段=false)

说明:此方法返回单个国家/地区对象数据。如果指定了字段参数,则该方法将返回其值。有关可用字段的列表,请检查上面的国家/地区数据结构。

# We can fetch a single value from the country data object.capital_of_spain=my_world.get_country_data('Spain','Capital')# Returns: "Madrid".# ... or just the full object.spain_data=my_world.get_country_data('Spain')# Returns: {'Country Name': 'Spain', ISO2: 'ES', ISO3: 'ESP', TLD: 'es', ... }

获取"国家"列表()

说明:此方法返回按字母顺序排序的国家名称列表。

# Let's fetch a list of world nations.get_countries_list=my_world.get_countries_list()# Returns: ['Afghanistan', 'Albania', 'Algeria', 'American Samoa', 'Andorra', ...]

获取(大陆名称)的国家列表

说明:此方法返回按字母顺序为特定大陆排序的国家名称列表。

# Let's fetch the list of nations of Europe.nations_of_europe=my_world.get_countries_list_of('Europe')# Returns: [ 'Albania', 'Andorra', 'Austria', 'Belarus', 'Belgium', ...]

获取(大陆名称)的国家/地区数据

说明:此方法返回按特定大陆的每个国家名称按字母顺序排序的国家对象列表。

# Let's fetch the list of nations of Europe in form of country objects.nations_of_europe=my_world.get_countries_data_of('Europe')""" Returns: [  { 'Country Name': 'Albania', ISO2: 'AL', ISO3: 'ALB', ... },  { 'Country Name': 'Andorra', ISO2: 'AD', ISO3: 'AND', ... } ]"""

获取国家/地区ISO2(国家/地区名称)

说明:此方法返回指定国家的ISO2代码。

$ pip install a-world-of-countries
0

获取"国家"iso3(国家名称)

说明:此方法返回指定国家的ISO3代码。

$ pip install a-world-of-countries
1

获取国家/地区TLD(国家/地区名称)

说明:此方法返回指定国家/地区的顶级域(TLD)。

$ pip install a-world-of-countries
2

获取国家/地区FIPS(国家/地区名称)

说明:此方法返回指定国家/地区的FIPS国家/地区代码。

$ pip install a-world-of-countries
3

获取国家/地区ISO数字(国家/地区名称)

说明:此方法返回指定国家/地区的ISO数字代码。

$ pip install a-world-of-countries
4

获取国家地理名称ID(国家名称)

说明:此方法返回指定国家的地理名称ID。

$ pip install a-world-of-countries
5

获取国家/地区e164(国家/地区名称)

说明:此方法返回指定国家/地区的E164代码。

$ pip install a-world-of-countries
6

获取国家/地区电话号码(国家/地区名称)

说明:此方法返回指定国家/地区的电话号码。

$ pip install a-world-of-countries
7

获取国家大陆名称(国家名称)

说明:此方法返回指定国家所属的大陆数据。

$ pip install a-world-of-countries
8

获取国家大陆代码(国家名称)

说明:此方法返回指定国家所属的大陆代码。

$ pip install a-world-of-countries
9

获取国家首都(国家名称)

说明:此方法返回指定国家的首都。

# Import the AWOC package.importawoc# Initialize the AWOC class.my_world=awoc.AWOC()# Let's retrieve the full list of nations of Europe.countries_of_europe=my_world.get_countries_list_of('Europe')# It returns: [ 'Albania', 'Andorra', 'Austria', 'Belarus', 'Belgium', and so on... ]# We can get the whole country data as well.italy_data=my_world.get_country_data('Italy')"""Returns:{  'Country Name': 'Italy',  ISO2: 'IT',  ISO3: 'ITA',  TLD: 'it',  FIPS: 'IT',  'ISO Numeric': '380',  GeoNameID: '3175395',  E164: '39',  'Phone Code': '39',  'Continent Name': 'Europe',  'Continent Code': 'eu',  Capital: 'Rome',  'Time Zone in Capital': 'Europe/Rome',  'Currency Name': 'Euro',  Languages:   'Italian (official), German (parts of Trentino-Alto Adige region are predominantly German-speaking), French (small French-speaking minority in Valle d\'Aosta region), Slovene (Slovene-speaking minority in the Trieste-Gorizia area)',  'Area KM2': '301230'}"""
0

获取国家时区(国家名称)

说明:此方法返回特定国家/地区的时区值。

# Import the AWOC package.importawoc# Initialize the AWOC class.my_world=awoc.AWOC()# Let's retrieve the full list of nations of Europe.countries_of_europe=my_world.get_countries_list_of('Europe')# It returns: [ 'Albania', 'Andorra', 'Austria', 'Belarus', 'Belgium', and so on... ]# We can get the whole country data as well.italy_data=my_world.get_country_data('Italy')"""Returns:{  'Country Name': 'Italy',  ISO2: 'IT',  ISO3: 'ITA',  TLD: 'it',  FIPS: 'IT',  'ISO Numeric': '380',  GeoNameID: '3175395',  E164: '39',  'Phone Code': '39',  'Continent Name': 'Europe',  'Continent Code': 'eu',  Capital: 'Rome',  'Time Zone in Capital': 'Europe/Rome',  'Currency Name': 'Euro',  Languages:   'Italian (official), German (parts of Trentino-Alto Adige region are predominantly German-speaking), French (small French-speaking minority in Valle d\'Aosta region), Slovene (Slovene-speaking minority in the Trieste-Gorizia area)',  'Area KM2': '301230'}"""
1

获取国家货币名称(国家名称)

说明:此方法返回指定国家的货币名称。

# Import the AWOC package.importawoc# Initialize the AWOC class.my_world=awoc.AWOC()# Let's retrieve the full list of nations of Europe.countries_of_europe=my_world.get_countries_list_of('Europe')# It returns: [ 'Albania', 'Andorra', 'Austria', 'Belarus', 'Belgium', and so on... ]# We can get the whole country data as well.italy_data=my_world.get_country_data('Italy')"""Returns:{  'Country Name': 'Italy',  ISO2: 'IT',  ISO3: 'ITA',  TLD: 'it',  FIPS: 'IT',  'ISO Numeric': '380',  GeoNameID: '3175395',  E164: '39',  'Phone Code': '39',  'Continent Name': 'Europe',  'Continent Code': 'eu',  Capital: 'Rome',  'Time Zone in Capital': 'Europe/Rome',  'Currency Name': 'Euro',  Languages:   'Italian (official), German (parts of Trentino-Alto Adige region are predominantly German-speaking), French (small French-speaking minority in Valle d\'Aosta region), Slovene (Slovene-speaking minority in the Trieste-Gorizia area)',  'Area KM2': '301230'}"""
2

按货币获取"国家"列表(货币名称,大陆名称=false)

说明:此方法返回按特定货币筛选的国家名称列表。

# Import the AWOC package.importawoc# Initialize the AWOC class.my_world=awoc.AWOC()# Let's retrieve the full list of nations of Europe.countries_of_europe=my_world.get_countries_list_of('Europe')# It returns: [ 'Albania', 'Andorra', 'Austria', 'Belarus', 'Belgium', and so on... ]# We can get the whole country data as well.italy_data=my_world.get_country_data('Italy')"""Returns:{  'Country Name': 'Italy',  ISO2: 'IT',  ISO3: 'ITA',  TLD: 'it',  FIPS: 'IT',  'ISO Numeric': '380',  GeoNameID: '3175395',  E164: '39',  'Phone Code': '39',  'Continent Name': 'Europe',  'Continent Code': 'eu',  Capital: 'Rome',  'Time Zone in Capital': 'Europe/Rome',  'Currency Name': 'Euro',  Languages:   'Italian (official), German (parts of Trentino-Alto Adige region are predominantly German-speaking), French (small French-speaking minority in Valle d\'Aosta region), Slovene (Slovene-speaking minority in the Trieste-Gorizia area)',  'Area KM2': '301230'}"""
3

按货币获取各国数据(货币名称,大陆名称=false)

说明:此方法返回特定货币的一个或多个国家/地区对象数据。

# Import the AWOC package.importawoc# Initialize the AWOC class.my_world=awoc.AWOC()# Let's retrieve the full list of nations of Europe.countries_of_europe=my_world.get_countries_list_of('Europe')# It returns: [ 'Albania', 'Andorra', 'Austria', 'Belarus', 'Belgium', and so on... ]# We can get the whole country data as well.italy_data=my_world.get_country_data('Italy')"""Returns:{  'Country Name': 'Italy',  ISO2: 'IT',  ISO3: 'ITA',  TLD: 'it',  FIPS: 'IT',  'ISO Numeric': '380',  GeoNameID: '3175395',  E164: '39',  'Phone Code': '39',  'Continent Name': 'Europe',  'Continent Code': 'eu',  Capital: 'Rome',  'Time Zone in Capital': 'Europe/Rome',  'Currency Name': 'Euro',  Languages:   'Italian (official), German (parts of Trentino-Alto Adige region are predominantly German-speaking), French (small French-speaking minority in Valle d\'Aosta region), Slovene (Slovene-speaking minority in the Trieste-Gorizia area)',  'Area KM2': '301230'}"""
4

获取国家语言(国家名称)

说明:此方法返回特定国家/地区的语言列表。

# Import the AWOC package.importawoc# Initialize the AWOC class.my_world=awoc.AWOC()# Let's retrieve the full list of nations of Europe.countries_of_europe=my_world.get_countries_list_of('Europe')# It returns: [ 'Albania', 'Andorra', 'Austria', 'Belarus', 'Belgium', and so on... ]# We can get the whole country data as well.italy_data=my_world.get_country_data('Italy')"""Returns:{  'Country Name': 'Italy',  ISO2: 'IT',  ISO3: 'ITA',  TLD: 'it',  FIPS: 'IT',  'ISO Numeric': '380',  GeoNameID: '3175395',  E164: '39',  'Phone Code': '39',  'Continent Name': 'Europe',  'Continent Code': 'eu',  Capital: 'Rome',  'Time Zone in Capital': 'Europe/Rome',  'Currency Name': 'Euro',  Languages:   'Italian (official), German (parts of Trentino-Alto Adige region are predominantly German-speaking), French (small French-speaking minority in Valle d\'Aosta region), Slovene (Slovene-speaking minority in the Trieste-Gorizia area)',  'Area KM2': '301230'}"""
5

获取"国家"区域(国家名称,单位为"km2")

说明:此方法返回以km2或mi2为单位的国家面积。

# Import the AWOC package.importawoc# Initialize the AWOC class.my_world=awoc.AWOC()# Let's retrieve the full list of nations of Europe.countries_of_europe=my_world.get_countries_list_of('Europe')# It returns: [ 'Albania', 'Andorra', 'Austria', 'Belarus', 'Belgium', and so on... ]# We can get the whole country data as well.italy_data=my_world.get_country_data('Italy')"""Returns:{  'Country Name': 'Italy',  ISO2: 'IT',  ISO3: 'ITA',  TLD: 'it',  FIPS: 'IT',  'ISO Numeric': '380',  GeoNameID: '3175395',  E164: '39',  'Phone Code': '39',  'Continent Name': 'Europe',  'Continent Code': 'eu',  Capital: 'Rome',  'Time Zone in Capital': 'Europe/Rome',  'Currency Name': 'Euro',  Languages:   'Italian (official), German (parts of Trentino-Alto Adige region are predominantly German-speaking), French (small French-speaking minority in Valle d\'Aosta region), Slovene (Slovene-speaking minority in the Trieste-Gorizia area)',  'Area KM2': '301230'}"""
6

更改日志

1.0.0

初始版本。

许可证

麻省理工学院

学分

  • 通过以下方式覆盖图像:freepik

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
当IntellijIDEA打开时,java Gluon SceneBuilder不会打开FXML文件   java在启动tomcat后执行某些操作   如何在Java中使用Google Cloud语音API在识别语音时录制音频   Java端口转发性能   写入Java项目文件夹中的txt文件   使用java中的命令提示符cmd   对象类型方法的java assertequal   java如何通过应用程序在设备上更新Android操作系统   java是否可以在@BeforeClass注释方法中运行Android Espresso单元测试?   java如何使用JMS API将NACK从Solace侦听器发送到Solace队列?   如何将Java和C集成到同一个项目中?   Android中的java安装\u失败\u冲突\u提供程序   java时间输入和显示   使用GAE数据存储对实体用户进行java身份验证时返回null   netbeans向Java运行时添加本机DLL时出现问题(JIntellitype)