stevekrouse
mayor of val town
Public vals
779
stevekrouse
blogRSS
HTTP
Val Town Blog RSS Feed View live at: https://stevekrouse-blogRSS.web.val.run This val returns an RSS feed of the Val Town Blog . Architecture Fetch and parse the HTML of https://blog.val.town – @stevekrouse.valTownBlogJSON. Create an RSS string out of that array of blog objects – @stevekrouse.valTownBlogRSS. Expose an endpoint that returns that RSS , with appropriate content-type and cache headers – this val, @stevekrouse.blogRSS Notes This is very inefficient. It refetches and re-parses blog.val.town on every single request, modulo some caching via the headers. It would be much more efficient to cache the results of fetching and parsing the Val Town blog, and then only re-fetch it every 10 minutes or so. Instead of fetching and parsing HTML from super.so, we could get this same data from Notion's API, with a val like @stevekrouse.notionGetDatabase.
0
stevekrouse
getDayName
Script
Get the day of week name JavaScript's Date.prototype.getDay() returns a number that represents the day of the week, 0 for Sunday, 1 for Monday, etc. This function returns the name of the week, ie "Sunday" , "Monday" , etc. The function optionally inputs a Date object, but will default to the current time if none is provided.
0
stevekrouse
alive
Script
Human Alive-ness API It works by querying Wikidata via SPARQL to search for birth and death dates of a person. Requires an exact name match. It will throw if it can't find results. It will return true if every match has a birth date and not a death date. (It will return false if a match does not have a birth date, because we assume that to mean they are a historical figure whose birthdate we don't know.) @stevekrouse.alive("Henry Kissinger") // true (for now) You can view some example usages / tests here: https://www.val.town/v/stevekrouse.aliveTests
0
stevekrouse
wikidata
Script
Query Wikidata via SPARQL Usage // get the death date for a person
@stevekrouse.wikidata(`SELECT ?person ?personLabel ?death_date WHERE {
?person rdfs:label "Henry Kissinger"@en;
wdt:P31 wd:Q5 . # Ensure the entity is a human
OPTIONAL {
?person wdt:P570 ?death_date . # Try to find a date of death
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}`) Learn more https://agg-shashank.medium.com/an-introduction-to-using-wikidata-apis-a678ee6d2968
0