Last active
February 26, 2020 02:42
-
-
Save SaidBySolo/2f0b4b71a96804cebcc8074ddef94d01 to your computer and use it in GitHub Desktop.
Current status korea crawling of coronavirus 19 on Naver(discord.py)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| The MIT License (MIT) | |
| Copyright (c) 2020 SaidBySolo | |
| Permission is hereby granted, free of charge, to any person obtaining a copy | |
| of this software and associated documentation files (the "Software"), to deal | |
| in the Software without restriction, including without limitation the rights | |
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| copies of the Software, and to permit persons to whom the Software is | |
| furnished to do so, subject to the following conditions: | |
| The above copyright notice and this permission notice shall be included in all | |
| copies or substantial portions of the Software. | |
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
| SOFTWARE. | |
| """ | |
| import discord | |
| from discord.ext import commands | |
| import requests | |
| from bs4 import BeautifulSoup | |
| class Corona(commands.Cog): | |
| def __init__(self, bot): | |
| self.bot = bot | |
| @commands.command() | |
| async def 코로나현황(self, ctx): | |
| response = requests.get('https://search.naver.com/search.naver?sm=tab_hty.top&where=nexearch&query=코로나') | |
| readerhtml = response.text | |
| soup = BeautifulSoup(readerhtml, 'lxml') | |
| data1 = soup.find('div', class_='graph_view') | |
| data2 = data1.findAll('div', class_='box') | |
| data3 = data1.findAll('div', class_='box bottom') | |
| checked = data2[0].find('p', class_='txt').find('strong', class_='num').text | |
| checking = data2[2].find('p', class_='txt').find('strong', class_='num').text | |
| free = data3[0].find('p', class_='txt').find('strong', class_='num').text | |
| die = data3[1].find('p', class_='txt').find('strong', class_='num').text | |
| wasup = soup.find('div', class_='csp_notice_info').find('p').find_all(text=True, recursive=True) | |
| #=============================== | |
| coembed = discord.Embed(color=0x192131, title='코로나현황', description =f'{wasup[1]}' ) | |
| coembed.add_field(name="확진자", value=f'{checked}명', inline=True) | |
| coembed.add_field(name="격리해제", value=f'{free}명', inline=True) | |
| coembed.add_field(name="검사중", value=f'{checking}명', inline=True) | |
| coembed.add_field(name="사망자", value=f'{die}명', inline=True) | |
| coembed.set_footer(text="https://gist.github.com/SaidBySolo") | |
| await ctx.send(embed = coembed) | |
| def setup(bot): | |
| bot.add_cog(Corona(bot)) | |
| #if not using cogs,rewrite================================================== | |
| import discord | |
| from bs4 import BeautifulSoup | |
| import requests | |
| token = "Token paste here" | |
| client = discord.Client() | |
| @client.event | |
| async def on_message(message): | |
| if message.content == "(사용하실접두사)코로나현황": | |
| response = requests.get('https://search.naver.com/search.naver?sm=tab_hty.top&where=nexearch&query=코로나') | |
| readerhtml = response.text | |
| soup = BeautifulSoup(readerhtml, 'lxml') | |
| data1 = soup.find('div', class_='graph_view') | |
| data2 = data1.findAll('div', class_='box') | |
| data3 = data1.findAll('div', class_='box bottom') | |
| checked = data2[0].find('p', class_='txt').find('strong', class_='num').text | |
| checking = data2[2].find('p', class_='txt').find('strong', class_='num').text | |
| free = data3[0].find('p', class_='txt').find('strong', class_='num').text | |
| die = data3[1].find('p', class_='txt').find('strong', class_='num').text | |
| wasup = soup.find('div', class_='csp_notice_info').find('p').find_all(text=True, recursive=True) | |
| #=============================== | |
| coembed = discord.Embed(color=0x192131, title='코로나현황', description =f'{wasup[1]}' ) | |
| coembed.add_field(name="확진자", value=f'{checked}명', inline=True) | |
| coembed.add_field(name="격리해제", value=f'{free}명', inline=True) | |
| coembed.add_field(name="검사중", value=f'{checking}명', inline=True) | |
| coembed.add_field(name="사망자", value=f'{die}명', inline=True) | |
| coembed.set_footer(text="https://gist.github.com/SaidBySolo") | |
| await message.channel.send(embed = coembed) | |
| client.run(token) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment