Skip to content

Instantly share code, notes, and snippets.

@crssnky
Last active May 8, 2019 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crssnky/71305395f4bba9d5e7f1169dc12f343d to your computer and use it in GitHub Desktop.
Save crssnky/71305395f4bba9d5e7f1169dc12f343d to your computer and use it in GitHub Desktop.
const URL = "https://sparql.crssnky.xyz/spql/imas/query?query=";
const Query = ['PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>PREFIX schema: <http://schema.org/>PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>SELECT (sample(?o) as ?date) (sample(?n) as ?name)WHERE {?sub schema:birthDate ?o;rdfs:label ?n;bind("', '"^^xsd:gMonthDay as ?3ago)bind("', '"^^xsd:gMonthDay as ?3later)FILTER(?o>=?3ago && ?o<=?3later).}group by(?sub) order by(?o)'];
const date = new Date();
var strings = [];
date.setDate(date.getDate() - 3)
for (var i = 0; i < 7; i++) {
const month = date.getMonth() + 1;
const day = date.getDate();
strings.push("--" + (month < 10 ? "0" + month : month) + "-" + (day < 10 ? "0" + day : day));
document.getElementById(i).innerHTML = "<h3>" + month + "月" + day + "日</h3>"
date.setDate(date.getDate() + 1);
}
const request = new XMLHttpRequest();
request.addEventListener("load", (e) => {
if (e.target.status != 200) {
console.log(event.target.status + ':' + event.target.statusText);
return;
}
const json = JSON.parse(e.target.responseText)["results"]["bindings"];
json.forEach(i => {
const current = i["date"]["value"];
strings.forEach(function (j, index) {
if (current === j) {
const div = document.getElementById(index.toString());
div.innerHTML += i["name"]["value"] + "<br>";
}
});
});
});
request.addEventListener("error", () => {
console.log("Http Request Error");
});
request.open("GET", URL + encodeURIComponent(Query[0] + strings[0] + Query[1] + strings[strings.length - 1] + Query[2]));
request.send();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment