Miha Vidakovic
Miha Vidakovic

Reputation: 393

Download latest file from Github folder

how would I download the latest file that is uploaded to some Github repo in a particular folder? I am using Node.js with cron job to download the file, but I need to get the fresh file every day.

This is the repo if anyone is interested: https://github.com/CSSEGISandData/COVID-19

Upvotes: 0

Views: 285

Answers (1)

Previous day's reports are published every day, so get the latest file using the date.

function getDate() {
	const yesterday = new Date();
	yesterday.setDate(yesterday.getDate() - 1);
	let dd = yesterday.getDate(); 
	let mm = yesterday.getMonth() + 1; 
	const yyyy = yesterday.getFullYear(); 
	if (dd < 10) { 
	    dd = '0' + dd; 
	} 
	if (mm < 10) { 
	    mm = '0' + mm; 
	} 
	return `${mm}-${dd}-${yyyy}`
}

const baseUrl = 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/';

function getLatestDownloadUrl() {
	return `${baseUrl}${getDate()}.csv`;
}

console.log(getLatestDownloadUrl());

Upvotes: 1

Related Questions