Skip to content

Instantly share code, notes, and snippets.

@vladbatushkov
Last active May 14, 2019 13:17
Show Gist options
  • Save vladbatushkov/e80b4bae9c42beff3fef5205a57e16a5 to your computer and use it in GitHub Desktop.
Save vladbatushkov/e80b4bae9c42beff3fef5205a57e16a5 to your computer and use it in GitHub Desktop.
All winners of Formula 1.
UNWIND range(1950, 2018) as year
WITH "https://www.formula1.com/en/results.html/" + year + "/races.html" as url, year
CALL apoc.load.html(url, { place: "table.resultsarchive-table tbody tr td:eq(1)", pilot: "table.resultsarchive-table tbody tr td:eq(3)" }) YIELD value
WITH collect(value) as data, year
WITH { pilots: data[0].pilot, places: data[1].place } as root, year
WITH [ x IN range(0, length(root.pilots) - 1) | { pilot: root.pilots[x].text, place: root.places[x].text }] as result, year
UNWIND result as item
MERGE (y:Year { value: year })
MERGE (p:Pilot { name: item.pilot })
MERGE (c:Country { name: item.place })
MERGE (y)<-[:IN]-(w:Winner { pilot: item.pilot, year: year, country: item.place })-[:AT]->(c)
MERGE (p)-[:IS]->(w)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment