-
Notifications
You must be signed in to change notification settings - Fork 4
介接程式使用說明
ssivart edited this page Nov 6, 2018
·
6 revisions
可以傳入的參數組合為:
- 字串形式
direct(start_date='2012/01/01', end_date='2013/01/01', format='%Y/%m/%d')
- datetime物件
direct(start_date=start_date, end_date=end_date)
- 傳入delta執行從今天往前推算n天
direct(delta=-3)
進入django shell
python manage.py shell
import特定app的direct function
from crops.builder import direct
result = direct(start_date='2016/01/01', end_date='2018/01/01', format='%Y/%m/%d')
direct方法會回傳一個dailytrans.utils.DirectResult物件,可以取得start_date, end_date, success(是否執行成功)
direct.success # return True
direct.start_date # return 2016/01/01
- 繼承AbstractApi(定義在dailytrans/builders/abstract.py),分別定義以下三種方法:
- request(): 對API發送HTTP請求
- hook(): 解序列成dailytrans.DailyTran物件
- load(): 儲存或更新dailytrans.DailyTran物件
- 在特定app新增builder.py
- 透過director界面(定義在dailytrans/builders/utils.py)實作direct方法如:
from dailytrans.builders.utils import director
@director
def direct(start_date=None, end_date=None, format=None, delta=None)
pass # do something...
- 介接程式路徑:dailytrans/builders/
- 介接程式測試路徑:dailytrans/tests/builders/