Skip to content

Instantly share code, notes, and snippets.

@Lwdthe1
Last active October 16, 2022 17:36
Show Gist options
  • Save Lwdthe1/881998931a2822bf97bbdbbb978b1513 to your computer and use it in GitHub Desktop.
Save Lwdthe1/881998931a2822bf97bbdbbb978b1513 to your computer and use it in GitHub Desktop.
36 Largest European Cities By Population With Geographic Coordinates, in JSON Raw
//data from https://en.wikipedia.org/wiki/List_of_European_cities_by_population_within_city_limits
//The script
function runIt() {
var table = document.getElementsByClassName('wikitable sortable jquery-tablesorter')[0]
var cities = []
for (var i = 0, row; row = table.rows[i]; i++) {
if(i == 0) continue
//iterate through rows
//rows would be accessed using the "row" variable assigned in the for loop
var city = {}
for (var j = 0, col; col = row.cells[j]; j++) {
//iterate through columns
//columns would be accessed using the "col" variable assigned in the for loop
col = col.innerText
if(j == 0) city.rank = col
else if(j == 1) city.city = col
else if(j == 2) city.country = col
else if(j == 3) city.population = col
else if(j == 4) city.date = col
else if(j == 5) continue
else if(j == 6) continue
else if(j == 7) {
var c = col.split(" ")
city.latitude = c[0].split("°")[0]
city.longitude = c[1].split("°")[0]
}
}
cities.push(city)
}
var s = ""
cities.map((city) => {
s += JSON.stringify(city) + ",\n"
})
console.log(s)
}
runIt()
//the data
[{"rank":"1","city":"Istanbul[a]","country":" Turkey","population":"14,804,116","date":"31 December 2016","latitude":"41.013611","longitude":"28.955"},
{"rank":"2","city":"Moscow[b]","country":" Russia","population":"12,330,126","date":"1 January 2016","latitude":"55.75","longitude":"37.616667"},
{"rank":"3","city":"London","country":" United Kingdom","population":"8,673,713","date":"30 June 2015","latitude":"51.507222","longitude":"0.1275"},
{"rank":"4","city":"Saint Petersburg","country":" Russia","population":"5,225,690","date":"1 January 2016","latitude":"59.95","longitude":"30.3"},
{"rank":"5","city":"Berlin","country":" Germany","population":"3,562,166","date":"31 December 2014","latitude":"52.516667","longitude":"13.383333"},
{"rank":"6","city":"Madrid","country":" Spain","population":"3,165,235","date":"1 January 2014","latitude":"40.383333","longitude":"3.716667"},
{"rank":"7","city":"Kiev","country":" Ukraine","population":"2,909,491","date":"1 June 2016","latitude":"50.45","longitude":"30.523333"},
{"rank":"8","city":"Rome","country":" Italy","population":"2,874,038","date":"30 November 2014","latitude":"41.9","longitude":"12.5"},
{"rank":"9","city":"Paris","country":" France","population":"2,241,346","date":"1 January 2014","latitude":"48.8567","longitude":"2.3508"},
{"rank":"10","city":"Bucharest","country":" Romania","population":"2,106,144","date":"1 January 2016","latitude":"44.4325","longitude":"26.103889"},
{"rank":"11","city":"Minsk","country":" Belarus","population":"1,949,400","date":"1 October 2015","latitude":"53.9","longitude":"27.566667"},
{"rank":"12","city":"Vienna","country":" Austria","population":"1,840,573","date":"1 January 2016","latitude":"48.2","longitude":"16.366667"},
{"rank":"13","city":"Hamburg","country":" Germany","population":"1,758,041","date":"31 October 2014","latitude":"53.565278","longitude":"10.001389"},
{"rank":"14","city":"Budapest","country":" Hungary","population":"1,759,407","date":"1 January 2015","latitude":"47.4925","longitude":"19.051389"},
{"rank":"15","city":"Warsaw","country":" Poland","population":"1,748,916","date":"30 June 2016","latitude":"52.233333","longitude":"21.016667"},
{"rank":"16","city":"Barcelona","country":" Spain","population":"1,602,386","date":"1 January 2014","latitude":"41.383333","longitude":"2.183333"},
{"rank":"17","city":"Munich","country":" Germany","population":"1,521,678","date":"31 December 2015","latitude":"48.133333","longitude":"11.566667"},
{"rank":"18","city":"Kharkiv","country":" Ukraine","population":"1,431,565","date":"1 January 2014","latitude":"50.004444","longitude":"36.231389"},
{"rank":"19","city":"Milan","country":" Italy","population":"1,350,973","date":"30 November 2016","latitude":"45.466667","longitude":"9.183333"},
{"rank":"20","city":"Prague","country":" Czech Republic","population":"1,280,208","date":"31 December 2016","latitude":"50.083333","longitude":"14.416667"},
{"rank":"21","city":"Nizhny Novgorod","country":" Russia","population":"1,260,000","date":"1 January 2013","latitude":"56.326944","longitude":"44.0075"},
{"rank":"22","city":"Sofia","country":" Bulgaria","population":"1,260,120","date":"31 December 2014","latitude":"42.7","longitude":"23.33"},
{"rank":"23","city":"Kazan","country":" Russia","population":"1,216,965","date":"1 January 2016","latitude":"55.790278","longitude":"49.134722"},
{"rank":"24","city":"Brussels","country":" Belgium","population":"1,171,828","date":"1 January 2015","latitude":"50.85","longitude":"4.35"},
{"rank":"25","city":"Samara","country":" Russia","population":"1,170,910","date":"1 January 2016","latitude":"53.202778","longitude":"50.140833"},
{"rank":"26","city":"Belgrade","country":" Serbia","population":"1,166,763","date":"30 September 2011","latitude":"44.816667","longitude":"20.466667"},
{"rank":"27","city":"Rostov-on-Don","country":" Russia","population":"1,119,875","date":"1 January 2016","latitude":"47.233333","longitude":"39.7"},
{"rank":"28","city":"Birmingham","country":" United Kingdom","population":"1,092,330","date":"30 June 2013","latitude":"52.483056","longitude":"1.893611"},
{"rank":"29","city":"Ufa","country":" Russia","population":"1,121,429","date":"1 January 2016","latitude":"54.75","longitude":"55.966667"},
{"rank":"30","city":"Cologne","country":" Germany","population":"1,039,488","date":"30 June 2014","latitude":"50.936389","longitude":"6.952778"},
{"rank":"31","city":"Perm","country":" Russia","population":"1,041,876","date":"1 January 2016","latitude":"58","longitude":"56.316667"},
{"rank":"32","city":"Voronezh","country":" Russia","population":"1,032,382","date":"1 January 2016","latitude":"51.671667","longitude":"39.210556"},
{"rank":"33","city":"Volgograd","country":" Russia","population":"1,016,137","date":"1 January 2016","latitude":"48.7","longitude":"44.516667"},
{"rank":"34","city":"Odessa","country":" Ukraine","population":"999,359","date":"1 January 2014","latitude":"46.466667","longitude":"30.733333"},
{"rank":"35","city":"Naples","country":" Italy","population":"989,111","date":"1 January 2014","latitude":"40.833333","longitude":"14.25"},
{"rank":"36","city":"Dnipropetrovsk","country":" Ukraine","population":"982,969","date":"1 January 2014","latitude":"48.45","longitude":"34.983333"}]
@Lwdthe1
Copy link
Author

Lwdthe1 commented Apr 6, 2017

Here's a similar gist for 1000 US cities: https://gist.github.com/Miserlou/c5cd8364bf9b2420bb29

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment