2016-11-23 64 views

回答

3

1010data API和SDK將數據發送回無格式。因此,爲了以您想要的格式返回數據,您必須對其執行字符串操作。在你的情況,你可以使用下面的語法來得到你想要的格式:

<willbe name="string_date" value="splice(case(month(date_col);1;'Jan';2;'Feb';3;'Mar';4;'Apr';5;'May';6;'Jun';7;'Jul';8;'Aug';9;'Sep';10;'Oct';11;'Nov';12;'Dec';NA) day(date_col);' ')"/> 

你可以在這裏閱讀有關的所有字符串處理函數:1010data String Functions

一旦你確定並執行您想要的格式,您可以使用API​​來檢索乾淨的數據。以下是Python 2.7中完整API調用的示例。作爲參考,1010data API Documentation

import urllib2 
from lxml import etree 

def post(url=None, body=None): 
    return urllib2.urlopen(urllib2.Request(url, body, headers={'Content-Type': 'text/xml'})).read().decode('utf-8') 

if __name__ == '__main__': 
    url = "https://www2.1010data.com/cgi-bin/prod-stable/gw.k?protocol=xml-rpc&apiversion=3&uid=UID" 
    response = post(url + "&pswd=PWD&api=login&kill=possess") 
    tree = etree.fromstring(response) 
    session = {} 
    for child in tree: 
     session[child.tag] = child.text 
    sessionurl = url + "&pswd=" + session['pswd'] + "&sid=" + session['sid'] + "&api=" 
    query = post(sessionurl + "query", 
       "<in><name>pub.doc.retail.salesdetail</name><ops><sel value=i_=1/><willbe name=\"string_date\" value=\"splice(case(month(trans_date);1;'Jan';2;'Feb';3;'Mar';4;'Apr';5;'May';6;'Jun';7;'Jul';8;'Aug';9;'Sep';10;'Oct';11;'Nov';12;'Dec';NA) day(trans_date);' ')\"/></ops></in>") 
    data = post(sessionurl + "getdata", 
       "<in><cols><col>string_date</col></cols></in>") 
+0

偉大的它適用於我 –