{{announcement.body}}
{{announcement.title}}

Using Coronavirus Quarantines to Boost Your Skills

DZone 's Guide to

Using Coronavirus Quarantines to Boost Your Skills

Are you under a coronavirus lockdown? See how you can use this time to enhance your skills, like with this Python, urllib, and Beautiful Soup program.

· Big Data Zone ·
Free Resource

The outbreak of coronavirus globally has had a major impact on the global economy. Many countries have gone into lockdown, and there is no industry left that hasn't felt the impact. Even the programming world is facing some major setbacks because of it. However, if we talk about individual programmers, they might also be facing social or physical problems after being in quarantine or working from home for 2 or 3 weeks. But we can turn this time in our favor by learning some new skills online. All you need is a computer and a good internet connection.

Though the programming world may not be facing too many problems, the overall IT industry is. If we look at the stats of developer hiring in the USA, in February, the hiring of developers fell by nearly 70,000, which was up 52,000 in January. This decrease in developer hiring has had a huge impact on demands on developers and affects organizational strength as well.

What a Programmer or Developer Can Do in Quarantine?

Now, this is a perfect time to learn some new skills. If your city has been lockdown or you are in quarantine, now you can use this time to upgrade your programming skills. If you are a beginner, you can learn some new intermediate programming and try something new to add valuable skills in your arsenal.

As we know, tools and technologies in the programming world are not always stable, and you always need to update your skills. A time like this may not come in your life again — and we hope it won’t — so open your computer, surf the internet, and find the best tool for yourself to learn.

Calculating the Number of People Affected by Coronavirus Worldwide

Here we will use web-scraping in Python to scrape data from worldometer, which lists out the live details of cases affected by the coronavirus.

Prerequisites

  • python3
  • pip
  • internet

Python Libraries

  • urllib
  • bs4 (beautiful soup)

1. urllib

urllib is a powerful  open-source library for python. It contains various modules such as request, error, parse, and robot parsers, which can be used to send requests and collect data from websites.

Here in this example, we have used the urllib request method to send the HTTP request and open the URLs.

install urllib

Shell
 




x


 
1
pip install urllib


2. bs4

Also known as Beautiful Soup, it is used to pull out HTML and XML files. It works with your favorite parser to provide idiomatic ways of navigating, searching, and modifying the parse tree. It commonly saves programmers' hours or days of work.

install beautiful soup

Shell
 




xxxxxxxxxx
1


 
1
pip install bs4


Python Program to Calculate the Total Number of People Affected by the Coronavirus

Python
 




xxxxxxxxxx
1
51


 
1
from bs4 import BeautifulSoup
2
from urllib.request import urlopen as ureq
3
 
          
4
#country list
5
def show_countries(c):
6
    for i in range(len(c)):
7
        print("({0})".format(i+1), c[i])
8
 
          
9
# WORLDOMETER.INFO
10
url ="https://www.worldometers.info/coronavirus/"
11
 
          
12
#sending request to worldometer
13
client = ureq(url)
14
page= client.read()
15
client.close()   #connection closed
16
 
          
17
#parsing the page
18
page_soup = BeautifulSoup(page,'html.parser')
19
 
          
20
#getting data present in table celles
21
container = page_soup.findAll("td")
22
 
          
23
#geting data from the page
24
data = [i.text.strip() if i.text.strip() else "0" for i in container ]
25
countries = [data[i] for i in range(len(data)) if data[i][0].isalpha()]
26
 
          
27
json_format_data ={}
28
 
          
29
for i in range(len(data)):
30
    if data[i][0].isalpha():
31
        ele=data[i].lower()
32
        json_format_data[ele]=[]
33
    else:
34
        json_format_data[ele].append(data[i])
35
 
          
36
print("---------Corona Case Details---------")
37
 
          
38
label=["Total Cases", "New Cases","Total Deaths","New Deaths", "Total Recovered", "Active Cases", "Serious Critical","Tot Cases/1M pop", "Tot Deaths/1M pop"]
39
for i in range(9):
40
    print(label[i],"-------->",json_format_data["total:"][i])
41
 
          
42
enter = int(input("Enter 1 to see the country List or 0 to skip: "))
43
 
          
44
if enter ==1:
45
    show_countries(countries)
