-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
106 lines (80 loc) · 3.2 KB
/
index.html
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
<title>zeehaven - convert zeeschuimer ndjson to csv</title>
<script type="text/javascript" src="datamodel.js"></script>
<script>
function dodrop(event) {
var dt = event.dataTransfer;
var files = dt.files;
for (var i = 0; i < files.length; i++) {
reader = new FileReader();
const fname = files[i].name.split('-');
const _date = new Date();
const filename = [fname[0], fname[1], fname[2], _date.toISOString() + ".csv"].join('-');
reader.onload = function (event) {
const input = event.target.result;
let result = input.split('\n').map(function(s) { if (s) { return JSON.parse(s); } });
const replacer = (key, value) => value === null ? '' : value;
//get rid of any empty last lines
if (result[result.length - 1] == undefined) {
result.pop();
}
//const _type = document.querySelector('input[name="type"]:checked').value;
const _type = fname[2];
let header = []
let csv = "";
if (_type == "twitter.com") {
csv = parseTwitter(header, result);
} else if (_type == "instagram.com") {
csv = parseInstagram(header, result);
} else if (_type == "tiktok.com") {
csv = parseTiktok(header, result);
}else {
csv = parseAll(header, result);
}
downloadCSV(filename, csv);
}
reader.readAsText(files[i]);
}
}
function downloadCSV(filename, data) {
let downloadLink;
if (window.Blob == undefined || window.URL == undefined || window.URL.createObjectURL == undefined) {
alert("Your browser doesn't support Blobs");
return;
}
let csvFile = new Blob([data], {type:"text/csv"});
downloadLink = document.createElement("a");
downloadLink.innerHTML = "<button>Download the Data</button>";
downloadLink.download = filename;
downloadLink.href = window.URL.createObjectURL(csvFile);
downloadLink.style.display = "none";
document.body.appendChild(downloadLink);
downloadLink.click();
}
</script>
</head>
<body>
<div class="alles">
<h1>zeehaven</h1>
<h2>convert <a href="https://github.com/digitalmethodsinitiative/zeeschuimer" target="_blank">zeeschuimer</a> ndjson to csv</h2>
<img src="img/zeehaven.png" width="60%">
<div id="output"
ondragenter="document.getElementById('output').textContent = ''; event.stopPropagation(); event.preventDefault();"
ondragover="event.stopPropagation(); event.preventDefault();"
ondrop="event.stopPropagation(); event.preventDefault();
dodrop(event);">
drop your ndjson file here.
select location to save your csv file.
</div>
<div id="csv"></div>
<footer class="credits">
<p><a href="https://github.com/PublicDataLab/zeehaven" target="_blank">code / credit</a></p>
<p><a href="https://publicdatalab.org/" target="_blank"><img src="https://publicdatalab.org/wp-content/uploads/2021/02/pdl-logo.png" height="20"></a></p>
</footer>
</div>
</body>
</html>