Python is short-world epidemic map

Crawling the world epidemic map#

Overview##

Code##

# Import the required database
import json #Processing json format
import jsonpath #Processing json data
import requests #Request library
from pyecharts.charts import Map,Geo #Drawing
from pyecharts import options as opts #Import configuration items
from pyecharts.globals import GeoType, RenderType #Import configuration items
# 1. Destination URL
url='https://api.inews.qq.com/newsqa/v1/automation/foreign/country/ranklist'
# 2. Request resources
resp=requests.post(url)
# print(resp.text)
# Establish a national dictionary to match epidemic data for mapping
nameMap={"Somalia":"Somalia","Liechtenstein":"Liechtenstein","Morocco":"Morocco","W. Sahara":"Western Sahara","Serbia":"Serbia","Afghanistan":"Afghanistan","Angola":"Angola","Albania":"Albania","Andorra":"Andorra","United Arab Emirates":"United Arab Emirates","Argentina":"Argentina","Armenia":"Armenia","Australia":"Australia","Austria":"Austria","Azerbaijan":"Azerbaijan","Burundi":"Burundi","Belgium":"Belgium","Benin":"Benin","Burkina Faso":"Burkina Faso","Bangladesh":"Bangladesh","Bulgaria":"Bulgaria","Bahrain":"Bahrain","Bahamas":"Bahamas","Bosnia and Herz.":"Bosnia and Herzegovina","Belarus":"Belarus","Belize":"Belize","Bermuda":"Bermuda","Bolivia":"Bolivia","Brazil":"Brazil","Barbados":"Barbados","Brunei":"Brunei","Bhutan":"Bhutan","Botswana":"Botswana","Central African Rep.":"Central Africa","Canada":"Canada","Switzerland":"Switzerland","Chile":"Chile","China":"China","Côte d'Ivoire":"Cote d'Ivoire","Cameroon":"Cameroon","Dem. Rep. Congo":"Democratic Republic of Congo","Congo":"Congo","Colombia":"Colombia","Cape Verde":"Cape Verde","Costa Rica":"Costa Rica","Cuba":"Cuba","N. Cyprus":"Northern Cyprus","Cyprus":"Cyprus","Czech Rep.":"Czech Republic","Germany":"Germany","Djibouti":"Djibouti","Denmark":"Denmark","Dominican Rep.":"Dominica","Algeria":"Algeria","Ecuador":"Ecuador","Egypt":"Egypt","Eritrea":"Eritrea","Spain":"Spain","Estonia":"Estonia","Ethiopia":"Ethiopia","Finland":"Finland","Fiji":"Fiji","France":"France","Gabon":"Gabon","United Kingdom":"United Kingdom","Georgia":"Georgia","Ghana":"Ghana","Guinea":"Guinea","Gambia":"Gambia","Guinea-Bissau":"Guinea比绍","Eq. Guinea":"赤道Guinea","Greece":"Greece","Grenada":"Grenada","Greenland":"Greenland","Guatemala":"Guatemala","Guam":"Guam","Guyana":"Guyana","Honduras":"Honduras","Croatia":"Croatia","Haiti":"Haiti","Hungary":"Hungary","Indonesia":"Indonesia","India":"India","Br. Indian Ocean Ter.":"英属India洋领土","Ireland":"Ireland","Iran":"Iran","Iraq":"Iraq","Iceland":"Iceland","Israel":"Israel","Italy":"Italy","Jamaica":"Jamaica","Jordan":"Jordan","Japan":"Japan","Siachen Glacier":"Siachen Glacier","Kazakhstan":"Kazakhstan","Kenya":"Kenya","Kyrgyzstan":"Kyrgyzstan","Cambodia":"Cambodia","Korea":"Korea","Kuwait":"Kuwait","Lao PDR":"Laos","Lebanon":"Lebanon","Liberia":"Liberia","Libya":"Libya","Sri Lanka":"Sri Lanka","Lesotho":"Lesotho","Lithuania":"Lithuania","Luxembourg":"Luxembourg","Latvia":"Latvia","Moldova":"Moldova","Madagascar":"Madagascar","Mexico":"Mexico","Macedonia":"Macedonia","Mali":"Mali","Malta":"Malta","Myanmar":"Myanmar","Montenegro":"Montenegro","Mongolia":"Mongolia","Mozambique":"Mozambique","Mauritania":"Mauritania","Mauritius":"Mauritius","Malawi":"Malawi","Malaysia":"Malaysia","Namibia":"Namibia","New Caledonia":"New Caledonia","Niger":"Niger","Nigeria":"Nigeria","Nicaragua":"Nicaragua","Netherlands":"Netherlands","Norway":"Norway","Nepal":"Nepal","New Zealand":"new Zealand","Oman":"Oman","Pakistan":"Pakistan","Panama":"Panama","Peru":"Peru","Philippines":"Philippines","Papua New Guinea":"巴布亚新Guinea","Poland":"Poland","Puerto Rico":"Puerto Rico","Dem. Rep. Korea":"Korea","Portugal":"Portugal","Paraguay":"Paraguay","Palestine":"Palestine","Qatar":"Qatar","Romania":"Romania","Russia":"Russia","Rwanda":"Rwanda","Saudi Arabia":"Saudi Arabia","Sudan":"Sudan","S. Sudan":"南Sudan","Senegal":"Senegal","Singapore":"Singapore","Solomon Is.":"Solomon Islands","Sierra Leone":"Sierra Leone","El Salvador":"Salvador","Suriname":"Suriname","Slovakia":"Slovakia","Slovenia":"Slovenia","Sweden":"Sweden","Swaziland":"Swaziland","Seychelles":"Seychelles","Syria":"Syria","Chad":"Chad","Togo":"Togo","Thailand":"Thailand","Tajikistan":"Tajikistan","Turkmenistan":"Turkmenistan","Timor-Leste":"East Timor","Tonga":"Tonga","Trinidad and Tobago":"Trinidad and Tobago","Tunisia":"Tunisia","Turkey":"Turkey","Tanzania":"Tanzania","Uganda":"Uganda","Ukraine":"Ukraine","Uruguay":"Uruguay","United States":"United States","Uzbekistan":"Uzbekistan","Venezuela":"Venezuela","Vietnam":"Vietnam","Vanuatu":"Vanuatu","Yemen":"Yemen","South Africa":"South Africa","Zambia":"Zambia","Zimbabwe":"Zimbabwe","Aland":"Aland Islands","American Samoa":"American Samoa","Fr. S. Antarctic Lands":"Antarctica","Antigua and Barb.":"Antigua and Barbuda","Comoros":"Comoros","Curaçao":"Curacao","Cayman Is.":"Cayman Islands","Dominica":"Dominica","Falkland Is.":"Malvinas Islands (Falkland)","Faeroe Is.":"Faroe Islands","Micronesia":"Micronesia","Heard I. and McDonald Is.":"Heard Island and McDonald Islands","Isle of Man":"Isle of Man","Jersey":"Jersey","Kiribati":"Kiribati","Saint Lucia":"Saint Lucia","N. Mariana Is.":"北Mali亚纳群岛","Montserrat":"Montserrat","Niue":"Niue","Palau":"Palau","Fr. Polynesia":"French Polynesia","S. Geo. and S. Sandw. Is.":"South Georgia and the South Sandwich Islands","Saint Helena":"St. Helena","St. Pierre and Miquelon":"Saint Pierre and Miquelon","São Tomé and Principe":"Sao Tome and Principe","Turks and Caicos Is.":"Turks and Caicos Islands","St. Vin. and Gren.":"Saint Vincent and the Grenadines","U.S. Virgin Is.":"United States Virgin Islands","Samoa":"Samoa"}
# 3. Extract data
data=json.loads(resp.text)
name=jsonpath.jsonpath(data,"$..name")
confirm=jsonpath.jsonpath(data,"$..confirm")
# print(name)
# print(confirm)
# Build the database
data_list=zip(name,confirm)#Combine two columns of data
print(data_list)
# Visualization
map=Map(opts.InitOpts(width='1600px',height='900px')).add(series_name="World Epidemic Map",
    data_pair=list(data_list),
    maptype="world", 
    name_map=nameMap,
    is_map_symbol_show=False)
# Setup diagram
map.set_series_opts(label_opts=opts.LabelOpts(is_show=False))#Do not display country name
map.set_global_opts(title_opts=opts.TitleOpts(title="World epidemic"),#Set title
     visualmap_opts=opts.VisualMapOpts(max_=10000000,is_piecewise=True))#Set the legend and draw the color according to the number of patients
map.render("Distribution of the world epidemic.html")#Save result

result##

Concluding remarks##

Finally configured jupyternotebook, very happy.

Recommended Posts

Python is short-world epidemic map
Python 3.9 is here!
Why python is popular
Python is slowly fading
Is python an interpreted language?
Is python an interpreted language
Python realizes 3D map visualization
Python is short _SVM test
Is python code case sensitive
What is introspection in python
What is object-oriented in python
What is Python variable scope
What is list comprehension in python
Is there function overloading in python
Python deep copy is not perfect
Python judges that it is empty
Python is a cross-platform language code
What is the use of Python
Is python language free or paid?
Everything in Python is an object
Is python suitable for data mining
Is python crawler easy to learn