46
 
          
47
country_name =input("Enter the Country Name, To See its Corona Cases: ").lower()
48
 
          
49
print("\n\n ------Corona Cases in {0}--------".format(country_name))
50
for i in range(9):
51
    print(label[i],"-------->",json_format_data[country_name][i])



Output:

Plain Text
 




xxxxxxxxxx
1
425


 
1
---------Corona Case Details---------
2
Total Cases --------> 470,968
3
New Cases --------> 48,441
4
Total Deaths --------> 21,278
5
New Deaths --------> 2,388
6
Total Recovered --------> 113,827
7
Active Cases --------> 335,863
8
Serious Critical --------> 14,956
9
Tot Cases/1M pop --------> 60.4
10
Tot Deaths/1M pop --------> 2.7
11
 
          
12
Enter 1 to see the country List or 0 to skip: 1
13
(1) China
14
(2) Italy
15
(3) USA
16
(4) Spain
17
(5) Germany
18
(6) Iran
19
(7) France
20
(8) Switzerland
21
(9) UK
22
(10) S. Korea
23
(11) Netherlands
24
(12) Belgium
25
(13) Austria
26
(14) Portugal
27
(15) Canada
28
(16) Norway
29
(17) Sweden
30
(18) Australia
31
(19) Israel
32
(20) Brazil
33
(21) Turkey
34
(22) Malaysia
35
(23) Denmar
36
(24) Czechia
37
(25) Ireland
38
(26) Luxembourg
39
(27) Japan
40
(28) Chile
41
(29) Ecuado
42
(30) Pakistan
43
(31) Poland
44
(32) Thailand
45
(33) Romania
46
(34) Saudi Arabia
47
(35) Finland
48
(36) Indonesia
49
(37) Russia
50
(38) Greece
51
(39) Iceland
52
(40) India
53
(41) Diamond Princess
54
(42) South Africa
55
(43) Philippines
56
(44) Singapore
57
(45) Panama
58
(46) Estonia
59
(47) Qatar
60
(48) Slovenia
61
(49) Argentina
62
(50) Croatia
63
(51) Peru
64
(52) Mexico
65
(53) Colombia
66
(54) Bahrain
67
(55) Egypt
68
(56) Hong Kong
69
(57) Dominican Republic
70
(58) Serbia
71
(59) Iraq
72
(60) Lebanon
73
(61) UAE
74
(62) Algeria
75
(63) Lithuania
76
(64) Armenia
77
(65) New Zealand
78
(66) Hungary
79
(67) Taiwan
80
(68) Latvia
81
(69) Bulgaria
82
(70) Slovakia
83
(71) Morocco
84
(72) Andorra
85
(73) Uruguay
86
(74) San Marino
87
(75) Kuwait
88
(76) North Macedonia
89
(77) Costa Rica
90
(78) Bosniaand Herzegovina
91
(79) Albania
92
(80) Tunisia
93
(81) Jordan
94
(82) Ukraine
95
(83) Vietnam
96
(84) Moldova
97
(85) Burkina Fas
98
(86) Faeroe Islands
99
(87) Malta
100
(88) Ghana
101
(89) Cyprus
102
(90) Azerbaijan
103
(91) Réunion
104
(92) Brunei
105
(93) Kazakhstan
106
(94) Oman
107
(95) Venezuela
108
(96) Senegal
109
(97) Sri Lanka
110
(98) Cambodia
111
(99) Belarus
112
(100) Afghanistan
113
(101) Palestine
114
(102) Ivory Coast
115
(103) Georgia
116
(104) Cameroon
117
(105) Guadeloupe
118
(106) Montenegro
119
(107) Martinique
120
(108) Uzbekistan
121
(109) Trinidad and Tobago
122
(110) Cuba
123
(111) Mauritius
124
(112) Honduras
125
(113) DRC
126
(114) Nigeria
127
(115) Liechtenstein
128
(116) Channel Islands
129
(117) Bangladesh
130
(118) Kyrgyzstan
131
(119) Paraguay
132
(120) Rwanda
133
(121) Bolivia
134
(122) Mayotte
135
(123) Macao
136
(124) Monaco
137
(125) Kenya
138
(126) French Guiana
139
(127) Jamaica
140
(128) Gibraltar
141
(129) French Polynesia
142
(130) Isle of Man
143
(131) Guatemala
144
(132) Madagascar
145
(133) Togo
146
(134) Aruba
147
(135) Barbados
148
(136) New Caledonia
149
(137) Uganda
150
(138) El Salvador
151
(139) Maldives
152
(140) Tanzania
153
(141) Ethiopia
154
(142) Zambia
155
(143) Djibouti
156
(144) Dominica
157
(145) Mongolia
158
(146) Saint Martin
159
(147) Equatorial Guinea
160
(148) Cayman Islands
161
(149) Haiti
162
(150) Suriname
163
(151) Gabon
164
(152) Nigeria
165
(153) Bermuda
166
(154) Namibia
167
(155) Seychelles
168
(156) Curaçao
169
(157) Benin
170
(158) Greenland
171
(159) Laos
172
(160) Guyana
173
(161) Bahamas
174
(162) Fiji
175
(163) Mozambique
176
(164) Syria
177
(165) Cabo Verde
178
(166) Congo
179
(167) Eritrea
180
(168) Guinea
181
(169) Vatican City
182
(170) Eswatini
183
(171) Gambia
184
(172) Sudan
185
(173) Zimbabwe
186
(174) Nepal
187
(175) Angola
188
(176) Antigua and Barbuda
189
(177) CAR
190
(178) Chad
191
(179) Liberia
192
(180) Mauritania
193
(181) Myanmar
194
(182) St. Barth
195
(183) Saint Lucia
196
(184) Sint Maarten
197
(185) Belize
198
(186) Bhutan
199
(187) British Virgin Islands
200
(188) Guinea-Bissau
201
(189) Mali
202
(190) Nicaragua
203
(191) Saint Kitts and Nevis
204
(192) Somalia
205
(193) Grenada
206
(194) Libya
207
(195) Montserrat
208
(196) Papua New Guinea
209
(197) St. Vincent Grenadines
210
(198) Timor-Leste
211
(199) Turks and Caicos
212
(200) Total:
213
(201) China
214
(202) Italy
215
(203) USA
216
(204) Spain
217
(205) Germany
218
(206) Iran
219
(207) France
220
(208) Switzerland
221
(209) UK
222
(210) S. Korea
223
(211) Netherlands
224
(212) Austria
225
(213) Belgium
226
(214) Canada
227
(215) Norway
228
(216) Portugal
229
(217) Australia
230
(218) Brazil
231
(219) Sweden
232
(220) Turkey
233
(221) Israel
234
(222) Malaysia
235
(223) Denmark
236
(224) Czechia
237
(225) Ireland
238
(226) Luxembourg
239
(227) Japan
240
(228) Ecuaor
241
(229) Chile
242
(230) Pakistan
243
(231) Poland
244
(232) Thailand
245
(233) Romania
246
(234) Saudi Arabia
247
(235) Finland
248
(236) Greece
249
(237) Indonesia
250
(238) Iceland
251
(239) Diamond Princess
252
(240) South Africa
253
(241) Russia
254
(242) India
255
(243) Philippines
256
(244) Singapore
257
(245) Panama
258
(246) Qatar
259
(247) Slovenia
260
(248) Argentina
261
(249) Peru
262
(250) Colombia
263
(251) Egypt
264
(252) Croatia
265
(253) Bahrai
266
(254) Hong Kong
267
(255) Mexico
268
(256) Estonia
269
(257) Dominican Republic
270
(258) Serbia
271
(259) Iraq
272
(260) Lebanon
273
(261) UAE
274
(262) Algeria
275
(263) New Zealand
276
(264) Lithuania
277
(265) Armenia
278
(266) Bulgaria
279
(267) Taiwan
280
(268) Hungary
281
(269) Morocco
282
(270) Latvia
283
(271) Uruguay
284
(272) Slovakia
285
(273) San Marino
286
(274) Costa Rica
287
(275) Kuwait
288
(276) Andorra
289
(277) North Macedonia
290
(278) Bosnia and Herzegovina
291
(279) Tunisia
292
(280) Jordan
293
(281) Moldova
294
(282) Vietnam
295
(283) Albania
296
(284) Burkina Faso
297
(285) Ukraine
298
(286) Cyprus
299
(287) Faeroe Islands
300
(288) Malta
301
(289) Réunion
302
(290) Brunei
303
(291) Venezuela
304
(292) SriLanka
305
(293) Oman
306
(294) Senegal
307
(295) Cambodia
308
(296) Azerbaijan
309
(297) Belarus
310
(298) Afghanistan
311
(299) Kazakhstan
312
(300) Ivory Coast
313
(301) Cameroon
314
(302) Georgia
315
(303) Guadeloupe
316
(304) Palestine
317
(305) Ghana
318
(306) Martinique
319
(307) Trinidad and Tobago
320
(308) Uzbekistan
321
(309) Cuba
322
(310) Montenegro
323
(311) Honduras
324
(312) Nigeria
325
(313) Liechtenstein
326
(314) DRC
327
(315) Mauritius
328
(316) Channel Islands
329
(317) Kyrgyzstan
330
(318) Rwanda
331
(319) Bangladesh
332
(320) Paraguay
333
(321) Mayotte
334
(322) Bolivia
335
(323) Macao
336
(324) Monaco
337
(325) French Guiana
338
(326) Kenya
339
(327) Jamaica
340
(328) Gibraltar
341
(329) French Polynesia
342
(330) Guatemala
343
(331) Isle of Man
344
(332) Togo
345
(333) Aruba
346
(334) Madagascar
347
(335) Barbados
348
(336) New Caledonia
349
(337) Uganda
350
(338) Maldives
351
(339) Tanzania
352
(340) Ethiopia
353
(341) Zambia
354
(342) Djibouti
355
(343) Dominica
356
(344) Saint Martin
357
(345) Mongolia
358
(346) El Salvador
359
(347) Equatorial Guinea
360
(348) Cayman Islands
361
(349) Haiti
362
(350) Suriname
363
(351) Niger
364
(352) Bermuda
365
(353) Namibia
366
(354) Seychelles
367
(355) Curaçao
368
(356) Gabon
369
(357) Benin
370
(358) Greenland
371
(359) Guyana
372
(360) Bahamas
373
(361) Fiji
374
(362) Mozambique
375
(363) Syria
376
(364) Cabo Verde
377
(365) Congo
378
(366) Eritrea
379
(367) Guinea
380
(368) Vatican City
381
(369) Eswatini
382
(370) Gambia
383
(371) Sudan
384
(372) Zimbabwe
385
(373) Nepal
386
(374) Angola
387
(375) Antigua and Barbuda
388
(376) CAR
389
(377) Chad
390
(378) Laos
391
(379) Liberia
392
(380) Myanmar
393
(381) St. Barth
394
(382) Saint Lucia
395
(383) Sint Maarten
396
(384) Belize
397
(385) Bhutan
398
(386) British Virgin Islands
399
(387) Guinea-Bissau
400
(388) Mali
401
(389) Mauritania
402
(390) Nicaragua
403
(391) Saint Kitts and Nevis
404
(392) Grenada
405
(393) Libya
406
(394) Montserrat
407
(395) Papua New Guinea
408
(396) St. Vincent Grenadines
409
(397) Somalia
410
(398) Timor-Leste
411
(399) Turks and Caicos
412
(400) Total:
413
 
          
414
Enter the Country Name, To See its Corona Cases: china
415
 
          
416
 ------Corona Cases in china--------
417
Total Cases --------> 81,218
418
New Cases --------> +47
419
Total Deaths --------> 3,281
420
New Deaths --------> +4
421
Total Recovered --------> 73,650
422
Active Cases --------> 4,287
423
Serious Critical --------> 1,399
424
Tot Cases/1M pop --------> 56
425
Tot Deaths/1M pop --------> 2



Stay home, stay safe.

Do the Five

Help stop coronavirus:

  • HANDS: Wash them often
  • ELBOW: Cough into it
  • FACE: Don't touch it
  • SPACE: Keep safe distance
  • HOME: Stay if you can
Topics:
beautiful soup ,big data ,coronavirus ,python ,tutorial ,urllib ,web scraping

Published at DZone with permission of Vijay Singh Khatri . See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}