Git Product home page Git Product logo

gogopowerkimibot's Introduction

GoGoPowerKimi

Wake Up Heroku

LINE Bot, LINE Notify. 使用 Django, Django Q 排程, PostgreSQL, GraphQL, GitHub Active 自動部署至 Heroku 發票, 天氣, 天文, 匯率, 常春藤, 股市, 疫情, ptt 爬蟲, Cambridge Dictionary爬蟲 中油油價漲幅 notify, 每日英文單字 notify, Shopee自動打卡簽到 等

line bot line notify

Commands

  • 發票 {數字N}: N:代表前 N 期的發票(optinal) ex. 發票 1
  • 天氣 {地區}: 地區:縣市區(required) ex. 天氣汐止
  • 疫情: 台灣疫情資訊
  • 匯率 {幣別}: ex. 匯率 美金
  • 卡比請客
  • 笑鼠人
  • 吱吱
  • 蔡章章戶頭
  • t:{英文單字}: 取得翻譯 音標 詞性
  • te:{英文單字}: 取得翻譯 音標 詞性 中英例句
  • td:: 取得每日一單字
  • ls : 顯示所有指令
  • 天文: 當天天文景象+圖片
  • 天文月: 當月天文景象 https://www.nmns.edu.tw/learn/feature/star/2021/202109/
  • 樂透: 威力彩, 大樂透
  • 三大: 三大法人買賣
  • 外資{數字N}: 外資買賣 N:代表前N名 ex. 外資1
  • event: 永豐一週財經大事

Install package

pip3 install -r requirements.txt

Apply for LINE dev account

https://developers.line.biz/en/

Migration

# create
python3 manage.py makemigrations

# sync
python3 manage.py migrate

Set up Https by ngrok

LINE bot user webhook url as a link to server. 1. require url not IP address. 2. must https.

https://ngrok.com/download

Run server

# 將靜態文件收集到STATIC_ROOT中
python3 manage.py collectstatic
python3 manage.py runserver
./ngrok http 8000

Allow hosts

linebot_practise/settings.py

ALLOWED_HOSTS = ['127.0.0.1', '20af8c34126e.ngrok.io']

Add Webhook URL

ngrok webhook

Heroku

  1. runtime.txt
  2. Procfile : 告訴 Heroku 伺服器種類及主程式名稱
  3. gogopowerkimibot/prod_settings.py

Heroku 免費限制

  1. 每 30 分鐘沒使用就會停機
    • Django Q 排程, 設定每25分鐘, 呼叫一次api避免休眠
  2. 免費 550 小時
    • 可以驗證信用卡增加 450 小時
    • 因為加了排程會導致時間使用超過, 可以設定凌晨時不呼叫排成,讓他停機. 然後使用 github的workflows, 建立排程在早上喚醒
## install
pip3 install virtualenv

## create env
virtualenv herokuenv

cd herokuenv
## start env
source bin/activate
## stop env
deactivate

pip3 install dj-database-url dj-static gunicorn psycopg2-binary
pip freeze > requirements.txt

heroku config:set DJANGO_SETTINGS_MODULE=gogopowerkimibot.prod_settings
heroku config:set DISABLE_COLLECTSTATIC=1
heroku config:add TZ="Asia/Taipei"
heroku git:remote -a gogopowerkimibot

# bash
heroku run bash

# log
heroku login
heroku logs --tail

Apply for notify token

https://notify-bot.line.me/my/

Schedule tool: Django Q

  1. pip3 install django-q
  2. settings.py > INSTALLED_APPS > add django_q
  3. python3 manage.py migrate
  4. settings.py > INSTALLED_APPS > add Q_CLUSTER :https://django-q.readthedocs.io/en/latest/configure.html#orm-configuration
# settings.py example
Q_CLUSTER = {
    'name': 'myproject',
    'workers': 8,
    'recycle': 500,
    'timeout': 60,
    'compress': True,
    'save_limit': 250,
    'queue_limit': 500,
    'cpu_affinity': 1,
    'label': 'Django Q',
    'redis': {
        'host': '127.0.0.1',
        'port': 6379,
        'db': 0, }
}

Q_CLUSTER = {
    'name': 'gogopowerkimibot',
    'workers': 1,
    'timeout': 600,
    'retry': 1200,
    'queue_limit': 50,
    'bulk': 10,
    'orm': 'default'
}
  1. python3 manage.py qcluster

GraphQL Client

pip3 install --pre 'gql[all]'

Reference

memo

python3 manage.py createsuperuser
python3 manage.py showmigrations
python3 manage.py migrate django_q zero
python3 -B -m services.linenotifyservice

gogopowerkimibot's People

Contributors

dependabot[bot] avatar kimi0230 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  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.