Nina Diana

Nina Diana


Python Real-Time Data Collection-New Coronavirus

This repo holds the code for crawling the latest news on the pneumonia virus from Clove doctor’s website

The content of the crawling includes the number of confirmed cases, the number of suspected cases, the progress of relevant research (source of infection, route of transmission, etc.), the number of infected cases in various provinces and the latest 3 real-time news

If you don’t see your province in an infected province, it may be because no cases have been found, but that doesn’t mean you can let your guard down

It may be faster for domestic users to download EXE files through this link

2020-02-03 New Program

The function of 2019-ncov-timer. py program is to crawl the data at 0:00 am every day, and save it in the current sheet with the date of the day as the sheet name. The program was written to make it easier for researchers to analyze data

Please read the following notes carefully

  1. You need to make sure that when the program is running, 2019- ncov.xlsx this Excel file is closed
  2. It needs to be run before 0 a.m. every day to make sure the program is running until it says, “file was written successfully.”
  3. Run directly, and the Excel directory generated is the same as the directory where the program runs

Part of the data in Excel are as follows:



This project was written by me after staying up late for 2 hours in the evening. I just hope to call on all of you to give full play to your strengths, use what you have learned and do something within your capacity for the prevention and control of the epidemic. You can say that my project is rubbish, but please don’t say that I am trying to make a show. No Chinese would make a show of this kind of thing


My power is limited, you can help optimize the code to make it simpler, or you can do some awesome projects, such as data visualization of epidemic transmission. I will also continue to improve the project, welcome to ask more questions. Thanks

I’ll soon deploy the data I’ve crawled to the server as json, so you can call it


Source code, pay attention to the required modules (such as pip install module name)

import requests

import re

from bs4 import BeautifulSoup

from time import sleep

import json

from prettytable import ALL

from prettytable import PrettyTable


hubei = {}

guangdong = {}

zhejiang = {}

beijing = {}

shanghai = {}

hunan = {}

anhui = {}

chongqing = {}

sichuan = {}

shandong = {}

guangxi = {}

fujian = {}

jiangsu = {}

henan = {}

hainan = {}

tianjin = {}

jiangxi = {}

shanxi1 = {} # 陕西

guizhou = {}

liaoning = {}

xianggang = {}

heilongjiang = {}

aomen = {}

xinjiang = {}

gansu = {}

yunnan = {}

taiwan = {}

shanxi2 = {} # 山西

jilin = {}

hebei = {}

ningxia = {}

neimenggu = {}

qinghai = {} # none

xizang = {} # none

provinces_idx = [hubei, guangdong, zhejiang, chongqing, hunan, anhui, beijing,

                 shanghai, henan, guangxi, shandong, jiangxi, jiangsu, sichuan,

                 liaoning, fujian, heilongjiang, hainan, tianjin, hebei, shanxi2,

                 yunnan, xianggang, shanxi1, guizhou, jilin, gansu, taiwan,

                 xinjiang, ningxia, aomen, neimenggu, qinghai, xizang]

