Ultimate talented people
Map of the number of people infected with the new coronavirus by prefecture https://gis.jag-japan.com/covid19jp/
I have created a site called, but I am not so enthusiastic, so I decided to create a BOT that displays the breakdown of the number of infected people.
The data of the number of infected people was put in the json file on the same site, so I will use that.
https://services6.arcgis.com/5jNaHNYe2AnnqRnS/arcgis/rest/services/COVID19_Japan/FeatureServer/0/query?where=%E9%80%9A%E3%81%97%3E0&returnIdsOnly=false&returnCountOnly=false&&f=pgeojson&outFields=*&orderByFields=%E9%80%9A%E3%81%97
The following sites are easy to understand for creating and basics of Discord BOT using discord.py.
How to make a simple Discord Bot in Python https://qiita.com/PinappleHunter/items/af4ccdbb04727437477f Discord Bot Fastest Tutorial [Python & Heroku & GitHub] https://qiita.com/1ntegrale9/items/aa4b373e8895273875a8
First, create a program to download the above json file. You can easily download it using ** urllib **.
download.py
import urllib.request
def download():
url = 'https://services6.arcgis.com/5jNaHNYe2AnnqRnS/arcgis/rest/services/COVID19_Japan/FeatureServer/0/query?where=%E9%80%9A%E3%81%97%3E0&returnIdsOnly=false&returnCountOnly=false&&f=pgeojson&outFields=*&orderByFields=%E9%80%9A%E3%81%97'
title = 'COVID-19_data.json'
urllib.request.urlretrieve(url, "{0}".format(title))
Next, make the BOT body.
main.py
import download
import json
from collections import defaultdict
import discord
TOKEN = 'Any token'
CHANNEK_ID = 'Any channel ID'
client = discord.Client()
#Displayed at startup
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
#When you receive the message
@client.event
async def on_message(message):
#Ignore messages from bots
if message.author.bot:
return
if message.content.startswith("!count"):
#Load json file
download.download()
json_open = open('COVID-19_data.json', 'r', encoding="utf-8_sig")
json_load = json.load(json_open)
jsn = json_load
#Keep the name and number of prefectures of residence in defaultdict
properties = defaultdict(int)
for f in jsn['features']:
property = f['properties']['Prefecture of residence']
if property == 'People's Republic of China' or property == 'investigating' or property == 'unknown':
continue
if property not in properties:
properties[property] = 0
properties[property] += 1
#It takes time to output line by line, so the output contents are saved in advance.
say = ''
for p in properties:
say += p + ' ' + str(properties[p]) + '\n'
await message.channel.send(say)
client.run(TOKEN)
The above is the BOT program that displays the number of people infected with the new coronavirus in each prefecture.
Data !!!!
Actually, it was output a little more, but it could not fit due to the capture size. Please note.
It's a rough idea, so there may be places where you can make mistakes and be smart. In that case, I would appreciate it if you could point out. The violence of the new coronavirus is still unstoppable. Please be careful.
Twitter https://twitter.com/hasegawa2718