Skip to content

Instantly share code, notes, and snippets.

@rizsotto
Last active December 19, 2015 05:38
Show Gist options
  • Save rizsotto/5905179 to your computer and use it in GitHub Desktop.
Save rizsotto/5905179 to your computer and use it in GitHub Desktop.
Hungarian national tobacco shops addresses parser
<!DOCTYPE html>
<html dir="ltr" lang="hu-HU">
<head/>
<meta charset="UTF-8"/>
</head>
<body>
<pre id='goods'></pre>
<script type="text/javascript">
function parse_raw_data(data) {
function parse_address(node) {
var nodes = node.childNodes;
if (nodes.length < 3) { console.log('parse address failed'); return 0; }
var firsts = nodes[0].nodeValue.match(/[^\s,]+/g);
var seconds = nodes[2].nodeValue.trim();
return {country: "HUN", city: firsts[1], postalCode: firsts[0], details: seconds};
}
var queue = [];
for (var idx in data) {
var d = data[idx];
var div = document.createElement('div');
div.innerHTML = d.data.html;
var heads = div.getElementsByTagName('h3');
var result = {geo: d.latLng, address: parse_address(heads[0])};
queue.push(result);
}
return queue;
}
function full_list_callback(data) {
var queue = parse_raw_data(data);
var x = document.createTextNode(JSON.stringify(queue, null, 4));
document.getElementById('goods').appendChild(x);
}
</script>
<script type="text/javascript" src="http://trafikok.nemzetidohany.hu/mind.jsonp"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment