HackMD
  • Prime
    Prime  Full-text search on all paid plans
    Search anywhere and reach everything in a Workspace with Prime plan.
    Got it
      • Create new note
      • Create a note from template
    • Prime  Full-text search on all paid plans
      Prime  Full-text search on all paid plans
      Search anywhere and reach everything in a Workspace with Prime plan.
      Got it
      • Sharing Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • More (Comment, Invitee)
      • Publishing
        Everyone on the web can find and read all notes of this public team.
        After the note is published, everyone on the web can find and read this note.
        See all published notes on profile page.
      • Commenting Enable
        Disabled Forbidden Owners Signed-in users Everyone
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
        • Everyone
      • Invitee
      • No invitee
      • Options
      • Versions and GitHub Sync
      • Transfer ownership
      • Delete this note
      • Template
      • Save as template
      • Insert from template
      • Export
      • Dropbox
      • Google Drive
      • Gist
      • Import
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
      • Download
      • Markdown
      • HTML
      • Raw HTML
    Menu Sharing Create Help
    Create Create new note Create a note from template
    Menu
    Options
    Versions and GitHub Sync Transfer ownership Delete this note
    Export
    Dropbox Google Drive Gist
    Import
    Dropbox Google Drive Gist Clipboard
    Download
    Markdown HTML Raw HTML
    Back
    Sharing
    Sharing Link copied
    /edit
    View mode
    • Edit mode
    • View mode
    • Book mode
    • Slide mode
    Edit mode View mode Book mode Slide mode
    Note Permission
    Read
    Only me
    • Only me
    • Signed-in users
    • Everyone
    Only me Signed-in users Everyone
    Write
    Only me
    • Only me
    • Signed-in users
    • Everyone
    Only me Signed-in users Everyone
    More (Comment, Invitee)
    Publishing
    Everyone on the web can find and read all notes of this public team.
    After the note is published, everyone on the web can find and read this note.
    See all published notes on profile page.
    More (Comment, Invitee)
    Commenting Enable
    Disabled Forbidden Owners Signed-in users Everyone
    Permission
    Owners
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Invitee
    No invitee
       owned this note    owned this note      
    Published Linked with GitHub
    Like BookmarkBookmarked
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Deta.sh Micros Base Drive 使用方法(待補充) ###### tags: `deta` `heroku` [ToC] 因為我教學的對象是**高中生**,由於年紀太小,他們沒有信用卡, 許多提供雲運算的商家都需要試刷卡(就算提供免費額度),它們也都無法使用。 Heroku對他們來說是個學習的好工具,但現在heroku要收費了, 我也要另外想辦法了!我找到了deta.sh,它有我需要的全部雲服務,太棒了! 目前在上面放了3個line bot - [bot1](https://hackmd.io/tTnueeJiS5yQgDtlE_G2Hw) [bot2](https://hackmd.io/rGg38eMVT5iR-cyzvFVP1g) [bot3](https://hackmd.io/mQAwolZvRKWQw5XSzFwMNg) 與 1隻爬蟲(使用cron定時抓資料) 它有 Micros, Base, Drive 三種服務 ### Micros: Deploy scalable Node & Python apps in seconds. 簡單來說 Deta micros 相當於 heroku dynos Standard 1x 的平替。Drive它提供無限的空間,無限的Micros數量。 可以將你的 node.js或是python程式放在它上面執行,成為微服務器。 這部分使用方法可參閱[將LineBot發布到 Deta.sh 中](https://hackmd.io/@CSL/HJcsPvhOj) 裡面有詳細的說明。 ```bash! deta 常用指令 auth Change auth settings for a deta micro clone Clone a deta micro #從 deta.sh 複製到本機 Example: deta clone --name mymicro cron Change cron settings for a deta micro "下方有詳細說明" deploy Deploy a deta micro #將程式發布: deta deploy ,程式碼修改後要執行的 details Details about a deta micro #顯示 micros的狀況,例如: { "name": "crontest", "id": "b17dxxxxxxxxxxxxxxxx", "project": "default", "runtime": "python3.9", "endpoint": "https://tkxxxx.deta.dev", "region": "ap-southeast-1", "dependencies": [ "deta" ], "visor": "enabled", "http_auth": "disabled", "cron": "2 minutes" } help Help about any command login Login to deta #登入deta.sh網站 new Create a new deta micro projects List deta projects pull Pull the lastest deployed code of a deta micro run Run a deta micro Example: deta run # run from cli update Update a deta micro version Print deta version visor Change visor settings for a deta micro #debug時要enable方便偵錯 watch Deploy changes in real time #執行這個功能時,一儲存程式會自動發布,不用再deploy ``` #### deta.sh micros: cron 功能 deta的micros有cron的功能,這功能相當好用,它可以依照你的需要時間取執行你的程式(**網路爬蟲很需要**),使用方法與linux的crontab相當類似。 執行下列指令就能每10分鐘自動執行main.py mkdir crontest cd crontest deta new --python 新增 main.py 與 requirements.txt(內容在下方) deta deploy deta visor enable deta cron set "10 minutes" ```python main.py ---------------------- from deta import app # define a function to run on a schedule # the function must take an event as an argument @app.lib.cron() def cron_job(event): return "running on a schedule" ---------------------- requirements.txt ---------------------- deta ``` 登入 deta.sh (指令:deta login) 選擇 micros 裡的 crontest 查看 visor ,他每10分鐘執行一次, 如果不要再執行cron功能了,下指令 deta cron remove即可。 ``` 在官方文件中還有許多設定時間的方法,看一下就會使用了,不過要這注意是UTC時間 1. deta cron set "1 minute" : run every minute 2. deta cron set "5 hours" : run every five hours 3. deta cron set "0 10 * * ? *" : run at 10:00 am(UTC) every day 4. deta cron set "30 18 ? * MON-FRI *" : run at 6:00 pm(UTC) Monday through Friday 5. deta cron set "0/5 8-17 ? * MON-FRI *" : run every 5 minutes Monday through Friday between 8:00 am and 5:55 pm(UTC) ``` ### Base: Instantly usable database with a feature-rich API. Deta Base is a super easy to use production-grade NoSQL database that comes with unlimited storage. 它是一個NoSQL資料庫(無限的空間),我使用的感覺是"它與 redis cloud 很相像"。 ```python! from deta import Deta deta = Deta("xxxxxxxxx") users = deta.Base("you_data_base_name") id='001' datajson={"name":"Mary","Gender":"female"} # 寫入資料庫: insert 與 put users.insert(datajson,id) # 後面的id是資料庫的key,前面的參數是data # 如果id已存在,insert時會出現錯誤 # 使用put則不會,會覆蓋原來的資料 users.put(datajson,id) #從資料庫讀取資料 item=users.get(id) #從資料庫將資料刪除 users.delete(id) #將資料庫的資料更新(修改) users.update(datajson,id) ``` ### Drive: Upload, host and serve images and files. The easy to use cloud storage solution by Deta – get 10GB for free. Drive它提供10GB的空間讓你存放影像或其他種類的檔案(如pdf、mp4、...等), ## :memo: deta.sh官方文件 [Deta.sh官方DOC](https://docs.deta.sh/docs/home)拿來 ## :rocket: 它的缺點:號稱"Deta is free for ever."且還在beta中。 大家對於這些免費的資源所帶來的後遺症,都經歷不少了! 擔心一但若不能持續,後續搬家維護的問題不少。穩定度如何?也要持續觀察! 但若只是拿來學習、寫一些簡單的webapi,應該相當不錯。 Author - [name=林奇賢]

    Import from clipboard

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lost their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template is not available.


    Upgrade

    All
    • All
    • Team
    No template found.

    Create custom template


    Upgrade

    Delete template

    Do you really want to delete this template?

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Tutorials

    Book Mode Tutorial

    Slide Mode Tutorial

    YAML Metadata

    Contacts

    Facebook

    Twitter

    Feedback

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions

    Versions and GitHub Sync

    Sign in to link this note to GitHub Learn more
    This note is not linked with GitHub Learn more
     
    Add badge Pull Push GitHub Link Settings
    Upgrade now

    Version named by    

    More Less
    • Edit
    • Delete

    Note content is identical to the latest version.
    Compare with
      Choose a version
      No search result
      Version not found

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub

        Please sign in to GitHub and install the HackMD app on your GitHub repo. Learn more

         Sign in to GitHub

        HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Available push count

        Upgrade

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Upgrade

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully