PyPtt - 當 Python 遇上 PTT - CodingMan

tags: COSCUP2020 中階 RB105

歡迎來到 https://hackmd.io/@coscup/2020 共筆

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 →

點擊本頁上方的 開始用 Markdown 一起寫筆記!
手機版請點選上方 按鈕展開議程列表。

請從這裡開始

簡報公開於:https://pttcodingman.github.io/

CodingMan

  • PTTer
  • Project
    • PyPtt
    • uPtt
      • UI/UX
        • adobeXD
      • EULA
    • Ptt official app
      • Backend
      • User
      • Run python
        • iOS
        • Android

01 - PTT

  • 批踢踢實業坊
    • 簡稱批踢踢、PTT
    • 臺大電子佈告欄(BBS)
    • 貨幣、法律
    • Talnet, SSH and WebSocket
    • 10000 ↑ posts/day
    • 16 ↑ pushs/post
      • crawl 2000 posts

02 - PyPtt

  • 源起 2017 年
    • 抓超貼
    • 深度學習鄉民
      • 自動評論鄉民文章
      • 登入
        • 爬文
        • 推文
      • 登出
    • GitHub
      • PttAutoLoginPost
        • 登入
        • 貼文
        • 登出
      • 網頁式爬蟲
        • 推文不即時
    • 不存在完整解決方案
  • Pure Python PTT API
    https://github.com/PttCodingMan/PyPtt
    • 391 stars
    • 文章
      • 推文
      • 發文
      • 爬文
      • 回文
    • 信箱
      • 寄信
      • 收信
      • 刪信
    • 水球
    • 一般使用者、板主、站長
  • Host
    • PTT1
    • PTT2
    • Localhost

03 - Case

  • 頭推機器人
    • PyPtt
      • 取得最新文章
      • 推文
  • 五樓機器人
    • PyPtt
      • 取得最新文章
      • 爬文
      • 推文
  • 準點報時機器人
    • 跨年搶第一篇
    • PyPtt
      • 取得 PTT 時間
      • 貼文
  • 魔法師終結者
    • 偵測關鍵字寄信
    • PyPtt
      • 取得最新文章
      • 爬文
      • 寄信
  • 地震文機器人
    • 地牛 Wake Up(因爲 PTT 無法取得地震資訊)
    • PyPtt
      • 貼文
  • 機器學習鄉民
    • PyPtt
      • 取得最新文章
      • 爬文
      • 推文
  • 超貼工具
    • Wanted
      • 三篇/天
    • 範圍日期文章
      • 二元搜尋
    • PyPtt
      • 爬文
  • Telegram beauty bot
    https://t.me/CodingMan_ptt_beauty_bot
    • 2000 pic at 6:00 am every day
    • 50 push up(品質保證)
    • PyPtt
      • 爬文
  • PTT One-Time Password
    • 緣由
      • 密碼最多 8 碼
      • 平均 2 小時內破解完成
      • 目前系統無法提供更高安全性
    • 特性
      • 每 30 秒更換一次密碼
    • 演算法
      • RFC2638
    • App
      • Google authenticator
      • Microsoft authenticator
    • Release
      • 等待 PTT 釋出信箱重設密碼功能(不然會被使用者追殺)
  • Ptt Talk
    • 聊天配對服務(目前沒有上線)
    • PyPtt
      • 收發刪信
      • 接水球
  • uPtt
    • 水球通訊軟體

04 - API

  • Install
    • pip3 install PyPtt
from PyPtt import PTT ptt_bot = PTT.API() ptt_bot.login(ptt_id, pw) ptt_bot.logout()
  • Setting
    • Host
      • Ptt1(default)
      • Ptt2
      • Localhost
    ​​​​ptt_bot = PTT.API( ​​​​ host=PTT.data_type.host_type.PTT2)
    • Connect mode
      • Websocket
      • Telnet
      • Localhost
    ​​​​ptt_bot = PTT.API( ​​​​ connect_mode= ​​​​ PTT.connect_core.connect_mode.TELNET)
    • Port
    • Test on localhost
      • Ptt docker
    ​​​​ptt_bot = PTT.API( ​​​​ connect_mode=PTT.connect_core.connect_mode.TELNET, ​​​​ host=PTT.data_type.host_type.LOCALHOST, ​​​​ port=8888)
  • 推文
    • 看板
    • 類型
      • 推、噓、箭頭
    • 內文
      • 自動換行
    • 文章
      • 編號
      • AID
        • 1TJH_XY0
ptt_bot.push( board, PTT.data_type.push_type.PUSH, content, post_index=index)
  • 貼文
    • 看板
    • 標題
    • 內文
    • 文章類型(Gossiping)
      • 問卦
      • 爆卦
    • 簽名檔
ptt_bot.post( board, title, content, 1, 1)
  • 登入式爬蟲
    • 登入 PTT 取得資料
    • 優點
      • 即時推文
      • 條件搜尋
      • Query mode
    • 缺點
      • 效能
        • scrapy
        • BBS 架構需要翻頁
    • 文章編號
      • 第一篇:1
      • 最新的文章編號?
    • 取得最新的文章編號
      • 類型
        • BBS
        • Mail
      • 看板名稱
    ​​​​index = ptt_bot.get_new_index ( ​​​​ PTT.data_type.index_type.BBS, ​​​​ board=board_name)
    • 取得最新的文章編號
      • 類型
      • 看板
      • 搜尋類型
      • 搜尋條件
    ​​​​index = ptt_bot.get_new_index ( ​​​​ PTT.data_type.index_type.BBS, ​​​​ board, ​​​​ search_type= ​​​​ PTT data_type.post_search_type.KEYWORD, ​​​​ search_condition='[公告]')
    • 取得文章
      • 看板
      • 文章
        • 編號
        • AID
          • 1TJH_XY0
    • 取得文章
      • 看板
      • 編號
      • 搜尋類型
        • KEYWORD
        • AUTHOR
        • PUSH
        • MARK
        • MONEY
      • 搜尋條件
    • 取得文章
      • 看板
      • 編號
      • Query mode
        • 避開翻頁問題

05 - Demo

06 - Reference


Q:有一些 App 發文是不計算 P 幣的,PyPtt 會計算 P 幣嗎?還是像其它 App 一樣是直接 0P 幣?聽眾

A:之前有其它開發者,號稱是用人類平均手打的速度送出的,但是他後來好像也被停權了。PyPtt 的作法是直接送出,所以就是 0P 幣。CodingMan

Q:想要貢獻有需要遵守的 policy 嗎?或是要 fork 出來自己改?聽眾

A:歡迎貢獻,如果有好的作法我會 merge 起來再作修改。CodingMan

Select a repo