250x250
Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 파이썬
- lda
- spring MVC(모델2)방식
- Gmarket
- 방식으로 텍스트
- java
- db
- 크롤링
- word2vec
- 토픽추출
- 과학백과사전
- Topics
- 幼稚园杀手(유치원킬러)
- oracle
- 코사인 유사도
- 네이버뉴스
- 이력서
- 자바
- mysql
- (깃)git bash
- 지마켓
- tomoto
- jsp 파일 설정
- test
- r
- pytorch
- Python
- Websocket
- 게시판 만들기
- RESFUL
Archives
- Today
- Total
무회blog
200819-,텔레그램 챗봇, 멜론차트 , 테스트 001 본문
melon_rank.py
0.00MB
testBot001.py
0.00MB
testBot001.py
# import modules
from telegram.ext import (Updater, CommandHandler, MessageHandler, Filters,)
import logging
from melon_rank import show_music_rank
# print(show_music_rank())
print('kase',show_music_rank)
# Enable logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
logger = logging.getLogger(__name__)
#My bot token from BotFather
token = '1356043789:AAG3egnGTbnNdpvDmmLunlns-OJHUFoxLS8'
# define command handlers
def start(bot, update):
bot.send_message(chat_id=update.message.chat_id, text="봇이 정상 작동 합니다.")
# 정해진 커맨드가 아닌 다른 명령어를 받았을때 출력할 메시지
def unknown(bot, update):
bot.send_message(chat_id=update.message.chat_id, text="죄송하지만 ,명령어를 이해 할수 없습니다.")
# main 문을 정의
def main():
# Create Updater object and attach dispatcher to it
updater = Updater(token)
dp= updater.dispatcher
print("Bot started")
#Start the bot
updater.start_polling()
dp.add_handler(CommandHandler('start', start))
## 현재 한국어 코멘드가 들어가지 않음.
dp.add_handler(CommandHandler('melon_rank', show_music_rank))
dp.add_handler(MessageHandler(Filters.command, unknown))
# Run the bot until you press Ctrl-C
updater.idle()
updater.stop()
if __name__ == '__main__':
main()
ps: 현재 한국어 지원 안함
melon_rank.py
import time ,re , timeit
import pandas as pd
from selenium import webdriver
from bs4 import BeautifulSoup
from bs4 import SoupStrainer
from selenium import webdriver
from datetime import datetime
options = webdriver.ChromeOptions()
options.add_argument('headless')
options.add_argument('window-size=1920x1080')
options.add_argument("disable-gpu")
# 혹은 options.add_argument("--disable-gpu")
driver = webdriver.Chrome("C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe", options = options)
# driver = webdriver.Chrome("C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe")
def show_music_rank(self,update):
# def show_music_rank(self):
addr = 'https://www.melon.com/chart/index.htm'
driver.get(addr)
melon = driver.page_source
soup = BeautifulSoup(melon, 'html.parser')
title = soup.select('#frm > div div.ellipsis.rank01 > span > a')
artist = soup.select('#frm > div div.ellipsis.rank02 > span > a')
titles = []
for i,j in enumerate(title):
if i < 10:
tts = str(i) + ' ' + j.get_text()
titles.append(tts)
artists = []
for i, j in enumerate(artist):
if i < 10:
tts = j.get_text()
artists.append(tts)
key_val = [titles, artists]
# rank_text = dict(zip(*key_val))
update.message.reply_text('실시간 멜론 차트\n'
+ '1 위: ' + '제목: ' + titles[0] +'-' '아티스트: ' + artists[0] + '\n'
+ '2 위: ' + '제목: ' + titles[1] +'-' '아티스트: ' + artists[1] + '\n'
+ '3 위: ' + '제목: ' + titles[2] +'-' '아티스트: ' + artists[2] + '\n'
+ '4 위: ' + '제목: ' + titles[3] +'-' '아티스트: ' + artists[3] + '\n'
+ '5 위: ' + '제목: ' + titles[4] +'-' '아티스트: ' + artists[4] + '\n'
+ '6 위: ' + '제목: ' + titles[5] +'-' '아티스트: ' + artists[5] + '\n'
+ '7 위: ' + '제목: ' + titles[6] +'-' '아티스트: ' + artists[6] + '\n'
+ '8 위: ' + '제목: ' + titles[7] +'-' '아티스트: ' + artists[7] + '\n'
+ '9 위: ' + '제목: ' + titles[8] +'-' '아티스트: ' + artists[8] + '\n'
+ '10 위: '+ '제목: ' + titles[9] +'-' '아티스트: ' + artists[9] + '\n'
)
'Python' 카테고리의 다른 글
python: websocket, client,server (0) | 2020.08.25 |
---|---|
python: restFul, REST API, _inputOutput_02, rest,조회,GET,입력,POST, (0) | 2020.08.25 |
python: 200805-keras001.py, 파이참 모듈에서 테스트 (0) | 2020.08.05 |
파이썬 ,코드 읽고 파일 경로 열기 , # import 된 모듈의 지정된 경로 아래 파일을 오픈하기 ,지정경로 파일 열기 (0) | 2020.07.31 |
200724-cluster,문서분류,파일, (0) | 2020.07.24 |
Comments