map = {

    '湖北':0, '广东':1, '浙江':2, '北京':3, '上海':4, '湖南':5, '安徽':6, '重庆':7,

    '四川':8, '山东':9, '广西':10, '福建':11, '江苏':12, '河南':13, '海南':14,

    '天津':15, '江西':16, '陕西':17, '贵州':18, '辽宁':19, '香港':20, '黑龙江':21,

    '澳门':22, '新疆':23, '甘肃':24, '云南':25, '台湾':26, '山西':27, '吉林':28,

    '河北':29, '宁夏':30, '内蒙古':31, '青海':32, '西藏':33




def getTime(text):

    TitleTime = str(text)

    TitleTime = re.findall('<span>(.*?)</span>', TitleTime)

    return TitleTime[0]


def getAllCountry(text):

    AllCountry = str(text)

    AllCountry = AllCountry.replace("[<p class=\"confirmedNumber___3WrF5\"><span class=\"content___2hIPS\">", "")

    AllCountry = AllCountry.replace("<span style=\"color: #4169e2\">", "")

    AllCountry = re.sub("</span>", "", AllCountry)

    AllCountry = AllCountry.replace("</p>]", "")


    AllCountry = AllCountry.replace("<span style=\"color: rgb(65, 105, 226);\">", "")

    AllCountry = re.sub("<span>", "", AllCountry)

    AllCountry = re.sub("<p>", "", AllCountry)

    AllCountry = re.sub("</p>", "", AllCountry)

    return AllCountry 


def query(province):

    table = PrettyTable(['地区', '确诊', '死亡', '治愈'])


    for (k, v) in province.items():

        name = k

        table.add_row([name, v[0] if v[0] != 0 else '-', v[1] if v[1] != 0 else '-', v[2] if v[2] != 0 else '-'])

    if len(province.keys()) != 0:





def getInfo(text):

    text = str(text)

    text = re.sub("<p class=\"descText___Ui3tV\">", "", text)

    text = re.sub("</p>", "", text)

    return text


def is_json(json_str):



    except ValueError:

        return False

    return True


def ff(str, num):

    return str[:num] + str[num+1:]



def main():

    url = ""



        headers = {}

        headers['user-agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36' #http头大小写不敏感

        headers['accept'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8'

        headers['Connection'] = 'keep-alive'

        headers['Upgrade-Insecure-Requests'] = '1'


        r = requests.get(url, headers=headers)


        r.encoding = r.apparent_encoding

        soup = BeautifulSoup(r.text,'lxml')

        table = PrettyTable(['地区', '确诊', '死亡', '治愈'])

        table.hrules = ALL


        #### 截至时间

        # TitleTime = getTime('.title___2d1_B'))



        # print("              ",TitleTime + "\n")


        while True:

            r = requests.get("")

            json_str = json.loads(r.text)

            if json_str['error'] == 0:






        print("     确诊 " + str(json_str['data']['statistics']['confirmedCount']) + " 例"

            + "       " + "疑似 " + str(json_str['data']['statistics']['suspectedCount']) + " 例"

            + "       " + "死亡" + str(json_str['data']['statistics']['deadCount']) + " 例"

            + "       " + "治愈" + str(json_str['data']['statistics']['curedCount']) + " 例\n")





        print("传染源:" + json_str['data']['statistics']['infectSource'])

        print("病毒:" + json_str['data']['statistics']['virus'])

        print("传播途径:" + json_str['data']['statistics']['passWay'])


        print(json_str['data']['statistics']['remark2'] + "\n")





        json_provinces = re.findall("{\"provinceName\":(.*?)]}", str(soup))


        idx = 0

        for province in json_provinces:

            if is_json(province):




                province = "{\"provinceName\":" + province + "]}"

                province = json.loads(province)


            province_name = province['provinceShortName'] if province['provinceShortName'] != 0 else '-'

            confirmed = province['confirmedCount'] if province['confirmedCount'] != 0 else '-'

            suspected = province['suspectedCount'] if province['suspectedCount'] != 0 else '-'

            cured = province['curedCount'] if province['curedCount'] != 0 else '-'

            dead = province['deadCount'] if province['deadCount'] != 0 else '-'

            table.add_row([province_name, confirmed, dead, cured])

            map[province_name] = idx

            idx = idx + 1

            for city in province['cities']:

                provinces_idx[map[province_name]][city['cityName']] = [city['confirmedCount'], city['deadCount'], city['curedCount']]









        json_provinces = str(re.findall("\"id\":949(.*?)]}", str(soup)))

        json_provinces = json_provinces[:1] + "{\"id\":949" + json_provinces[2:]

        json_provinces = json_provinces[:len(json_provinces) - 2] + json_provinces[len(json_provinces) - 1:]

        provinces = json.loads(json_provinces)


        table = PrettyTable(['地区', '确诊', '死亡', '治愈'])

        for province in provinces:

            confirmed = province['confirmedCount'] if province['confirmedCount'] != 0 else '-'

            dead = province['deadCount'] if province['deadCount'] != 0 else '-'

            cured = province['curedCount'] if province['curedCount'] != 0 else '-'

            table.add_row([province['provinceName'], confirmed, dead, cured])









        idx = 0

        for news in json_str['data']['timeline']:

            if idx == 5:


            print(news['pubDateStr'] + "  " + news['title'])

            idx = idx + 1




        key = input("请输入您想查询详细信息的省份,例如 湖北\n")


        if key in map.keys():









if __name__ == '__main__':



Finally, I wish you all a hundred poisons, China, come on! !! Definitely going through the storm! !!

#python #corona #coronavirus

What is GEEK

Buddha Community

Python Real-Time Data Collection-New Coronavirus
Ray  Patel

Ray Patel


top 30 Python Tips and Tricks for Beginners

Welcome to my Blog , In this article, you are going to learn the top 10 python tips and tricks.

1) swap two numbers.

2) Reversing a string in Python.

3) Create a single string from all the elements in list.

4) Chaining Of Comparison Operators.

5) Print The File Path Of Imported Modules.

6) Return Multiple Values From Functions.

7) Find The Most Frequent Value In A List.

8) Check The Memory Usage Of An Object.

#python #python hacks tricks #python learning tips #python programming tricks #python tips #python tips and tricks #python tips and tricks advanced #python tips and tricks for beginners #python tips tricks and techniques #python tutorial #tips and tricks in python #tips to learn python #top 30 python tips and tricks for beginners

Ian  Robinson

Ian Robinson


4 Real-Time Data Analytics Predictions for 2021

