0

Hi I am working on a project that needs traffic data I am trying to use APIs like tomtom or HERE but i can't get it to work

All I want is to collect the traffic count (number of cars in each route) and stock it in pandas df

I tried this but it didn't give me traffic count

response = requests.get('https://api.tomtom.com/traffic/services/4/incidentDetails/s3/-35.871247%2C140.910645%2C-28.902397%2C153.566895/22/-1/json?key='+apiKey+'&projection=EPSG4326&originalPosition=true')
dict = json.loads(response.content)
print(dict)
keys = dict.keys() 
values = dict.values()

I can use any other api instead of tomtom if it can provide data too

Life is complex
  • 15,374
  • 5
  • 29
  • 58
shi ft
  • 19
  • 1

2 Answers2

0

Try this here code:

from json import dumps as to_json_func_from_the_json_module

from requests import get

key = 'tada!'
response = get(f'https://api.tomtom.com/traffic/services/4/incidentDetails/s3/-35.871247%2C140.910645%2C-28.902397%2C153.566895/22/-1/json?{key=!s}&projection=EPSG4326&originalPosition=true')
dct = response.json()

print(to_json_func_from_the_json_module(dct, indent=2, default=str))
print('N. (#) Keys:', len(dct))

It should work. Let me know if not.

rv.kvetch
  • 9,940
  • 3
  • 24
  • 53
  • the apikey is key that is provided by tomtom after sing in up it is used to connect to tomtom api the code does not give any errors it just dosen't provide traffic count here is the output {'@id': '1682942440', 'poi': [{'id': '0aab15fcf8096e2691de5f01aa5b06f8', 'p': {'x': 140.8933447, 'y': -34.2666487}, 'op': {'x': 140.8933443, 'y': -34.2666511}, 'ic': 9, 'ty': 0, 'cs': 0, 'd': 'roadworks', 'sd': '2023-04-19T08:23:00Z', 'f': 'Loxton Main Road (Sturt Highway)', 't': 'West Settlement Road (Sturt Highway)', 'l': 3788, 'r': 'A20'}, – shi ft May 01 '23 at 14:57
0

Those services do not return number of cars.

szogoon
  • 470
  • 3
  • 15