Code Monkey home page Code Monkey logo

linebot_heroku_wakeup's Introduction

操作步驟:

1.下載程式碼

git clone https://github.com/maso0310/linebot_heroku_wakeup.git

2.依照此篇影片內容步驟中進行程式碼中LINEBOT、MongoDB設定

3.將自己的herokuapp網址複製至下圖紅框中,完成指定的herokuapp喚醒設定
喚醒heroku的網址設定

4.若要維持每天24小時運作,則需要進入heroku官網進行信用卡資料設定(從每月550小時額度新增為1000小時),同一個帳號之下的APP使用的運作時間共同計算,可由信用卡設定下方觀看每月額度與已使用累積時間。 heroku信用卡設定的位置


5.部署至herokuapp之後,可由自己的heroku根路徑('/')網址進入以下網頁
簡易說明頁面

6.在herokuapp的more當中,可由viewlog看到每28分鐘進行一次喚醒的動作,代表完成設定
喚醒成功的log

簡易的聊天機器人資料庫 Heroku / MongoDB / LINE BOT / HTML網頁

讓herokuapp持續運作不休眠 / flask的route設定與templates網頁模板

1.在app.py當中設定要放置html模板的路徑位置,template_folder='templates'

app = Flask(__name__,template_folder='templates')

2.新增兩個route,一個在根路徑("/")下,作為首頁範例,另一個則是在("/heroku_wake_up")

@app.route("/")
def index():
    return render_template("./index.html")

@app.route("/heroku_wake_up")
def heroku_wake_up():
    return "Hey!Wake Up!!"

3.建立templates資料夾,並新增第一個範例首頁index.html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Maso的萬事屋LINEBOT範例</title>
</head>

<body>
    <h1>Maso的萬事屋LINEBOT範例,使用到以下套件</h1>
    <ul>
        <li>Flask: 一個使用Python編寫的輕量級Web應用框架。</li>
        <li>line-bot-sdk: 一個基於Python的SDK,可用於呼叫LINE BOT API。</li>
        <li>Pymongo: 串連No SQL資料庫型態的MongoDB所使用的python套件。</li>
        <li>Requests: 用於透過pyhon發出request的套件。</li>
        <li>BeautifulSoup4: 用於解析HTML文檔的套件。</li>
    </ul>
</body>

</html>

4.建立每28分鐘喚醒herokuapp的request函數,並以子執行緒方式啟動,使該任務在不影響主程式情況下持續運作

#======讓heroku不會睡著======
import threading 
import requests
def wake_up_heroku():
    while 1==1:
        url = '你的herokuapp網址' + 'heroku_wake_up'
        res = requests.get(url)
        if res.status_code==200:
            print('喚醒heroku成功')
        else:
            print('喚醒失敗')
        time.sleep(28*60)

threading.Thread(target=wake_up_heroku).start()
#======讓heroku不會睡著======

5.完成以Flask網頁框架製作的LINEBOT、HTML網頁模板、MongoDB資料庫與持續運作的herokuapp範例專案部署

====================================
如果喜歡這個教學內容
歡迎訂閱Youtube頻道
Maso的萬事屋
或加LINE私下交流 LINE ID: mastermaso
LOGO
====================================

linebot_heroku_wakeup's People

Contributors

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