Use covid-19 data to plan next travel

go.fly
3 min readMar 21, 2022

Background

In China, just couple of covid-19 cases found in one city, visitors will need 48 hours nucleic acid test report, sometimes 24 hours test report. Most of the poor provinces in the west part of China, will lockdown the whole city, and everyone from outside, will be quarantined in managed hotels for 48 hours to 14 days, which is depends on the local government policy.

During these special period, the local hotel price & air ticket price will hit rock bottom. For example, on Chinese national holiday, round-trip ticket from Shanghai to Dalian, cost about 3000 RMB(about $400), But during the lockdown, it only cost about 200–500RMB, yes, less than 1/10, and the flight is almost empty…what is more important is: this super cheap price will last far longer than the lockdown period, at least 5 days.(Masses need time to discover this news)

My program just used for computing the ending of the lock down, so traveller can buy tickets at the price recovery period.

Chinese covid-19 restriction and rules

Open this link, you can see a list of risk areas. If covid-19 case found in a city, his or her working and living places will be marked as middle or high risk areas. More cases found in one city, more and more middle or high risk areas will be added.

Following is the data for Beijing in June, 2021

(Red for high risk area, orange for middle risk area)

And it takes 14 days to reclassify the high/middle risk to low risk area. When there is no high/middle risk area, the city will be reopen for visitor and traveller, and the hotel & ticket price will bound back to normal quickly.

API and python code

There is no free official API to get all of risk areas in China, however, after some googling, I found some free API provided by wechat public account and website:

http://diqu.gezhong.vip/api.phphttps://m.sm.cn/api/rest?format=json&method=Huoshenshan.riskArea&_=1628665447912

diqu.genzhong.vip was discovered first, this API is updated every day at 0 AM CST, but second API updated more frequently, and always return more details. So at last, I switched to the second one.

The basic logic:

Get risk areas by python requests lib

url = API_URLr = requests.get(url)

Compare lastest data with old data, find the newly added areas, and update their timestamps.

All of the data will be saved in a CSV file, looks like:

$ cat /var/data/riskdb.csv
type,province,city,area,date
middle,天津,河北区,月牙河街锦江南里27门,2022–03–20
middle,天津,滨海新区,天津临港经济区泰长领钧实业发展有限公司,2022–03–17
middle,天津,滨海新区,天津临港经济区川匠之作(蓝领公寓店),2022–03–15
middle,天津,西青区,西营门街跃升里1号楼,2022–03–15
middle,天津,西青区,精武镇金牛花园11号楼,2022–03–12
middle,天津,西青区,西营门街赵苑西里8号楼,2022–03–12
middle,天津,西青区,西营门街王顶堤家园1号楼、17号楼,2022–03–12
middle,天津,武清区,汊沽港镇大刘堡村中心西街南1–2排,2022–03–14
middle,天津,武清区,汊沽港镇三街中山路、永华道、兴业路合围区域,2022–03–14
middle,天津,津南区,双港镇欣桃园21号楼1门,2022–03–12
middle,福建,漳州,芗城区龙江富城小区1栋,2022–03–20
middle,福建,漳州,龙文区苏菲辣蹦酒吧,2022–03–20
middle,福建,漳州,龙文区碧湖街道翰苑颐园,2022–03–20
middle,福建,莆田,仙游县盖尾镇湖坂村黄畲85–1号,2022–03–20
middle,福建,莆田,仙游县鲤南镇天博华府4号楼,2022–03–20
middle,福建,莆田,仙游县鲤南镇天博小区3号楼,2022–03–20
middle,福建,莆田,仙游县鲤城街道南门社区大园巷5–2号,2022–03–20

Provide an API for user:

predict(location):

Which will check every risk areas in the target location, found the latest updated timestamp, add 14 days delta time, and return the predict unlock time.

cleanDate = datetime.today()delta = timedelta(days=14)if province:    rows = riskDB.date[riskDB[‘province’] == province]    if rows.empty:        print(“No COVID-19 case in “, province)        return cleanDate    bookedDateStr = rows.max()

I created a cron job to run prediction every morning, and here is the final output:

province Estimated clearing time江苏      2022–04–03 00:00:00陕西      2022–04–01 00:00:00江西      2022–04–01 00:00:00广东      2022–03–30 00:00:00安徽      2022–04–03 00:00:00山东      2022–04–02 00:00:00吉林      2022–04–03 00:00:00上海      2022–04–03 00:00:00

Final words

Actually, I already tested this small python program for almost one year, and it saved me lots of money for travel. However, future is unpredictable, all of the prediction are bases on covid-19 can be controlled by local government. Today, the Omicron variant spreads more easily than the original virus that causes COVID-19 and the Delta variant. Two largest city:Shanghai & Shenzhen took almost one month lock down, the situation still not clear.

when most of resident locked in their home, there is no car in the middle of work day

--

--