{"id":21682660,"url":"https://github.com/chairco/dj-hackmd-notifier","last_synced_at":"2025-09-17T11:09:16.491Z","repository":{"id":82500754,"uuid":"107832138","full_name":"chairco/dj-Hackmd-notifier","owner":"chairco","description":"Notification the change with hackmd.io document on monitor","archived":false,"fork":false,"pushed_at":"2022-12-08T00:35:08.000Z","size":39,"stargazers_count":5,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-31T23:29:00.081Z","etag":null,"topics":["diff","django","django-q","hackmd","notification"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chairco.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-10-22T02:43:27.000Z","updated_at":"2023-01-31T16:53:43.000Z","dependencies_parsed_at":null,"dependency_job_id":"18604409-0f6c-4773-973d-2706e13b417d","html_url":"https://github.com/chairco/dj-Hackmd-notifier","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/chairco/dj-Hackmd-notifier","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chairco%2Fdj-Hackmd-notifier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chairco%2Fdj-Hackmd-notifier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chairco%2Fdj-Hackmd-notifier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chairco%2Fdj-Hackmd-notifier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chairco","download_url":"https://codeload.github.com/chairco/dj-Hackmd-notifier/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chairco%2Fdj-Hackmd-notifier/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275583378,"owners_count":25490651,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-17T02:00:09.119Z","response_time":84,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["diff","django","django-q","hackmd","notification"],"created_at":"2024-11-25T15:39:13.194Z","updated_at":"2025-09-17T11:09:16.473Z","avatar_url":"https://github.com/chairco.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dj-Hackmd-notifier\n\nDjango + Django-Q 開發，用來建立排程與比對 [Hackmd.io](https://hackmd.io/) 上的網頁文件內容的線上工具。\n\n\n## 環境設定\n\n建議採用 [Pipenv](https://github.com/kennethreitz/pipenv) 做套件管理，Pipenv 是一個出色的 Python 工具管理套件，類似其他程式語言裡常見的：bundler, composer, npm, cargo, yarn, 等\n\n如果對它還不熟悉，這裡有一篇簡單的 [Pipenv 使用教學](https://chairco.github.io/posts/2017/02/Pipenv%20tutorial.html)。\n\n### pipenv\n\n建立環境:\n```\npipenv --python 3.6.3\n```\n\n安裝必要套件:\n```\npipenv install --dev\n```\n\n進入虛擬環境:\n```\npipenv shell\n```\n\n\n### py3 內建虛擬環境\n\n```\npython3 -m venv env\n```\n\n進入虛擬環境:\n```\nsource source env/bin/activate \n```\n\n安裝必要套件:\n```\npip install -r requirements.txt\n```\n\n\n## Django 環境設定\n\n使用 python-dotenv 管理環境變數，首先需要在 settings/ 目錄下先建立 `local.env` 檔案。\n\n```\ncp dj-Hackmd-notifier/src/src/settings/local_sample.env dj-Hackmd-notifier/src/src/settings/local.env \n```\n\n接著設定環境需要參數:\n\n+ `EMAIL_HOST_USER={}` 發送信件 gmail 帳號。\n+ `EMAIL_HOST_PASSWORD={}` 發送信件 gmail 密碼。\n+ `DATABASE_URL='postgres://localhost/hackmds'` 預設採用 postgresql 資料庫，可根據需求修改(sqlite3 目前測試會有問題)。\n+ `SECRET_KEY={}` Django 需要的 secret key。可到[這邊](https://www.miniwebtool.com/django-secret-key-generator/)取得\n\n因為 Google 目前針對帳號安全開啟二階段認證，因此如果需要透過第三方程式發送 gmail 信件，請先至[後台](https://myaccount.google.com/lesssecureapps)關閉二階段認證並且允許第三方程式存取帳戶。 *注意: 這樣修改可能會有資安危險。*\n\n\n新增 logs 資料夾, 專案所有產生的 log file 都會存放在此\n```\ncd dj-Hackmd-notifier/src\nmkdir -p logs\n```\n\n\n建立資料庫:\n\n注意，目前資料庫預設 `Postgresql` 請先在本機端預設安裝，並且建立對應的 table。安裝完成後再執行 migrate 指令。\n\n```\npython manage.py migrate\n```\n\n建立 admin 帳號(請注意一定要輸入信箱，因為信件會發送到此):\n```\npython manage.py createsuperuser\n```\n\n啟動伺服器：\n```\npython manage.py runserver\n```\n\n如果可以順利連到 [localhost:8000/admin](http://localhost:8000/admin) 恭喜已經完成一半了。\n\n\n## 排程設定\n\n\n### 一次一個網頁\n\n先進入 [後台網頁](http://localhost:8000/admin/)，並用剛剛建立的 admin 帳號與密碼登入。\n\n![Imgur](https://i.imgur.com/OpHhXEU.png)\n\n\n點選 `Scheduled tasks` 旁邊的新增排程。\n\n+ `Name` 隨意輸入，不要太複雜。\n+ `Func` 執行任務函式，src 是 Django project 名稱, tasks 是檔案名稱, `hackmd_task` 為函式名稱。\n+ `Hook` 任務結束時會印出 stdout 的結果。目前還沒印出具體訊息。\n+ `Kwargs` 函式需要的參數, 在這裡只需要 `url`。注意因為比對是以 `url` 作為 key 儲存在 db 因此請以 hackmd.io **發表**的網址，例如: url='https://hackmd.io/s/ByIn4AYaZ', 一定要帶上 https:// 程式未來可為這部分自動偵測。\n+ `Schedule type` 多久運作一次。\n+ `Repeats` 設定 -1 代表永遠。\n+ `Next Run` 點選現在。\n\n最後按儲存完成。 \n\n![Imgur](https://i.imgur.com/5NXFgC2.png)\n\n![Imgur](https://i.imgur.com/yMSlUX8.png)\n\n\n### 一次多組網頁\n\n感謝 @mlouielu 提醒。可能會有一次要抓取多個網頁（根據 hw 別）這邊新增一個 `hackmd_taskchain` 函數來處理。\n\n+ `Name` 隨意輸入。\n+ `Func` 執行任務函式，src 是 Django project 名稱, tasks 是檔案名稱, `hackmd_taskchain` 為函式名稱。\n+ `Hook` 任務結束時會印出 stdout 的結果。目前還沒印出具體訊息。\n+ `Kwargs` 函式需要的參數, 在這裡輸入多個網址，例如: `urls='https://hackmd.io/s/H1fSXCcpb, https://hackmd.io/s/H1fSXCcp2#1234'` 程式會幫忙處理前後空白問題。注意要帶上 https://\n+ `Schedule type` 多久運作一次。\n+ `Repeats` 設定 -1 代表永遠。\n+ `Next Run` 點選現在。\n\n![Imgur](https://i.imgur.com/gKKxho0.png) \n\n![Imgur](https://i.imgur.com/ukz8lEH.png)\n\n\n### 啟動 Django-Q instance\n\n開啟一個終端機執行 Django-Q:\n\n```\npython manage.py qcluster\n```\n\n看到下面資訊就代表運作成功，接著稍等一下就會開始執行排程。\n\n```\n21:38:27 [Q] INFO Q Cluster-9144 starting.\n21:38:27 [Q] INFO Process-1:1 ready for work at 9146\n21:38:27 [Q] INFO Process-1:2 ready for work at 9147\n21:38:27 [Q] INFO Process-1:3 ready for work at 9148\n21:38:27 [Q] INFO Process-1:4 ready for work at 9149\n21:38:27 [Q] INFO Process-1:5 monitoring at 9150\n21:38:27 [Q] INFO Process-1 guarding cluster at 9145\n21:38:27 [Q] INFO Process-1:6 pushing tasks at 9151\n21:38:27 [Q] INFO Q Cluster-9144 running.\n```\n\n\n如果有超過 2 處的修改就會收到信件如：\n\n![Imgur](https://i.imgur.com/rnDd7Xu.png)\n\n![Imgur](https://i.imgur.com/kXyu18I.png)\n\n\n## 參考\n\n本專案同時參考 @uranusjr 的 diffhtml [專案](https://github.com/uranusjr/diffhtml)在此感謝。\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchairco%2Fdj-hackmd-notifier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchairco%2Fdj-hackmd-notifier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchairco%2Fdj-hackmd-notifier/lists"}