Skip to content
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

Updated to enhance version of opening_hours.js #4

Merged
merged 3 commits into from
Mar 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ This project uses node.js as a server-side runtime environment.
To run the project you need to install [nodejs](http://nodejs.org/)
and [npm](https://npmjs.org/).

$ git clone https://github.com/cmichi/ulm-opening-hours.git
$ git clone --recursive https://github.com/cmichi/ulm-opening-hours.git
$ cd ulm-opening-hours/

# install the necessary dependencies from the package.json
Expand Down Expand Up @@ -70,7 +70,7 @@ Then open [http://localhost:3046/](http://localhost:3046).

# Libraries & Icons

* [opening_hours.js](https://github.com/AMDmi3/opening_hours.js/)
* [opening_hours.js](https://github.com/ypid/opening_hours.js/)
* [suncalc](https://github.com/mourner/suncalc)
* [leaflet](https://github.com/Leaflet/Leaflet)
* express
Expand All @@ -80,7 +80,6 @@ Then open [http://localhost:3046/](http://localhost:3046).
* [Edit Icon](http://thenounproject.com/noun/edit/#icon-No5587) by Naomi Atkinson, from The Noun Project
* [GitHub Buttons](https://github.com/mdo/github-buttons)


# License

The database file `./data/data.xml` is exported from the Open Street Map
Expand Down
25 changes: 12 additions & 13 deletions data/parse_xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var xpath = require('xpath')

var xml = fs.readFileSync('./data/data.xml', 'utf-8');

var doc = new dom().parseFromString(xml)
var doc = new dom().parseFromString(xml)
var nodes = xpath.select("//node", doc);
var ways = xpath.select("//way", doc);
var relations = xpath.select("//relation", doc);
Expand Down Expand Up @@ -69,7 +69,7 @@ function parseWay(way_doc) {
/* problem: lat/lon is missing.
solution: search the first referenced node and get it */
var ref_nodes = xpath.select("//nd/@ref", way_doc);
if (ref_nodes == undefined || ref_nodes.length === 0)
if (ref_nodes == undefined || ref_nodes.length === 0)
return undefined;

var j = 0;
Expand All @@ -85,7 +85,7 @@ function parseWay(way_doc) {
var new_way = way_doc.toString();
new_way = new_way.replace("<way ", "<node " + 'lat="' + lat + '"' + ' lon="' + lon + '" ');
new_way = new_way.replace("</way>", "</node>");

var _new_doc = new dom().parseFromString(new_way);
var obj = getObj(_new_doc);

Expand All @@ -102,39 +102,39 @@ function parseWay(way_doc) {

function getObj(new_doc) {
var xml_opening_hours = xpath.select("//tag[@k='opening_hours']/@v", new_doc);
if (xml_opening_hours == undefined || xml_opening_hours.length === 0)
if (xml_opening_hours == undefined || xml_opening_hours.length === 0)
return undefined;

var xml_name = xpath.select("//tag[@k='name']/@v", new_doc);
if (xml_name == undefined || xml_name.length === 0)
if (xml_name == undefined || xml_name.length === 0)
xml_name = xpath.select("//node/@id", new_doc);

var xml_amenity = xpath.select("//tag[@k='amenity']/@v", new_doc);
if (xml_amenity == undefined || xml_amenity.length === 0)
if (xml_amenity == undefined || xml_amenity.length === 0)
xml_amenity = undefined;

var xml_shop = xpath.select("//tag[@k='shop']/@v", new_doc);
if (xml_shop == undefined || xml_shop.length === 0)
if (xml_shop == undefined || xml_shop.length === 0)
xml_shop = undefined;

var xml_tourism = xpath.select("//tag[@k='tourism']/@v", new_doc);
if (xml_tourism == undefined || xml_tourism.length === 0)
if (xml_tourism == undefined || xml_tourism.length === 0)
xml_tourism = undefined;

var xml_office = xpath.select("//tag[@k='office']/@v", new_doc);
if (xml_office == undefined || xml_office.length === 0)
if (xml_office == undefined || xml_office.length === 0)
xml_office = undefined;

var xml_craft = xpath.select("//tag[@k='craft']/@v", new_doc);
if (xml_craft == undefined || xml_craft.length === 0)
if (xml_craft == undefined || xml_craft.length === 0)
xml_craft = undefined;

var xml_leisure = xpath.select("//tag[@k='leisure']/@v", new_doc);
if (xml_leisure == undefined || xml_leisure.length === 0)
if (xml_leisure == undefined || xml_leisure.length === 0)
xml_leisure = undefined;

var xml_id = xpath.select("//node/@id", new_doc);
if (xml_id == undefined || xml_id.length === 0)
if (xml_id == undefined || xml_id.length === 0)
xml_id = undefined;

var xml_category = "other"; //xml_name[0].value;
Expand All @@ -156,4 +156,3 @@ function getObj(new_doc) {

return obj;
}

Loading