Public
Edited
Apr 18, 2023
Importers
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
urlsFromMain = {
let html = await getHtml(urlMain)
let $ = cheerio.load(html.data)
let el = $("h4 a")
let data = []
el.each((i,e) => {
let year = $(e).text()
let url = $(e).attr("href")
data.push({ year: year, url: url })
})
yield data
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
years = d3.range(1946, 2023 + 1)
Insert cell
urls = years.map(d => d == 1959 ? url1959.concat(d) : urlBase.concat(d))
Insert cell
Insert cell
resolutions = {
let data = []

// Pour chaque url (année)
for (const [i, u] of urls.entries()) {
let year = years[i]
let html = await getHtml(u)
let $ = cheerio.load(html.data)
let tr = $("tr")

// Pour chaque ligne
// /!\ si year >= 2014, 3 cellules (res, date, sujet) sinon 2 cellules (res, sujet)
tr.each((i, e) => {
let tds = $(e).find("td")
let res = $(tds[0]).text()
let date = year >= 2014 ? $(tds[1]).text() : NaN
let subject = year >= 2014 ? $(tds[2]).text() : $(tds[1]).text()
let row = { "year": year, "res": cleanup(res), "date": cleanup(date), "subject": cleanup(subject)}
if (tds.length > 0) data.push(row) // supprime les lignes à 1 cellule servant de titre à certaines années
})
}
yield data
}
Insert cell
Insert cell
Insert cell
Insert cell
DPPA-SCVETOES_april_2023.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
vetos_by_member = aq
.from(dppaScvetoes_april_2023)
.select({
year: "year",
number_of_vetoes: "vetos",
china: "china",
russian_federation_or_ussr: "russia_ussr",
france: "france",
united_states_of_america: "usa",
united_kingdom_of_great_britain_and_northern_ireland: "uk"
})
.groupby("year")
.rollup({
vetos: aq.op.sum("vetos"),
china: aq.op.sum("china"),
russia_ussr: aq.op.sum("russia_ussr"),
france: aq.op.sum("france"),
usa: aq.op.sum("usa"),
uk: aq.op.sum("uk")
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
vetos = {
let data = []
let html = await getHtml(urlVetos)
let $ = cheerio.load(html.data)
let tr = $("tr")
tr.each((i, e) => {
let tds = $(e).find("td:not(.title)") // sauf une ligne d'en-tête
let row = { "date": $(tds[0]).text(),
"draft": $(tds[1]).text().replace(/\n/gm, ""),
"written_record": $(tds[2]).text().replace(/\n/gm, " "),
"subject": cleanup($(tds[3]).text()),
"no_vote" : $(tds[4]) } // pas de texte pour conserver le tag séparateur <br>
if (tds.length > 0) data.push(row) // supprime les en-tête restantes en "th"
})
yield data
}

Insert cell
Insert cell
vetos_clean = aq.from(vetos)
.derive({ no_vote: d => op.replace(d.no_vote, /<td>|<\/td>/g, "") }) // tag début et fin
.derive({ no_vote: d => op.replace(d.no_vote, /<br>/g, ",") }) // tag séparateur
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// Récupère le contenu html d'une url en passant par un proxy
async function getHtml(u) {
return await axios({
method: 'get',
url: cors.concat(u)
})
}
Insert cell
// Remplace les tabulations et les sauts de lignes
cleanup = string => typeof(string) == "string" ? string.replace(/(\t|\n)/gm, "") : string
Insert cell
today = (
{
short: new Date().toLocaleString("fr", {
"day": "numeric",
"month": "numeric",
"year": "numeric"
}),
long: new Date().toLocaleString("fr", {
"day": "numeric",
"month": "long",
"year": "numeric"
})
}
)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more