안녕하세요?
아나콘다를 사용해서 티맵 API를 파이썬에서 json의 값을 request로 가져오고 그게 딕셔너리 형태로 저장이 되었더라고요
여기서 원하는 값이 두개인데 그게 잘 가져와지네요 무엇을 잘못 입력했을까요?
제가 가져 오고 싶은 데이터는 totalDistance와 totalTime 이 두가지 입니다
혹시 제가 딕셔너리 구조를 잘못 파악하고 있나 싶어서 일단 데이터 프레임으로 바꿔서 엑셀로 저장 해봤습니다
그랬더니
type는
FeatureCollection
feautres에는 {'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [14395473.264624588, 4237025.082804387]}, 'properties': {'totalDistance': 6606, 'totalTime': 879, 'totalFare': 0, 'taxiFare': 7400, 'index': 0, 'pointIndex': 0, 'name': '', 'description': '돋질로92번길 을 따라 방면으로 30m 이동', 'nextRoadName': '돋질로92번길', 'turnType': 200, 'pointType': 'S'}}
이렇게 나오고요
저는 이렇게 입력하면 나올줄 알았는데 잘못 알았나보네요
a['FeatureCollection']['totalDistance']
어떻게 하면 저 값을 꺼낼수 있을까요?
이하 코드입니다
import requests
import logging
logging.basicConfig(format='[%(levelname)s] %(asctime)s - %(message)s', level=logging.INFO, datefmt="%H:%M:%S")
version = 1
callback = "result"
apiUrl = f"https://apis.openapi.sk.com/tmap/routes?version={version}&callback={callback}"
headers = {
"appKey": "l7xx42dd522c3fb34dffbabb3248549f667c",
"Accept": "application/json",
"Content-Type": "application/json; charset=UTF-8"
}
json = {
"startX" : "129.3165257",
"startY" : "35.536378",
"endX" : "129.3268071",
"endY" : "35.5265278",
"reqCoordType" : "WGS84GEO",
"resCoordType" : "EPSG3857"
# "searchOption" : searchOption,
# "trafficInfo" : trafficInfochk
}
req = requests.post(apiUrl, headers=headers, json=json)
logging.info(req.json())
----------------이하 결과로 나온 부분입니다--
{'type': 'FeatureCollection',
'features': [{'type': 'Feature',
'geometry': {'type': 'Point',
'coordinates': [14395473.264624588, 4237025.082804387]},
'properties': {'totalDistance': 6606,
'totalTime': 879,
'totalFare': 0,
'taxiFare': 7400,
'index': 0,
'pointIndex': 0,
'name': '',
'description': '돋질로92번길 을 따라 방면으로 30m 이동',
'nextRoadName': '돋질로92번길',
'turnType': 200,
'pointType': 'S'}},
{'type': 'Feature',
'geometry': {'type': 'LineString',
'coordinates': [[14395473.264624588, 4237025.082804387],
[14395464.606579054, 4237052.059376161],
[14395461.205255333, 4237060.418310736]]},
'properties': {'index': 1,
'lineIndex': 0,
'name': '돋질로92번길',
'description': '돋질로92번길, 30m',
'distance': 30,
'time': 3,
'roadType': 9,
'facilityType': 0}},
{'type': 'Feature',
'geometry': {'type': 'Point',
'coordinates': [14395461.205255333, 4237060.418310736]},
'properties': {'index': 2,
'pointIndex': 1,
'name': '',
'description': '좌회전 후 중앙로166번길 을 따라 53m 이동 ',
'nextRoadName': '중앙로166번길',
'turnType': 12,
'pointType': 'N'}},
{'type': 'Feature',
'geometry': {'type': 'LineString',
'coordinates': [[14395461.205255333, 4237060.418310736],
[14395453.166250477, 4237058.89830381],
[14395398.748562334, 4237040.27925476]]},
'properties': {'index': 3,
'lineIndex': 1,
'name': '중앙로166번길',
'description': '중앙로166번길, 53m',
'distance': 53,
'time': 6,
'roadType': 9,
'facilityType': 0}},
{'type': 'Feature',
'geometry': {'type': 'Point',
'coordinates': [14395398.748562334, 4237040.27925476]},
'properties': {'index': 4,
'pointIndex': 2,
'name': '교차로',
'description': '교차로 에서 좌회전 후 삼산로83번길 을 따라 209m 이동 ',
'nextRoadName': '삼산로83번길',
'turnType': 12,
'pointType': 'N'}},
{'type': 'Feature',
'geometry': {'type': 'LineString',
'coordinates': [[14395398.748562334, 4237040.27925476],
[14395437.091357697, 4236919.835195978],
[14395448.223136708, 4236884.880070007],
[14395477.598640455, 4236793.693316644]]},
'properties': {'index': 5,
'lineIndex': 2,
'name': '삼산로83번길',
'description': '삼산로83번길, 209m',
'distance': 209,
'time': 40,
'roadType': 9,
'facilityType': 0}},
{'type': 'Feature',
'geometry': {'type': 'Point',
'coordinates': [14395477.598640455, 4236793.693316644]},
'properties': {'index': 6,
'pointIndex': 3,
'name': '교차로',
'description': '교차로 에서 우회전 후 삼산로 을 따라 815m 이동 ',
'nextRoadName': '삼산로',
'turnType': 13,
'pointType': 'N'}},
{'type': 'Feature',
'geometry': {'type': 'LineString',
'coordinates': [[14395477.598640455, 4236793.693316644],
[14395413.28680168, 4236772.794816569],
[14395353.303633066, 4236753.796179618],
[14395286.51824362, 4236732.897698416],
[14395245.395759616, 4236719.978661003],
[14395231.482141534, 4236715.41901825],
[14395229.008608269, 4236714.659074401],
[14395219.423669042, 4236711.619306683],
[14395189.741287278, 4236701.740101366],
[14395144.599326955, 4236686.92129579],
[14395026.488161443, 4236648.544454289],
[14394926.619275471, 4236617.007085555],
[14394906.212630393, 4236610.547636804],
[14394889.825470341, 4236605.608042836],
[14394844.374307489, 4236591.16929909],
[14394782.226808157, 4236571.031111759],
[14394723.789600018, 4236552.412797882],
[14394669.371885607, 4236534.934419755],
[14394666.898352344, 4236534.174488417],
[14394658.859364886, 4236531.894680429],
[14394608.151950372, 4236515.556229984],
[14394549.714759646, 4236496.178138775],
[14394508.592293061, 4236482.49950972],
[14394501.790080935, 4236480.219741061]]},
'properties': {'index': 7,
'lineIndex': 3,
'name': '삼산로',
'description': '삼산로, 815m',
'distance': 815,
'time': 125,
'roadType': 5,
'facilityType': 0}},
{'type': 'Feature',
'geometry': {'type': 'Point',
'coordinates': [14394501.790080935, 4236480.219741061]},
'properties': {'index': 8,
'pointIndex': 4,
'name': '공업탑 로터리',
'description': '공업탑 로터리 에서 법원,검찰청 방면으로 1시 방향 후 31번국도 을 따라 113m 이동 ',
'nextRoadName': '31번국도',
'turnType': 131,
'pointType': 'N'}},
{'type': 'Feature',
'geometry': {'type': 'LineString',
'coordinates': [[14394501.790080935, 4236480.219741061],
[14394497.46121933, 4236486.678541394],
[14394492.823216109, 4236490.857724713],
[14394486.948437545, 4236495.036881042],
[14394479.21849599, 4236499.215996089],
[14394469.942611368, 4236502.255269043],
[14394460.357559023, 4236504.154727537],
[14394449.844942579, 4236505.294292752],
[14394441.496726483, 4236504.534227713],
[14394430.984170957, 4236503.014240697],
[14394424.181950135, 4236501.114403701],
[14394417.379746715, 4236498.454695339],
[14394411.81433603, 4236495.035144743],
[14394405.630563786, 4236490.475774187],
[14394400.99276941, 4236485.536505855],
[14394396.66417757, 4236480.21731168],
[14394394.19075743, 4236474.518227942],
[14394391.717345992, 4236468.439212362],
[14394389.862339625, 4236461.600345293]]},
'properties': {'index': 9,
'lineIndex': 4,
'name': '31번국도',
'description': '31번국도, 113m',
'distance': 113,
'time': 36,
'roadType': 2,
'facilityType': 0}},
{'type': 'Feature',
'geometry': {'type': 'LineString',
'coordinates': [[14394389.862339625, 4236461.600345293],
[14394381.514062613, 4236463.499825338],
[14394346.884196654, 4236470.337850479],
[14394322.148568176, 4236475.656368237],
[14394256.599118793, 4236491.232201459],
[14394174.662335401, 4236509.46723133],
[14394108.185313316, 4236524.66315441],
[14394054.076148985, 4236535.300138061],
[14394023.156617818, 4236541.758356397],
[14394002.131332804, 4236546.317119535],
[14393846.296875712, 4236579.748069046],
[14393803.937129322, 4236588.105743777],
[14393761.886576777, 4236596.463432026],
[14393722.618777437, 4236604.441251433],
[14393589.974032097, 4236630.274103445],
[14393582.553345341, 4236631.793693696],
[14393556.27175658, 4236636.732313463],
[14393495.669487262, 4236648.889019966],
[14393411.877611054, 4236664.084736344],
[14393405.384514507, 4236665.2244111],
[14393346.32821443, 4236677.381184935],
[14393329.01328161, 4236680.80026371],
[14393247.694947474, 4236696.37602418],
[14393204.71681365, 4236704.733773595],
[14393164.212239187, 4236712.711643271],
[14393145.660531076, 4236716.130704504],
[14393117.832947168, 4236722.209157257],
[14393051.046757992, 4236736.265535921],
[14393045.481242958, 4236737.405239614],
[14393039.91572792, 4236738.544943427],
[14392939.427219974, 4236760.959349613],
[14392729.174554743, 4236798.569104663],
[14392674.1377922, 4236809.966226029],
[14392596.838969624, 4236825.922210142],
[14392533.14473645, 4236839.218897983],
[14392530.052789459, 4236839.598774204],
[14392426.163210751, 4236859.353669938],
[14392423.071263766, 4236859.733546859],
[14392259.816191828, 4236891.645483335],
[14392107.69214141, 4236921.658017245],
[14391974.119799118, 4236948.251498626],
[14391948.76578352, 4236953.570234063],
[14391883.8347928, 4236966.107144188],
[14391792.312985167, 4236985.102648268],
[14391553.614385692, 4237027.271964871],
[14391522.694811752, 4237035.630245162],
[14391468.894668614, 4237053.866830589],
[14391397.47010354, 4237088.441146203],
[14391383.865427382, 4237094.900090322],
[14391222.464511415, 4237170.887922592],
[14391187.216119694, 4237183.805726095],
[14391141.764244815, 4237200.522909925],
[14391133.106748153, 4237203.562391548],
[14391113.627398051, 4237209.641307347],
[14391044.985855913, 4237232.05741209],
[14391026.12489348, 4237238.136357959],
[14390985.929444112, 4237249.154317188],
[14390938.622588951, 4237257.892350351],
[14390927.491576483, 4237259.411941968],
[14390897.499714626, 4237262.070985116],
[14390888.223891193, 4237262.450733248],
[14390863.179147927, 4237264.349966633],
[14390829.167783758, 4237266.248993354],
[14390811.23451585, 4237267.388466651],
[14390803.813846676, 4237268.148220269],
[14390714.765842684, 4237276.12537951],
[14390447.312732864, 4237295.877286651],
[14390388.875074109, 4237297.015828151],
[14390349.607449818, 4237297.394885268],
[14390346.824705407, 4237297.394821038],
[14390088.647454442, 4237315.247160586]]},
'properties': {'index': 10,
'lineIndex': 5,
'name': '문수로',
'description': '문수로, 3499m',
'distance': 3499,
'time': 406,
'roadType': 5,
'facilityType': 0}},
{'type': 'Feature',
'geometry': {'type': 'Point',
'coordinates': [14390088.647454442, 4237315.247160586]},
'properties': {'index': 11,
'pointIndex': 5,
'name': '옥현 사거리',
'description': '옥현 사거리 에서 울산IC 방면으로 우회전 후 남부순환도로 을 따라 899m 이동 ',
'nextRoadName': '남부순환도로',
'turnType': 13,
'pointType': 'N'}},
{'type': 'Feature',
'geometry': {'type': 'LineString',
'coordinates': [[14390088.647454442, 4237315.247160586],
[14390008.87461376, 4237351.721934183],
[14389985.066333063, 4237367.299975848],
[14389955.383117698, 4237393.896936523],
[14389927.245619413, 4237431.513067581],
[14389894.4697097, 4237491.167469754],
[14389890.7591144, 4237502.94646651],
[14389864.785625229, 4237555.76190807],
[14389840.358409375, 4237595.27854842],
[14389807.892093318, 4237637.454972036],
[14389783.156074783, 4237659.872964441],
[14389741.72340737, 4237690.270133278],
[14389689.777576415, 4237745.745729722],
[14389676.172691924, 4237761.324566225],
[14389664.113759166, 4237777.663420725],
[14389653.291575613, 4237795.142270198],
[14389643.087692788, 4237816.420975704],
[14389635.666641265, 4237833.899965405],
[14389622.679570774, 4237874.557821731],
[14389619.278021535, 4237892.796964982],
[14389616.494773023, 4237914.836000817],
[14389614.019796968, 4237977.153638603],
[14389616.183510493, 4238005.272764314],
[14389628.239209682, 4238130.289805849],
[14389628.54833396, 4238133.32975202],
[14389629.166599903, 4238138.649661626],
[14389629.784796303, 4238147.009516636],
[14389636.276936403, 4238187.668982718],
[14389639.677016579, 4238233.648469496],
[14389639.986132162, 4238237.068440319]]},
'properties': {'index': 12,
'lineIndex': 6,
'name': '남부순환도로',
'description': '남부순환도로, 899m',
'distance': 899,
'time': 98,
'roadType': 6,
'facilityType': 1}},
{'type': 'Feature',
'geometry': {'type': 'Point',
'coordinates': [14389639.986132162, 4238237.068440319]},
'properties': {'index': 13,
'pointIndex': 6,
'name': '신복 고가차도',
'description': '신복 고가차도 에서 고가도로옆 후 남부순환도로 을 따라 464m 이동 ',
'nextRoadName': '남부순환도로',
'turnType': 124,
'pointType': 'N'}},
{'type': 'Feature',
'geometry': {'type': 'LineString',
'coordinates': [[14389639.986132162, 4238237.068440319],
[14389638.129647894, 4238294.827945217],
[14389635.345973339, 4238335.487744954],
[14389627.304230368, 4238453.668019423],
[14389624.520616623, 4238491.66837356],
[14389620.809125822, 4238542.58905487],
[14389605.964031868, 4238708.272843174],
[14389599.468909774, 4238797.95597296],
[14389598.850348245, 4238805.556270319],
[14389598.850304773, 4238807.456349052]]},
'properties': {'index': 14,
'lineIndex': 7,
'name': '남부순환도로',
'description': '남부순환도로, 464m',
'distance': 464,
'time': 47,
'roadType': 6,
'facilityType': 1}},
{'type': 'Feature',
'geometry': {'type': 'Point',
'coordinates': [14389598.850304773, 4238807.456349052]},
'properties': {'index': 15,
'pointIndex': 7,
'name': '신복 로터리',
'description': '신복 로터리 에서 9시 방향 후 남부순환도로 을 따라 213m 이동 ',
'nextRoadName': '남부순환도로',
'turnType': 139,
'pointType': 'N'}},
{'type': 'Feature',
'geometry': {'type': 'LineString',
'coordinates': [[14389598.850304773, 4238807.456349052],
[14389600.395743487, 4238830.637371758],
[14389609.052753048, 4238848.878382717],
[14389613.999775892, 4238852.298652381],
[14389620.801892083, 4238858.759105966],
[14389628.531424522, 4238872.439924966],
[14389632.550544193, 4238889.920861065],
[14389631.622632327, 4238904.361557306],
[14389623.583306111, 4238916.902010364],
[14389612.761296405, 4238926.782273804],
[14389599.77496475, 4238935.142415266],
[14389580.295684649, 4238938.182127612],
[14389576.585384917, 4238937.041981095],
[14389559.579829263, 4238932.481346249],
[14389550.613321576, 4238927.540878937],
[14389541.95609465, 4238918.800223975],
[14389536.081646873, 4238908.539562993],
[14389532.68076702, 4238897.518930883],
[14389531.444296062, 4238884.218248946],
[14389533.91813353, 4238871.677704765]]},
'properties': {'index': 16,
'lineIndex': 8,
'name': '남부순환도로',
'description': '남부순환도로, 213m',
'distance': 213,
'time': 80,
'roadType': 6,
'facilityType': 5}},
{'type': 'Feature',
'geometry': {'type': 'LineString',
'coordinates': [[14389533.91813353, 4238871.677704765],
[14389510.728744982, 4238865.216865285],
[14389496.815023165, 4238865.216544094],
[14389462.803233676, 4238885.736738252],
[14389448.889216257, 4238898.657053342],
[14389406.528880712, 4238932.857833216],
[14389329.538159458, 4238996.699622301],
[14389288.723810453, 4239030.140696495],
[14389252.238227079, 4239061.30182488]]},
'properties': {'index': 17,
'lineIndex': 9,
'name': '대학로169번길',
'description': '대학로169번길, 282m',
'distance': 282,
'time': 34,
'roadType': 7,
'facilityType': 5}},
{'type': 'Feature',
'geometry': {'type': 'Point',
'coordinates': [14389252.238227079, 4239061.30182488]},
'properties': {'index': 18,
'pointIndex': 8,
'name': '교차로',
'description': '교차로 에서 좌회전 후 일반도로 을 따라 29m 이동 ',
'nextRoadName': '일반도로',
'turnType': 12,
'pointType': 'N'}},
{'type': 'Feature',
'geometry': {'type': 'LineString',
'coordinates': [[14389252.238227079, 4239061.30182488],
[14389229.049316788, 4239033.939554571]]},
'properties': {'index': 19,
'lineIndex': 10,
'name': '일반도로',
'description': '일반도로, 29m',
'distance': 29,
'time': 4,
'roadType': 9,
'facilityType': 0}},
{'type': 'Feature',
'geometry': {'type': 'Point',
'coordinates': [14389229.049316788, 4239033.939554571]},
'properties': {'index': 20,
'pointIndex': 9,
'name': '',
'description': '도착',
'nextRoadName': '',
'turnType': 201,
'pointType': 'E'}}]}