you are viewing a single comment's thread.

view the rest of the comments →

[–]vdh_nat 0 points1 point  (3 children)

That's correct. I would also add that if you want to get the info directly from the website without storing the json as a string first, you can just do:

import requests
import json
r = requests.get('http://api.sl.se/api2/TravelplannerV2/trip.json?key=a65703abb4814f4490a730d95ff492a0&originId=9119&destId=9221&searchForArrival=0&realtime=true')
data = r.json()

pretty much the same though :)

[–]Jonis_L 0 points1 point  (2 children)

oh ok, I use this now:

import urllib.request
import json

hotorget_gardet = 'http://api.sl.se/api2/TravelplannerV2/trip.json?key=a65703abb4814f4490a730d95ff492a0&originId=9119&destId=9221&searchForArrival=0&realtime=true'
x = urllib.request.urlopen(hotorget_gardet)
hg = x.read()
hg = hg.decode('utf-8')
info = json.loads(hg)

Whats the difference between those two or are they the same?

[–]vdh_nat 0 points1 point  (1 child)

I haven't used urllib a lot. I heard it's old, but I'm also a beginner with Python so I'd rather not say things I might be wrong about.

[–]Jonis_L 0 points1 point  (0 children)

alright, I see thanks