Incluye utilidades de ops para CRON_SECRET, login customer Google Ads, sync de seguimiento BPS y probes de conexiones. Co-authored-by: Cursor <cursoragent@cursor.com>
34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
import { config } from 'dotenv';
|
|
import { resolve } from 'path';
|
|
import { writeFileSync, mkdirSync } from 'fs';
|
|
config({ path: resolve(process.cwd(), '.env.local') });
|
|
import { getValidAccessToken } from '../src/lib/google-drive';
|
|
|
|
const ID = '1YPcHBjioiHHQy22Q2xevkvUqA5jMq87v6IviV7VTL2s';
|
|
const OCT = '1-Zss1suBLDxAgqUuP9DrJYWHiicyin8aQqMOTIIekAg';
|
|
|
|
async function exportXlsx(token: string, id: string, path: string) {
|
|
const mime =
|
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
|
|
const r = await fetch(
|
|
`https://www.googleapis.com/drive/v3/files/${id}/export?mimeType=${encodeURIComponent(mime)}`,
|
|
{ headers: { Authorization: `Bearer ${token}` } }
|
|
);
|
|
if (!r.ok) throw new Error(`${id} ${r.status} ${(await r.text()).slice(0, 300)}`);
|
|
const buf = Buffer.from(await r.arrayBuffer());
|
|
writeFileSync(path, buf);
|
|
console.log('wrote', path, buf.length);
|
|
}
|
|
|
|
async function main() {
|
|
const token = await getValidAccessToken();
|
|
mkdirSync('/tmp/bps-cal', { recursive: true });
|
|
await exportXlsx(token, ID, '/tmp/bps-cal/bps-calendario.xlsx');
|
|
await exportXlsx(token, OCT, '/tmp/bps-cal/bps-octubre.xlsx');
|
|
}
|
|
|
|
main().catch((e) => {
|
|
console.error(e);
|
|
process.exit(1);
|
|
});
|