안녕하세요. 루크입니다.
https://youtu.be/kWIQe5CPpxI
이번 시간에는 텔레그램 봇을 만들어서 업무는 물론 부업에서도 활용할 수 있는 나만의 개인 비서 어플을 만들어보겠습니다.
자세한 설명은 유튜브를 참고 부탁드리겠습니다 ㅎㅎ
- 텔레그램 설치
- 서버 만들기
https://www.pythonanywhere.com/
Host, run, and code Python in the cloud: PythonAnywhere
Batteries included With Python versions 2.7, 3.3, 3.4, 3.5 and 3.6, and all the goodies you normally find in a Python installation, PythonAnywhere is also preconfigured with loads of useful libraries, like NumPy, SciPy, Mechanize, BeautifulSoup, pycrypto,
www.pythonanywhere.com
- 훅 설정하기
api.telegram.org/bot토큰/setWebhook?url=서버이름.pythonanywhere.com/토큰
코드
# A very simple Flask Hello World app for you to get started with... import pandas as pd from flask import Flask, request import json import urllib.parse as parse import urllib.request as req app = Flask(__name__) df = pd.read_excel('/home/아이디/mysite/엑셀명.xlsx', sheet_name='시트이름') def baseRequest(command='getMe'): baseURL = 'https://api.telegram.org/bot토큰/' res = req.urlopen(baseURL+command) result = json.loads(res.read())['result'] return result def sendMessage(chat_id, text): query = parse.urlencode([ ('chat_id', chat_id), ('text',text) ]) print(query) baseRequest('sendMessage?'+query) @app.route('/') def hello_world(): return 'Hello from Flask!' @app.route('/토큰', methods=['POST','GET']) def telegram(): data = request.get_json() print(data) chat_id = data['message']['chat']['id'] text = data['message']['text'] try: df3 = df[df['칼럼이름1']== text] sendMessage(chat_id,str(df3['칼럼이름2'].values)) except: sendMessage(chat_id,text) return json.dumps({'success':True})
'부업 - 디지털 노마드 > 온라인 쇼핑몰 (쇼피,네이버 등)' 카테고리의 다른 글
[쇼피] 경쟁강도 파이썬으로 추출하기 코드 공유 (2) | 2020.12.17 |
---|---|
[쇼피] 국가별 주소 샘플 - 애플 사용자분들 앱스토어 국가 변경할 때 참고하세요! (0) | 2020.10.29 |
이 시국 데이트 하기도 어려운데 같이 부업이나 해볼까요? - 우리계발커플 같이 무자본 창업했습니다! (0) | 2020.09.23 |
최근댓글