-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfetchData.js
More file actions
123 lines (115 loc) · 3.27 KB
/
fetchData.js
File metadata and controls
123 lines (115 loc) · 3.27 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
const fs = require('fs');
const https = require('https');
const path = require('path');
function downloadRawData() {
const urlRoot = 'https://raw.githubusercontent.com/TaxFoundation/';
const files = [
{
name: 'IndexRanks',
url:
'international-tax-competitiveness-index/master/final_outputs/final_categories.csv',
},
{
name: 'IndexSubranks',
url:
'international-tax-competitiveness-index/master/final_outputs/subcategories_2025.csv',
},
{
name: 'SourceRevenueByCountry',
url:
'sources-of-government-revenue/master/final-outputs/oecd_by_country.csv',
},
{
name: 'SourceRevenueOECDAverage',
url:
'sources-of-government-revenue/master/final-outputs/oecd_averages.csv',
},
{
name: 'WorldwideCorporateTaxRates',
url:
'worldwide-corporate-tax-rates/refs/heads/master/final_outputs/rate_time_series.csv',
},
{
name: 'CountryCorporateTaxRates',
url:
'worldwide-corporate-tax-rates/refs/heads/master/final_data/final_data_long.csv',
},
{
name: 'OECDCorporateTaxRates',
url:
'capital-cost-recovery/master/final-outputs/npv_weighted_timeseries.csv',
},
{
name: 'CountryCorporateNPVAllYears',
url: 'capital-cost-recovery/master/final-data/npv_all_years.csv',
},
{
name: 'TaxBurdenOnLabor',
url: 'tax-burden-on-labor/refs/heads/master/final-outputs/Table1.csv',
},
{
name: 'IndexRawData',
url:
'international-tax-competitiveness-index/master/final_outputs/raw_data_2025.csv',
},
{
name: 'ConsumptionRevenue',
url: 'consumption-taxes/main/final_outputs/revenue.csv',
},
{
name: 'ReducedRates',
url: 'consumption-taxes/main/final_outputs/reduced_rates_base.csv',
},
{
name: 'Fuel',
url: 'consumption-taxes/main/final_outputs/fuel.csv',
},
{
name: 'Alcohol',
url: 'consumption-taxes/main/final_outputs/alcohol.csv',
},
{
name: 'Tobacco',
url: 'consumption-taxes/main/final_outputs/tobacco.csv',
},
{
name: 'ConsumptionData',
url: 'consumption-taxes/main/intermediate_outputs/consumption_data.csv',
},
];
files.forEach(f => {
const dest = path.resolve(__dirname, `static/data/${f.name}.csv`);
fs.access(dest, err => {
if (!err) {
fs.unlinkSync(dest);
console.log(`Removed old copy of ${f.name}.csv`);
}
const file = fs.createWriteStream(dest);
const req = https.get(`${urlRoot}${f.url}`);
req.on('response', response => {
if (response.statusCode !== 200) {
console.log(
`Response for ${f.name} was ${response.statusCode}, not downloaded`
);
}
response.pipe(file);
});
file.on('finish', () =>
file.close(() => console.log(`Wrote ${f.name}.csv`))
);
req.on('error', err => {
fs.unlink(dest, () =>
console.log(
`There was an error with the request for ${f.name}: ${err}`
)
);
});
file.on('error', err => {
fs.unlink(dest, () => {
console.log(`There was an error writing ${f.name}: ${err}`);
});
});
});
});
}
downloadRawData();