import discord
import requests
from bs4 import BeautifulSoup
import datetime
import re
now = str(datetime.datetime.now())
day = now[:4] + now[5:7] + now[8:10]
print(day)
req = requests.get("http://school.cbe.go.kr/chungjuja-e/M01040504/list?ymd="+ day)
#print(req.text)
soup = BeautifulSoup(req.text, "html.parser")
#print(soup)
element = soup.find_all("tr")
#print(element[2])
element = element[2].find_all('td')
element = element[5] # num
element = str(element)
element = element.replace('[', '')
element = element.replace(']', '')
element = element.replace('<br/>', '\n')
element = element.replace('<td class="textC last">', '')
element = element.replace('<td class="textC">', '')
element = element.replace('</td>', '')
element = element.replace('(h)', '')
element = element.replace('.', '')
element = re.sub(r"\d", "", element)
print(element)
class chatbot(discord.Client):
# 프로그램이 처음 실행되었을 때 초기 구성
async def on_ready(self):
# 상태 메시지 설정
# 종류는 3가지: Game, Streaming, CustomActivity
game = discord.Game("코딩")
# 계정 상태를 변경한다.
# 온라인 상태, game 중으로 설정
await client.change_presence(status=discord.Status.online, activity=game)
# 준비가 완료되면 콘솔 창에 "READY!"라고 표시
print("READY")
# 봇에 메시지가 오면 수행 될 액션
async def on_message(self, message):
# SENDER가 BOT일 경우 반응을 하지 않도록 한다.
if message.author.bot:
return None
# message.content = message의 내용
if message.content == "오늘급식":
# 현재 채널을 받아옴
channel = message.channel
# 답변 내용 구성
msg = element
# msg에 지정된 내용대로 메시지를 전송
await channel.send(msg)
return None
if __name__ == "__main__":
client = chatbot()
client.run("ODIxMzExOTY0OTUyMjY0NzY0.YFB4Xw.3QwR70Bl7WkdFmKRdHwWqxopVXE")
///////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
import discord
import requests
import datetime
import sys
import re
from bs4 import BeautifulSoup
from discord.ext import commands
value = []
def crawling():
sys.stdout = open('guepsic.txt', 'w')
현재 = str(datetime.datetime.now())
# print(현재)
날 = 현재[:4] + 현재[5:7] + 현재[8:10]
# print(날)
req = requests.get("http://school.cbe.go.kr/chungjuja-e/M01040504/list?ymd=" + 날)
# print(req.text)
soup = BeautifulSoup(req.text, "html.parser")
print(soup)
return 'Zero'
#return soup
#print('--------------------')
atag = soup("a", href="/chungjuja-e/M01040504/list?ymd=" + 날)
#print(atag)
sys.stdout = sys.__stdout__
fp = open('guepsic.txt', 'r')
data = []
while True:
line = fp.readline()
if not line:
break
data.append(line)
#print(data)
for i in range(len(data)):
if 'li' in data[i]:
# print(data[i][4:-6])
v = data[i][4:-6]
value.append(v)
# print(value)
# print(data[i][4:len(data[i]-5)])
value.pop(0)
print(value)
if value.count() == 0:
return 'Zero'
return value
bot = commands.Bot(command_prefix='!')
TOKEN = 'ODIxMzExOTY0OTUyMjY0NzY0.YFB4Xw.3QwR70Bl7WkdFmKRdHwWqxopVXE'
# discode
@bot.event
async def on_ready():
await bot.change_presence(status=discord.Status.online, activity=discord.Game('코딩'))
print('[알림][YW봇(코딩)이 성공적으로 구동되었습니다.]')
@bot.event
async def on_message(msg):
if msg.author.bot: return None
await bot.process_commands(msg)
@bot.command()
async def 급식(ctx):
await ctx.channel.send(crawling())
bot.run(TOKEN)
@bot.event
async def on_ready():
print('login')
print(bot.user.id)
print('---------------------------')
///////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
import discord
import asyncio
from discord import Member
from discord.ext import commands
client = discord.Client()
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
@client.event
async def on_message(message):
if message.content.startswith('!test'):
await message.channel.send(message.channel, 'test!!!!')
elif message.content.startswith('!say'):
await message.channel.send(message.channel, 'leave message')
msg = await client.wait_for_message(timeout=15.0, author=message.author)
if msg is None:
await message.channel.send(message.channel, '15초내로 입력해주세요. 다시시도: !say')
return
else:
await message.channel.send(message.channel, msg.content)
client.run('ODIxMzExOTY0OTUyMjY0NzY0.YFB4Xw.3QwR70Bl7WkdFmKRdHwWqxopVXE')
https://mandu-mandu.tistory.com/65?category=693080
https://github.com/Rapptz/discord.py