發表文章

[Weekly Report] 2018.04.05 - 04.18

[Weekly Report] 2018.04.05 - 04.18 My dormitory doesn't have static public IP address so I tend to use Dynamic DNS (DDNS) method. Even though my D-Link Access Point (AP) provides free DDNS service, but I want to use my own domain name. First I change my domain name server from freenom to Cloudflare , then install ddclient for automatically update my IP address to Cloudflare. But no matter how I changed the arguments of the configuration file for hours, it still didn't work. Then I tended to use Cloudflare API and read the official document, it succeeded in ten minutes. Here is my sample DNS-update code, you can also use requests library instead of curl : '''This program will get record from Cloudflare and compare my current IP address''' import json from os import popen, system getCMD = 'curl -X GET "https://api.cloudflare.com/client/v4/zones/{ZONE-ID}/dns_records?type=A&name={YOUR-FULL-DOMAIN-NAME}" \ -H "X-Auth-Email: {YOUR-...

PyDrive備份教學

最近買了台Raspberry Pi,因為讀寫都是在SD卡上面,所以很怕哪天SD卡突然掛了,裡面的資料就都沒了,上網找了這個方法,但用的人似乎很少 ,就來寫我人生中的第一篇電腦教學文!! 開始 此方法是使用Google釋出的API 所以要先去 APIs console 建立專案 如果是第一次使用 會先跳出使用介紹 這個別理他 ((好啦 大家都知道 先點選右上角的 "選取專案" -> "建立專案" 建立後 應該會直接跳轉到資料庫的畫面 此時透過搜尋列搜尋 "Drive API" 接著啟用它 點選 左側 "憑證" 後 選取"OAuth同意畫面" 只需在 " 向使用者顯示的產品名稱 " 輸入即可儲存 接著建立憑證 選取 "OAuth 用戶端ID" 類型務必選擇 "其他" 這樣可以用的範圍比較廣 接著右邊有個下載符號 下載完放到要執行的資料夾內 並重新命名為 client_secrets.json 安裝pyDrive 可以透過指令 $ pip install pydrive 會安裝到最新版本 但是遇到大檔上傳時會有內存溢出問題 因此建議可以安裝舊版 $ pip install -e git+https://github.com/googledrive/PyDrive.git#egg=PyDrive 裝完後 沒問題就可以開始寫程式了 先建立一個"quickstart.py" 的檔案 (檔名可以隨便取) 並貼上下面指令: (詳細請參考: http://pythonhosted.org/PyDrive/quickstart.html) from pydrive.auth import GoogleAuth from pydrive.drive import GoogleDrive gauth = GoogleAuth() gauth.CommandLineAuth() #透過授權碼認證 drive = GoogleDrive(gauth) file1 = drive.CreateFile({'title': 'Hello.txt'}) # 建立檔案 file1.Se...