Edits history of script submission #9449 for ' Get crawl statistics by frequency (botify)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Botify = {
    	token: string
    }
    /**
     * Get crawl statistics by frequency
     * Return crawl statistics grouped by time frequency (1 min, 5 mins or 60 min) for an analysis
     */
    export async function main(
    	auth: Botify,
    	username: string,
    	project_slug: string,
    	analysis_slug: string,
    	limit: string | undefined,
    	frequency: string | undefined
    ) {
    	const url = new URL(
    		`https://api.botify.com/analyses/${username}/${project_slug}/${analysis_slug}/crawl_statistics/time`
    	)
    	for (const [k, v] of [
    		['limit', limit],
    		['frequency', frequency]
    	]) {
    		if (v !== undefined && v !== '' && k !== undefined) {
    			url.searchParams.append(k, v)
    		}
    	}
    	const response = await fetch(url, {
    		method: 'GET',
    		headers: {
    			Authorization: 'Token ' + auth.token
    		},
    		body: undefined
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.text()
    }
    

    Submitted by hugo697 566 days ago