-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Profile debug script which fetches a way from OSM #5908
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
-- | ||
-- Fetch a way from the OpenStreetMap API and run the given profile over it. | ||
-- | ||
-- You'll need to install luasec and xml2lua first: | ||
-- > luarocks-5.1 install xml2lua | ||
-- > luarocks-5.1 install luasec | ||
-- [may require admin privileges] | ||
-- | ||
-- Then to test way 2606296 using the foot profile: | ||
-- > lua5.1 debug_way.lua foot 2606296 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My system (Ubuntu) currently does not have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess it applies not only for ubuntu, so indeed, this needs to be just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No problem, changed (blame Homebrew for this one ;) ). |
||
-- | ||
|
||
-- initialise libraries | ||
local pprint = require('lib/pprint') | ||
local Debug = require('lib/profile_debugger') | ||
local xml2lua = require('xml2lua') | ||
local handler = require('xmlhandler.tree') | ||
local https = require('ssl.https') | ||
|
||
-- load the profile | ||
Debug.load_profile(arg[1]) | ||
|
||
-- load way from the OSM API | ||
local url = 'https://www.openstreetmap.org/api/0.6/way/'..arg[2] | ||
local body, statusCode, headers, statusText = https.request(url) | ||
|
||
-- parse way tags | ||
local parser = xml2lua.parser(handler) | ||
parser:parse(body) | ||
|
||
-- convert XML-flavoured table to a simple k/v table | ||
local way = {} | ||
for i, p in pairs(handler.root.osm.way.tag) do | ||
way[p._attr.k] = p._attr.v | ||
end | ||
|
||
-- call the way function | ||
local result = {} | ||
Debug.process_way(way,result) | ||
|
||
-- print input and output | ||
pprint(way) | ||
print("=>") | ||
pprint(result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like
luasec
isn't really required? I got an error all right prior to installingxml2lua
but nothing related to not having runluarocks install luasec
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've rephrased the comment to note that you may have this already (my Ubuntu box and Mac didn't).