Coder Social home page Coder Social logo

kakaobot_hyoammeal's Introduction

효암 급식봇

이 소스는 MIT라이선스 하에 자유롭게 이용할 수 있습니다.

개발 참고 사이트

플러스 친구 추가

개발 환경

  • Amazon Web Service (EC2, Ubuntu 16.04)
  • PyCharm
  • Git

사용 언어

  • Django
  • Python + venv

필요 모듈

  • beautifulsoup4
  • urllib
  • lxml
  • dateutil

설치법

유의사항

혹시나 아마존 AWS EC2 우분투를 이용하는 경우 로케일 문제로 오류가 잦다. http://egloos.zum.com/killins/v/3014274를 보고 로케일을 수정하자.

1. 기초 패키지 설치

 sudo apt-get update
sudo apt-get install python3 python3-pip python3-venv

2. 레포지터리 클론 및 이동

git clone https://github.com/SerenityS/kakaobot_hyoammeal <working_dir>

cd <working_dir>

3. python 가상환경 구축 및 실행

python3 -m venv myvenv
source myvenv/bin/activate

4. python 추가 요구 패키지 설치

pip install Django lxml beautifulsoup4 python-dateutil

5. 첫 마이그레이션 & 실행

python3 manage.py migrate

python3 manage.py runserver host-ip:8000

아래와 같이 뜬다면 정상적으로 실행된 것이다.

Performing system checks...
System check identified no issues (0 silenced).
July 19, 2017 - 19:18:53
Django version 1.11.3, using settings 'kakaobot.settings'
Starting development server at http://host-ip:8000/
Quit the server with CONTROL-C.

여의치 않다면 127.0.0.1 루프백으로 두고 실행해서 테스트해도 된다.

6. 동작 확인

카카오톡 플러스친구 자동등답 API에선 http://host-ip:8000/keyboard/에 대한 반응을 필수로 요구한다.

터미널에 curl -XGET 'http://host-ip:8000/keyboard/'를 입력해보자.

serenitys@serenitys-X34:~$ curl -XGET 'http://host-ip:8000/keyboard/'
{"type": "buttons", "buttons": ["\uc870\uc2dd", "\uc911\uc2dd", "\uc11d\uc2dd", "\ub0b4\uc77c\uc758 \uc870\uc2dd", "\ub0b4\uc77c\uc758 \uc911\uc2dd", "\ub0b4\uc77c\uc758 \uc11d\uc2dd"]}

정상적으로 작동한다면 이와 같은 정보가 오는것을 확인할 수 있다.

또한 keyboard에서 선택한 메뉴의 응답으로 message를 반환하는데 POST형태로 서버로 요구사항을 전달하고 GET으로 정보를 받는다.

터미널에

curl -XPOST 'http://host-ip:8000/message' -d '{ "user_key": "encryptedUserKey", "type" : "text", "content": "중식"}'

를 입력해보자.

serenitys@serenitys-X34:~$ curl -XPOST (생략)
{"keyboard": {"type": "buttons", "buttons": ["\uc870\uc2dd", "\uc911\uc2dd", "\uc11d\uc2dd", "\ub0b4\uc77c\uc758 \uc870\uc2dd", "\ub0b4\uc77c\uc758 \uc911\uc2dd", "\ub0b4\uc77c\uc758 \uc11d\uc2dd"]}, "message": {"text": "07\uc6d4 19\uc77c \uc218\uc694\uc77c \uc911\uc2dd \uba54\ub274\uc785\ub2c8\ub2e4. \n \n\ub098\ubb3c\ube44\ube54\ubc25/\uc57d\uace0\ucd94\uc7a5\n\uac10\uc790\ub41c\uc7a5\uad6d\n\uc18c\uc13

와 같이 반환됨을 확인함으로서 정상 작동함을 알 수 있다.

7. 학교 코드 수정

타학교에서 사용하기 위해선 학교 코드 수정이 필요하다.

hyoammeal/views.py를 열어보자.

# 타학교에서 이용시 수정
regionCode = 'gne.go.kr'
schulCode = 'S100000747'

라는 코드를 발견할 수 있다. 여기서 regionCode는 각 시도교육청의 주소이며, schulCode는 링크 를 참조하도록 하자.

8. crontab을 통한 crawl.py의 주기적 실행

crontab -e
# 매주 일요일 0시 0분에 crawl.py 실행
0 0 * * 7 python3 ~/meal/hyoammeal/crawl.py

9. 카카오톡 플러스 친구와 연동

타게시물들을 참조하도록 하자.

작동 화면

kakaobot_hyoammeal's People

Contributors

serenitys avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.