def doIt():
    keyPath = os.path.join(os.getcwd(), 'key.properties')
    key = mylib3.getKey(keyPath)
    _url = 'http://openAPI.seoul.go.kr:8088'
    _key = str(key['gokr'])
    _type = 'json'
    _service = 'CardSubwayStatisticsService'
    _start_index = 1
    _end_index = 5
    _use_mon = '201306'
    _maxIter = 20
    _iter = 0
    _jfname = 'src/ds_open_subwayPassengers.json'
    while _iter < _maxIter:
        _api = os.path.join(_url, _key, _type, _service, str(_start_index),
                            str(_end_index), _use_mon)
        #print _api
        _api = _api.replace("\\", '/')
        r = requests.get(_api)
        _json = r.json()
        print _json
        saveJson(_jfname, _json)
        saveDB(_json)
        _start_index += 5
        _end_index += 5
        _iter += 1
Example #2
0
def doIt():
    # (1) service + operation
    SERVICE = 'ArpltnInforInqireSvc'
    OPERATION_NAME = 'getMinuDustFrcstDspth'
    params1 = os.path.join(SERVICE, OPERATION_NAME)
    # (2) query params encoding
    _d = dict()
    _d['dataTerm'] = 'month'
    params2 = urllib.urlencode(_d)
    # (3) add my service key
    keyPath = os.path.join(os.getcwd(), 'src', 'key.properties')
    key = mylib3.getKey(keyPath)
    keygokr = key['kgokr']  # keygokr='8Bx4C1%2B...'
    params = params1 + '?' + 'serviceKey=' + keygokr + '&' + params2
    # (4) make a full url
    _url = 'http://openapi.airkorea.or.kr/openapi/services/rest/ArpltnInforInqireSvc'
    url = urlparse.urljoin(_url, params)
    url = url.replace("\\", '/')
    # (5) get data
    data = requests.get(url).text
    print data
import os
import requests
import mylib3
import urlparse
keyPath = os.path.join(os.getcwd(), 'key.properties')
key = mylib3.getKey(keyPath)

_url = 'http://openAPI.seoul.go.kr:8088'
_key = str(key['gokr'])
_type = 'xml'
_service = 'CardSubwayStatisticsService'
_start_index = 1
_end_index = 5
_use_mon = '201306'
_maxIter = 2
_iter = 0
while _iter < _maxIter:
    _api = os.path.join(_url, _key, _type, _service, str(_start_index),
                        str(_end_index), _use_mon)
    #print _api
    _api = _api.replace("\\", '/')
    response = requests.get(_api).text
    print response
    _start_index += 5
    _end_index += 5
    _iter += 1