-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsampleJSONconverter.js
More file actions
141 lines (103 loc) · 3.02 KB
/
Copy pathsampleJSONconverter.js
File metadata and controls
141 lines (103 loc) · 3.02 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Convert Array of scraped data into a JSON and save it to a File
const scrapeData = require( './scraper_output/fees_10012022' );
const protocols = require('./utils/listOfProtocols');
const fs = require('fs-extra');
const utils = require('./utils/saveFileFunction');
let jsonOutput = {
"ethereumData": [],
"uniswapData": [],
"binance_Smart_ChainData": [],
"sushiswapData": [],
"aaveData": [],
"bitcoinData": [],
"trader_JoeData": [],
"compoundData": [],
"balancerData": [],
"terraswapData": [],
"makerDAOData": [],
"avalancheData": [],
"abracadabra_moneyData": [],
"spookyswapData": [],
"quickswapData": [],
};
// List of Functions to be called according to the type of data being scraped
let ethereumPush = ( obj ) => {
jsonOutput.ethereumData.push( obj );
}
let uniswapPush = ( obj ) => {
jsonOutput.uniswapData.push( obj );
}
let binanceSmartChainPush = ( obj ) => {
jsonOutput.binance_Smart_ChainData.push( obj );
}
let sushiswapPush = ( obj ) => {
jsonOutput.sushiswapData.push( obj );
}
let aavePush = ( obj ) => {
jsonOutput.aaveData.push( obj );
}
let bitcoinPush = ( obj ) => {
jsonOutput.bitcoinData.push( obj );
}
let trader_JoePush = ( obj ) => {
jsonOutput.trader_JoeData.push( obj );
}
let compoundPush = ( obj ) => {
jsonOutput.compoundData.push( obj );
}
let balancerPush = ( obj ) => {
jsonOutput.balancerData.push( obj );
}
let terraswapPush = ( obj ) => {
jsonOutput.terraswapData.push( obj );
}
let makerDAOPush = ( obj ) => {
jsonOutput.makerDAOData.push( obj );
}
let avalanchePush = ( obj ) => {
jsonOutput.avalancheData.push( obj );
}
let abracadabra_moneyPush = ( obj ) => {
jsonOutput.abracadabra_moneyData.push( obj );
}
let spookyswapPush = ( obj ) => {
jsonOutput.spookyswapData.push( obj );
}
let quickswapPush = ( obj ) => {
jsonOutput.quickswapData.push( obj );
}
// Array that stores the functions that will be called
const arrayOfFunctions = [
ethereumPush,
uniswapPush,
binanceSmartChainPush,
trader_JoePush,
aavePush,
sushiswapPush,
compoundPush,
bitcoinPush,
balancerPush,
terraswapPush,
makerDAOPush,
avalanchePush,
abracadabra_moneyPush,
spookyswapPush,
quickswapPush,
];
// Main function that calls the other functions in the Array
// It maps the scraped data to the corresponding array within the jsonOutput object
let mapProtocolToJSON = (data, row ) => {
let object = { "date": data[row][0], "fee": Number( data[row][2] ) };
let thisProtocol = data[row][1];
let protocolIndex = protocols.indexOf( thisProtocol );
let funcFromArray = arrayOfFunctions[protocolIndex];
funcFromArray( object )
}
// Loop to evaluate each position in the scrapeData
for ( let r = 0; r < scrapeData.length ; r++ ) {
mapProtocolToJSON( scrapeData, r );
}
const jsonFile = 'module.exports = ' + JSON.stringify(jsonOutput);
console.log(jsonFile)
const filePath = './chartJS_input/jsonFile.js'
utils.saveFile(filePath, jsonFile);