Skip to content

Commit 7beb74f

Browse files
🐛 Support for all in integrations
1 parent c3d3d9a commit 7beb74f

10 files changed

+31
-35
lines changed

src/api/clockify.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type ClockifyResult = {
2424
}[];
2525

2626
const getTimeData = async (date: Date) => {
27-
if (integrationConfig("clockify").entries) {
27+
if (integrationConfig("clockify", "entries")) {
2828
const {
2929
data,
3030
}: {

src/api/google-fit.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const saveData = async (data: fitness_v1.Schema$Session[]) => {
5050
}
5151
});
5252
for await (const sessionType of Object.keys(itemsByDateAndType)) {
53-
if (integrationConfig("google-fit")[sessionType])
53+
if (integrationConfig("google-fit", sessionType))
5454
for await (const sessionDate of Object.keys(itemsByDateAndType[sessionType])) {
5555
await write(
5656
join(".", "data", `google-fit-${sessionType.replace(/_/g, "-")}`, "daily", sessionDate, "sessions.json"),

src/api/last-fm.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const fetchTracks = async (date: Date, page = 1) => {
2828
};
2929

3030
const getLastFmTracks = async (date: Date, page = 1) => {
31-
if (integrationConfig("last-fm").history) {
31+
if (integrationConfig("last-fm", "history")) {
3232
console.log("Last.fm: Fetching tracks for", dayjs(date).format("YYYY-MM-DD"));
3333
const tracks = await fetchTracks(date, page);
3434
const itemsByDate: { [index: string]: ITrack[] } = {};
@@ -62,7 +62,7 @@ export default class LastDotFm implements Integration {
6262
}
6363
console.log("Last.fm: Added daily summaries");
6464

65-
if (integrationConfig("last-fm")["top-albums"]) {
65+
if (integrationConfig("last-fm", "top-albums")) {
6666
const topAlbumsWeekly = await lastFm.user.getTopAlbums({
6767
user: config("lastfmUsername"),
6868
period: "7day",
@@ -75,7 +75,7 @@ export default class LastDotFm implements Integration {
7575
);
7676
}
7777

78-
if (integrationConfig("last-fm")["top-tracks"]) {
78+
if (integrationConfig("last-fm", "top-tracks")) {
7979
const topTracksWeekly = await lastFm.user.getTopTracks({
8080
user: config("lastfmUsername"),
8181
period: "7day",
@@ -88,7 +88,7 @@ export default class LastDotFm implements Integration {
8888
);
8989
}
9090

91-
if (integrationConfig("last-fm")["top-artists"]) {
91+
if (integrationConfig("last-fm", "top-artists")) {
9292
const topArtistsWeekly = await lastFm.user.getTopArtists({
9393
user: config("lastfmUsername"),
9494
period: "7day",
@@ -101,7 +101,7 @@ export default class LastDotFm implements Integration {
101101
);
102102
}
103103

104-
if (integrationConfig("last-fm")["top-albums"]) {
104+
if (integrationConfig("last-fm", "top-albums")) {
105105
const topAlbumsMonthly = await lastFm.user.getTopAlbums({
106106
user: config("lastfmUsername"),
107107
period: "1month",
@@ -114,7 +114,7 @@ export default class LastDotFm implements Integration {
114114
);
115115
}
116116

117-
if (integrationConfig("last-fm")["top-tracks"]) {
117+
if (integrationConfig("last-fm", "top-tracks")) {
118118
const topTracksMonthly = await lastFm.user.getTopTracks({
119119
user: config("lastfmUsername"),
120120
period: "1month",
@@ -127,7 +127,7 @@ export default class LastDotFm implements Integration {
127127
);
128128
}
129129

130-
if (integrationConfig("last-fm")["top-artists"]) {
130+
if (integrationConfig("last-fm", "top-artists")) {
131131
const topArtistsMonthly = await lastFm.user.getTopArtists({
132132
user: config("lastfmUsername"),
133133
period: "1month",
@@ -140,7 +140,7 @@ export default class LastDotFm implements Integration {
140140
);
141141
}
142142

143-
if (integrationConfig("last-fm")["top-albums"]) {
143+
if (integrationConfig("last-fm", "top-albums")) {
144144
const topAlbumsYearly = await lastFm.user.getTopAlbums({
145145
user: config("lastfmUsername"),
146146
period: "12month",
@@ -153,7 +153,7 @@ export default class LastDotFm implements Integration {
153153
);
154154
}
155155

156-
if (integrationConfig("last-fm")["top-tracks"]) {
156+
if (integrationConfig("last-fm", "top-tracks")) {
157157
const topTracksYearly = await lastFm.user.getTopTracks({
158158
user: config("lastfmUsername"),
159159
period: "12month",
@@ -166,7 +166,7 @@ export default class LastDotFm implements Integration {
166166
);
167167
}
168168

169-
if (integrationConfig("last-fm")["top-artists"]) {
169+
if (integrationConfig("last-fm", "top-artists")) {
170170
const topArtistsYearly = await lastFm.user.getTopArtists({
171171
user: config("lastfmUsername"),
172172
period: "12month",

src/api/oura-ring.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ cosmicSync("stethoscope");
1616

1717
const updateOuraDailyData = async (date: Date) => {
1818
const formattedDate = dayjs(date).format("YYYY-MM-DD");
19-
if (integrationConfig("oura-ring").weight) {
19+
if (integrationConfig("oura-ring", "weight")) {
2020
const {
2121
data: healthData,
2222
}: {
@@ -43,7 +43,7 @@ const updateOuraDailyData = async (date: Date) => {
4343
);
4444
console.log("Oura: Added summary data");
4545
}
46-
if (integrationConfig("oura-ring").sleep) {
46+
if (integrationConfig("oura-ring", "sleep")) {
4747
const {
4848
data: sleepData,
4949
}: {
@@ -70,7 +70,7 @@ const updateOuraDailyData = async (date: Date) => {
7070
JSON.stringify(sleepData.sleep, null, 2)
7171
);
7272
}
73-
if (integrationConfig("oura-ring").readiness) {
73+
if (integrationConfig("oura-ring", "readiness")) {
7474
const {
7575
data: readinessData,
7676
}: {
@@ -97,7 +97,7 @@ const updateOuraDailyData = async (date: Date) => {
9797
JSON.stringify(readinessData.readiness, null, 2)
9898
);
9999
}
100-
if (integrationConfig("oura-ring").activity) {
100+
if (integrationConfig("oura-ring", "activity")) {
101101
const {
102102
data: activityData,
103103
}: {

src/api/pocket-casts.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ export default class PocketCastsI implements Integration {
2222
console.log("Pocket Casts: Starting...");
2323
await pocketCasts.login();
2424

25-
if (integrationConfig("pocket-casts").library) {
25+
if (integrationConfig("pocket-casts", "library")) {
2626
const podcasts = (await pocketCasts.getList()).podcasts;
2727
await write(join(".", "data", "pocket-casts-podcasts", "library.json"), JSON.stringify(podcasts, null, 2));
2828
console.log("Pocket Casts: Added library");
2929
}
3030

31-
if (integrationConfig("pocket-casts").history) {
31+
if (integrationConfig("pocket-casts", "history")) {
3232
let items: Episode[] = [];
3333
try {
3434
const years = await readdir(join(".", "data", "pocket-casts-podcasts", "daily"));

src/api/rescuetime.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const updateRescueTimeDailyData = async (date: Date) => {
4141
const day = dayjs(date).format("DD");
4242
const formattedDate = dayjs(date).format("YYYY-MM-DD");
4343

44-
if (integrationConfig("rescuetime")["top-categories"]) {
44+
if (integrationConfig("rescuetime", "top-categories")) {
4545
console.log("RescueTime: Adding data for", date);
4646
const topCategories = (
4747
await axios.get(
@@ -65,7 +65,7 @@ const updateRescueTimeDailyData = async (date: Date) => {
6565
JSON.stringify(topCategoriesData, null, 2)
6666
);
6767
}
68-
if (integrationConfig("rescuetime")["top-activities"]) {
68+
if (integrationConfig("rescuetime", "top-activities")) {
6969
const topActivities = (
7070
await axios.get(
7171
`https://www.rescuetime.com/anapi/data?format=json&key=${config(
@@ -89,7 +89,7 @@ const updateRescueTimeDailyData = async (date: Date) => {
8989
);
9090
}
9191

92-
if (integrationConfig("rescuetime").overview) {
92+
if (integrationConfig("rescuetime", "overview")) {
9393
const topOverview = (
9494
await axios.get(
9595
`https://www.rescuetime.com/anapi/data?format=json&key=${config(

src/api/spotify.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export default class Spotify implements Integration {
112112
api.setAccessToken(data.body.access_token);
113113
console.log("Spotify: Refreshed access token");
114114

115-
if (integrationConfig("spotify").history) {
115+
if (integrationConfig("spotify", "history")) {
116116
const history = await api.getMyRecentlyPlayedTracks();
117117
const itemsByDate: { [index: string]: Array<any> } = {};
118118
for await (const item of history.body.items) {
@@ -137,7 +137,7 @@ export default class Spotify implements Integration {
137137
const month = date.format("MM");
138138
const day = date.format("DD");
139139

140-
if (integrationConfig("spotify").library) {
140+
if (integrationConfig("spotify", "library")) {
141141
const library = await api.getMySavedTracks();
142142
const libraryItems = cleanSpotifyTracksResponse(library.body.items.map((item) => item.track)).map(
143143
(item, index) => ({
@@ -152,7 +152,7 @@ export default class Spotify implements Integration {
152152
console.log("Spotify: Added library");
153153
}
154154

155-
if (integrationConfig("spotify")["top-tracks"]) {
155+
if (integrationConfig("spotify", "top-tracks")) {
156156
const shortTermTopTracks = cleanSpotifyTracksResponse(
157157
(await api.getMyTopTracks({ time_range: "short_term" })).body.items
158158
);
@@ -181,7 +181,7 @@ export default class Spotify implements Integration {
181181
console.log("Spotify: Added long-term top tracks");
182182
}
183183

184-
if (integrationConfig("spotify")["top-artists"]) {
184+
if (integrationConfig("spotify", "top-artists")) {
185185
const shortTermTopArtists = cleanSpotifyArtistsResponse(
186186
(await api.getMyTopArtists({ time_range: "short_term" })).body.items
187187
);

src/api/twitter.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ interface Tweet {
2424
}
2525

2626
const getRecentTweets = async (count: number = 100) => {
27-
if (integrationConfig("twitter").tweets) {
27+
if (integrationConfig("twitter", "tweets")) {
2828
const response: Array<Tweet> = await client.get("statuses/user_timeline", {
2929
screen_name: config("twitterScreenName") || "",
3030
count,
@@ -46,7 +46,7 @@ const getRecentTweets = async (count: number = 100) => {
4646
}
4747
}
4848

49-
if (integrationConfig("twitter").likes) {
49+
if (integrationConfig("twitter", "likes")) {
5050
const response: Array<Tweet> = await client.get("favorites/list", {
5151
screen_name: config("twitterScreenName") || "",
5252
count,

src/api/wakatime.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const client = new WakaTimeClient(config("wakatimeApiKey") || "example");
1414
const updateWakatimeDailyData = async (date: Date) => {
1515
const formattedDate = dayjs(date).format("YYYY-MM-DD");
1616
console.log("WakaTime: Adding data for", formattedDate);
17-
if (integrationConfig("wakatime").summary) {
17+
if (integrationConfig("wakatime", "summary")) {
1818
const summary = await client.getMySummary({
1919
dateRange: {
2020
startDate: formattedDate,

src/common.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,11 @@ import { config, cosmicSync } from "@anandchowdhary/cosmic";
22
import { ensureFile, writeFile } from "fs-extra";
33
cosmicSync("stethoscope");
44

5-
export const integrationConfig = (service: string) => {
5+
export const integrationConfig = (service: string, key: string) => {
66
const configs: { [index: string]: { [index: string]: boolean } } = config("integrations") || {};
77
const items = configs[service] || {};
8-
if (items.all) {
9-
Object.keys(items).forEach((key) => {
10-
items[key] = true;
11-
});
12-
}
13-
return items;
8+
if (items.all) return true;
9+
return items[key];
1410
};
1511

1612
export const write = async (name: string, contents: any) => {

0 commit comments

Comments
 (0)