Skip to content

Commit 2ae5c16

Browse files
♻️ Use for await...of in legacy
1 parent 1641f95 commit 2ae5c16

File tree

4 files changed

+17
-40
lines changed

4 files changed

+17
-40
lines changed

src/api/last-fm.ts

+7-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import { cosmicSync, config } from "@anandchowdhary/cosmic";
2-
import dayjs from "dayjs";
1+
import { config, cosmicSync } from "@anandchowdhary/cosmic";
32
import LastFm from "@toplast/lastfm";
43
import { ITrack } from "@toplast/lastfm/lib/common/common.interface";
4+
import dayjs from "dayjs";
5+
import week from "dayjs/plugin/weekOfYear";
6+
import { join } from "path";
57
import { integrationConfig, write } from "../common";
68
import type { Integration } from "../integration";
7-
import { join } from "path";
8-
import PromisePool from "es6-promise-pool";
9-
import week from "dayjs/plugin/weekOfYear";
109
dayjs.extend(week);
1110
cosmicSync("stethoscope");
1211

@@ -183,16 +182,12 @@ export default class LastDotFm implements Integration {
183182
console.log("Last.fm: Completed");
184183
}
185184
async legacy(start: string) {
186-
const CONCURRENCY = 10;
187185
const startDate = dayjs(start);
188-
let count = 0;
189-
const pool = new PromisePool(async () => {
186+
for await (const count of [...Array(dayjs().diff(startDate, "day")).keys()]) {
190187
const date = dayjs(startDate).add(count, "day");
191-
if (dayjs().diff(date, "day") === 0) return null;
192-
count++;
193188
return getLastFmTracks(date.toDate());
194-
}, CONCURRENCY);
195-
await pool.start();
189+
}
190+
console.log("Done!");
196191
console.log("Done!");
197192
}
198193
async summary() {}

src/api/oura-ring.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import dayjs from "dayjs";
44
import isLeapYear from "dayjs/plugin/isLeapYear";
55
import isoWeeksInYear from "dayjs/plugin/isoWeeksInYear";
66
import week from "dayjs/plugin/weekOfYear";
7-
import PromisePool from "es6-promise-pool";
87
import { lstat, pathExists, readdir, readJson } from "fs-extra";
98
import { join } from "path";
109
import { integrationConfig, write } from "../common";
@@ -140,16 +139,11 @@ export default class OuraRing implements Integration {
140139
console.log("Oura: Added daily summaries");
141140
}
142141
async legacy(start: string) {
143-
const CONCURRENCY = 1;
144142
const startDate = dayjs(start);
145-
let count = 0;
146-
const pool = new PromisePool(async () => {
143+
for await (const count of [...Array(dayjs().diff(startDate, "day")).keys()]) {
147144
const date = dayjs(startDate).add(count, "day");
148-
if (dayjs().diff(date, "day") === 0) return null;
149-
count++;
150145
return updateOuraDailyData(date.toDate());
151-
}, CONCURRENCY);
152-
await pool.start();
146+
}
153147
console.log("Done!");
154148
}
155149
async summary() {

src/api/rescuetime.ts

+6-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { config, cosmicSync } from "@anandchowdhary/cosmic";
22
import axios from "axios";
33
import dayjs from "dayjs";
44
import week from "dayjs/plugin/weekOfYear";
5-
import PromisePool from "es6-promise-pool";
65
import { lstat, pathExists, readdir, readJson } from "fs-extra";
76
import { join } from "path";
87
import { integrationConfig, write } from "../common";
@@ -42,7 +41,7 @@ const updateRescueTimeDailyData = async (date: Date) => {
4241
const day = dayjs(date).format("DD");
4342
const formattedDate = dayjs(date).format("YYYY-MM-DD");
4443

45-
if (integrationConfig("rescue-time")["top-categories"]) {
44+
if (integrationConfig("rescuetime")["top-categories"]) {
4645
console.log("RescueTime: Adding data for", date);
4746
const topCategories = (
4847
await axios.get(
@@ -66,7 +65,7 @@ const updateRescueTimeDailyData = async (date: Date) => {
6665
JSON.stringify(topCategoriesData, null, 2)
6766
);
6867
}
69-
if (integrationConfig("rescue-time")["top-activities"]) {
68+
if (integrationConfig("rescuetime")["top-activities"]) {
7069
const topActivities = (
7170
await axios.get(
7271
`https://www.rescuetime.com/anapi/data?format=json&key=${config(
@@ -90,7 +89,7 @@ const updateRescueTimeDailyData = async (date: Date) => {
9089
);
9190
}
9291

93-
if (integrationConfig("rescue-time").overview) {
92+
if (integrationConfig("rescuetime").overview) {
9493
const topOverview = (
9594
await axios.get(
9695
`https://www.rescuetime.com/anapi/data?format=json&key=${config(
@@ -132,16 +131,11 @@ export default class RescueTime implements Integration {
132131
console.log("RescueTime: Added daily summaries");
133132
}
134133
async legacy(start: string) {
135-
const CONCURRENCY = 10;
136134
const startDate = dayjs(start);
137-
let count = 0;
138-
const pool = new PromisePool(async () => {
135+
for await (const count of [...Array(dayjs().diff(startDate, "day")).keys()]) {
139136
const date = dayjs(startDate).add(count, "day");
140-
if (dayjs().diff(date, "day") === 0) return null;
141-
count++;
142-
return updateRescueTimeDailyData(date.toDate());
143-
}, CONCURRENCY);
144-
await pool.start();
137+
await updateRescueTimeDailyData(date.toDate());
138+
}
145139
console.log("Done!");
146140
}
147141
async summary() {

src/api/wakatime.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { config, cosmicSync } from "@anandchowdhary/cosmic";
22
import dayjs from "dayjs";
33
import week from "dayjs/plugin/weekOfYear";
4-
import PromisePool from "es6-promise-pool";
54
import { lstat, pathExists, readdir, readJson } from "fs-extra";
65
import { join } from "path";
76
import { WakaTimeClient } from "wakatime-client";
@@ -45,16 +44,11 @@ export default class Wakatime implements Integration {
4544
console.log("WakaTime: Added daily summaries");
4645
}
4746
async legacy(start: string) {
48-
const CONCURRENCY = 3;
4947
const startDate = dayjs(start);
50-
let count = 0;
51-
const pool = new PromisePool(async () => {
48+
for await (const count of [...Array(dayjs().diff(startDate, "day")).keys()]) {
5249
const date = dayjs(startDate).add(count, "day");
53-
if (dayjs().diff(date, "day") === 0) return null;
54-
count++;
5550
return updateWakatimeDailyData(date.toDate());
56-
}, CONCURRENCY);
57-
await pool.start();
51+
}
5852
console.log("Done!");
5953
}
6054
async summary() {

0 commit comments

Comments
 (0)