Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

update scripts

Steven Tey8b71e757849f
diff --git a/apps/web/scripts/get-subscribers.ts b/apps/web/scripts/get-subscribers.ts
new file mode 100644
index 0000000000..34936904c4
--- /dev/null
+++ b/apps/web/scripts/get-subscribers.ts
@@ -0,0 +1,52 @@
+import { prisma } from "@/lib/prisma";
+import "dotenv-flow/config";
+import * as fs from "fs";
+import * as Papa from "papaparse";
+
+let emailOpens: string[] = [];
+
+async function main() {
+ Papa.parse(fs.createReadStream("email_opens.csv", "utf-8"), {
+ header: true,
+ skipEmptyLines: true,
+ step: (result: {
+ data: {
+ email_address: string;
+ };
+ }) => {
+ emailOpens.push(result.data.email_address);
+ },
+ });
+
+ const subscribers = await prisma.user.findMany({
+ where: {
+ subscribed: true,
+ },
+ select: {
+ email: true,
+ name: true,
+ },
+ orderBy: {
+ createdAt: "asc",
+ },
+ });
+
+ const subscribersThatOpenedEmail = subscribers
+ .filter((subscriber) => emailOpens.includes(subscriber.email!))
+ .map(({ email, name }) => ({
+ email,
+ ...(name && {
+ firstName: name.split(" ")[0],
+ lastName: name.split(" ").slice(1).join(" "),
+ }),
+ }));
+
+ console.table(subscribersThatOpenedEmail.slice(0, 10));
+
+ fs.writeFileSync(
+ "active_email_subscribers.csv",
+ Papa.unparse(subscribersThatOpenedEmail),
+ );
+}
+
+main();
diff --git a/apps/web/scripts/send-emails.tsx b/apps/web/scripts/send-emails.tsx
index 7575c17f4a..0f0573cd04 100644
--- a/apps/web/scripts/send-emails.tsx
+++ b/apps/web/scripts/send-emails.tsx
@@ -1,5 +1,6 @@
-import { sendCancellationFeedback } from "app/api/stripe/webhook/utils";
import "dotenv-flow/config";
+import { sendEmail } from "emails";
+import FailedPayment from "emails/failed-payment";
const attemptCount = 2;
const amountDue = 2400;
@@ -13,27 +14,24 @@ const workspace = {
};
async function main() {
- // const res = await sendEmail({
- // email: user.email as string,
- // from: "[email protected]",
- // subject: `${
- // attemptCount == 2
- // ? "2nd notice: "
- // : attemptCount == 3
- // ? "3rd notice: "
- // : ""
- // }Your payment for Dub.co failed`,
- // react: (
- // <FailedPayment
- // attemptCount={attemptCount}
- // amountDue={amountDue}
- // user={user}
- // workspace={workspace}
- // />
- // ),
- // });
- const res = await sendCancellationFeedback({
- owners: [user],
+ const res = await sendEmail({
+ email: user.email as string,
+ subject: `${
+ attemptCount == 2
+ ? "2nd notice: "
+ : attemptCount == 3
+ ? "3rd notice: "
+ : ""
+ }Your payment for Dub.co failed`,
+ react: (
+ <FailedPayment
+ attemptCount={attemptCount}
+ amountDue={amountDue}
+ user={user}
+ workspace={workspace}
+ />
+ ),
});
console.log({ res });