python plurk api 2.0 噗浪機器人製作教學
這邊是噗浪機器人api2.0的製作教學文,包含回應,按愛心功能,還有簡易部屬,有興趣的人歡迎看看,若有錯誤也歡迎指教:D
首先先創一個新的噗浪帳號
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
創建完成後,點這裡,按下「註冊新的應用服務」,
接下來的步驟這邊很詳細,就不贅述了XD,我的機器人程式也參考了這個連結,在這裡你會獲得四個參數,請記起來
- App Key
- App Secret
- Access Token
- Access Token Secret
Python 安裝
如果是沒有安裝python的人,可以參考教學,我記得mac原本就有安裝python3的樣子,如果是mac使用者可以直接繼續看
程式部分
可參考這份專案,這是SealBot的初期版本
可以選擇在terminal輸入此指令 git@github.com:chenyunhsin/PlurkSealBot.git
(需要git帳號),或是直接複製起來,存在自己新建的檔案裡,接著依序輸入以下指令(//後面是註解,不用輸入)
如果成功跑起來,可以試試看用本帳加機器人好友,理論上如果有好友邀請,機器人會自動同意邀請,且發噗後會回應~~
偶爾漏噗純屬正常,就api撈回來的資料本來就有少,目前還沒想到比較好的解決方法:p
程式功能介紹,請配合完整程式碼對照著看
非完整程式碼,複製貼上不會動喔,這邊是介紹~完整程式碼在這邊
程式主體是一個while loop,會不斷地跑,偵測有沒有新的噗會好友邀請,並對關鍵字做回應,這邊分段對程式介紹(非完整程式碼),若要客製化機器人可以看看~
請再創一個Procfile,請注意無副檔名!
內容如圖,總之就是為了讓worker去執行bot.py檔案!
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
使用Heroku部屬(將於11月起停止免費方案)
這邊是選用Heroku來部屬,選擇原因是Heroku提供免費帳戶每個月450個小時的運行時間,開通信用卡後+550個小時的免費時數,如果只有一個server,是很夠用的,至少我目前還沒被收到錢啦XD
先創建帳號後,登入,點選create new app
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
點進剛剛創的app,然後點Deploy
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
往下拉會看到一些指令,教你下載cli(這邊請根據自己的系統來選喔)和如何上傳檔案到heroku的空間
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
上傳成功後,termianl輸入heroku ps:scale worker=1
,因為雖然Procfile有定義,但根據heroku文件所說,除了web dyno,其他要自己起0.0
Heroku runs one web dyno for you automatically, but other process types don’t start by default. To launch a worker, you need to scale it up to one dyno:
最後用此指令可以看logheroku logs
,這個看dyno狀態heroku ps
使用Railway部屬
免費方案為每個月500小時5美元
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
首先請於github開一個Private的專案,請務必開Private,因為機器人專案包含很多token!
創建頁面如圖,
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
再把小海豹的程式碼丟進這個專案,如果懶得git clone到local再push,就直接這邊新增就好~
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
再來到Railway選擇Deploy from github repo後,綁定上面的專案
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
接下來去Dashboard找到剛建立好的Railway專案,在Start Command輸入
這邊是部署專案啟動時會下的command,我們只需要啟動機器人而已,因此這個command就夠了!至於requirements.txt,Railway環境會先自動pip install -r requirements.txt,所以不需要自己下!
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
結束了~目前還在試跑中,總之先看看會不會被停掉或收錢0.0
注意事項
- 噗浪機器人無法貼連結,但課噗幣可以解決,之前卜卦功能突然失效,寄信去問才知道被系統判斷為機器人就會這樣(使用次數過多就會被判斷為機器人),官方回應如下供大家參考
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 其他還有轉噗,消音,加為粉絲,判斷被提到等功能,可以再參考Plurk api 2.0
參考
Plurk oauth2
Plurk api 2.0
dada
豹豹機器人簡略版程式碼
問題回報or建議or想抖內(?
請私噗
豹豹機器人連結
他搭