-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport.js
More file actions
90 lines (82 loc) · 2.96 KB
/
export.js
File metadata and controls
90 lines (82 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
const hello = `hello at ${Date()}`
async function cdc(){
}
async function seer(){
}
// -------------- IARC (https://www.iarc.who.int/cancer-topics) --------------
let iarc={}
iarc.causes=['obesity','infections','uv','alcohol']
iarc.causesBy=['countries','cancers','attributable','regions','preventable']
iarc.causesGet= async (cause=iarc.causes[0],by=iarc.causesBy[0])=>{
let url = `https://gco.iarc.fr/causes/${cause}/data/${by}.json`
console.log(url)
try{
let d = await (await fetch(url)).json()
return d
} catch (err){
console.log(`${url}`,err)
return undefined
}
}
iarc.causesGetAll= async function(cache=false){ // retrieve all causal data
let dt={}
iarc.causes.forEach(async c=>{
dt[c]={}
iarc.causesBy.forEach(async b=>{
let url = `https://gco.iarc.fr/causes/${c}/data/${b}.json`
console.log(url)
try{
dt[c][b] = await (await fetch(url)).json()
} catch (err){
console.log(`${url}`, err)
}
})
})
if(cache){
iarc.causesGetAll=dt //replaces original function with fetched results, i.e. caching them
}
return dt
}
// ---------------------------------------------------------------------------
async function getZipURL(url='https://corsproxy.io/?https://ci5.iarc.fr/CI5plus/old/CI5plus_Summary_April2019.zip'){
const JSZip = (await import('https://cdn.jsdelivr.net/npm/jszip/+esm')).default
let res={}
fetch(url)
.then(response => response.blob())
.then(blob => {
var zip = new JSZip();
zip.loadAsync(blob)
.then((zip) => {
zip.forEach((relativePath, file) => {
file.async("uint8array").then((content) => {
// You will need to handle file content in browser's way like showing on the page or downloading it
// as creating files directly on user's computer is not allowed for security reasons
console.log("File:", relativePath, "Size:", content.byteLength);
// remove trailing blanks
let txt = (new TextDecoder()).decode(content)
let trailingBlank = txt.match(/[/\n/\r]+$/g)
if(trailingBlank){
txt=txt.slice(0,-(trailingBlank.length+1))
}
// parse text into table
res[relativePath]=(txt).split(/[\n\r]+/g).map(r=>r.split(/[\t,]/g))
});
});
})
.catch((err) => {
console.log("Error reading zip:", err);
});
})
.catch((err) => {
console.log("Error fetching zip:", err);
});
return res
// try files = getZipURL()
}
export { // these are the methods of epiVerseTracker
hello,
cdc,
seer,
iarc,
getZipURL
}