Data management, analytics, data science, and real-time systems will converge this year enabling new automated and self-learning solutions for real-time business operations.

The global pandemic of 2020 has upended social behaviors and business operations. Working from home is the new normal for many, and technology has accelerated and opened new lines of business. Retail and travel have been hit hard, and tech-savvy companies are reinventing e-commerce and in-store channels to survive and thrive. In biotech, pharma, and healthcare, analytics command centers have become the center of operations, much like network operation centers in transport and logistics during pre-COVID times.

While data management and analytics have been critical to strategy and growth over the last decade, COVID-19 has propelled these functions into the center of business operations. Data science and analytics have become a focal point for business leaders to make critical decisions like how to adapt business in this new order of supply and demand and forecast what lies ahead.

In the next year, I anticipate a convergence of data, analytics, integration, and DevOps to create an environment for rapid development of AI-infused applications to address business challenges and opportunities. We will see a proliferation of API-led microservices developer environments for real-time data integration, and the emergence of data hubs as a bridge between at-rest and in-motion data assets, and event-enabled analytics with deeper collaboration between data scientists, DevOps, and ModelOps developers. From this, an ML engineer persona will emerge.

#analytics #artificial intelligence technologies #big data #big data analysis tools #from our experts #machine learning #real-time decisions #real-time analytics #real-time data #real-time data analytics

Siphiwe  Nair

Siphiwe Nair


Your Data Architecture: Simple Best Practices for Your Data Strategy

If you accumulate data on which you base your decision-making as an organization, you should probably think about your data architecture and possible best practices.

If you accumulate data on which you base your decision-making as an organization, you most probably need to think about your data architecture and consider possible best practices. Gaining a competitive edge, remaining customer-centric to the greatest extent possible, and streamlining processes to get on-the-button outcomes can all be traced back to an organization’s capacity to build a future-ready data architecture.

In what follows, we offer a short overview of the overarching capabilities of data architecture. These include user-centricity, elasticity, robustness, and the capacity to ensure the seamless flow of data at all times. Added to these are automation enablement, plus security and data governance considerations. These points from our checklist for what we perceive to be an anticipatory analytics ecosystem.

#big data #data science #big data analytics #data analysis #data architecture #data transformation #data platform #data strategy #cloud data platform #data acquisition

Arvel  Parker

Arvel Parker


Basic Data Types in Python | Python Web Development For Beginners

At the end of 2019, Python is one of the fastest-growing programming languages. More than 10% of developers have opted for Python development.

In the programming world, Data types play an important role. Each Variable is stored in different data types and responsible for various functions. Python had two different objects, and They are mutable and immutable objects.

Table of Contents  hide

I Mutable objects

II Immutable objects

III Built-in data types in Python

Mutable objects

The Size and declared value and its sequence of the object can able to be modified called mutable objects.

Mutable Data Types are list, dict, set, byte array

Immutable objects

The Size and declared value and its sequence of the object can able to be modified.

Immutable data types are int, float, complex, String, tuples, bytes, and frozen sets.

id() and type() is used to know the Identity and data type of the object







Built-in data types in Python

a**=str(“Hello python world”)****#str**














Numbers (int,Float,Complex)

Numbers are stored in numeric Types. when a number is assigned to a variable, Python creates Number objects.

#signed interger




Python supports 3 types of numeric data.

int (signed integers like 20, 2, 225, etc.)

float (float is used to store floating-point numbers like 9.8, 3.1444, 89.52, etc.)

complex (complex numbers like 8.94j, 4.0 + 7.3j, etc.)

A complex number contains an ordered pair, i.e., a + ib where a and b denote the real and imaginary parts respectively).


The string can be represented as the sequence of characters in the quotation marks. In python, to define strings we can use single, double, or triple quotes.

# String Handling

‘Hello Python’

#single (') Quoted String

“Hello Python”

# Double (") Quoted String

“”“Hello Python”“”

‘’‘Hello Python’‘’

# triple (‘’') (“”") Quoted String

In python, string handling is a straightforward task, and python provides various built-in functions and operators for representing strings.

The operator “+” is used to concatenate strings and “*” is used to repeat the string.


output**:****‘Hello python’**

"python "*****2

'Output : Python python ’

#python web development #data types in python #list of all python data types #python data types #python datatypes #python types #python variable type

Ray  Patel

Ray Patel


Lambda, Map, Filter functions in python

Welcome to my Blog, In this article, we will learn python lambda function, Map function, and filter function.

Lambda function in python: Lambda is a one line anonymous function and lambda takes any number of arguments but can only have one expression and python lambda syntax is

Syntax: x = lambda arguments : expression

Now i will show you some python lambda function examples:

#python #anonymous function python #filter function in python #lambda #lambda python 3 #map python #python filter #python filter lambda #python lambda #python lambda examples #python map