diff --git a/app/cron_pocketbase.py b/app/cron_pocketbase.py
index fc7004e..de6a9ee 100644
--- a/app/cron_pocketbase.py
+++ b/app/cron_pocketbase.py
@@ -1,21 +1,95 @@
+import pytz
from datetime import datetime, timedelta
+from urllib.request import urlopen
+import certifi
+import json
+import ujson
+import schedule
+import time
+import subprocess
from pocketbase import PocketBase # Client also works the same
import asyncio
+import aiohttp
+import pytz
+import pandas as pd
+import numpy as np
+
+import smtplib
+from email.mime.multipart import MIMEMultipart
+from email.mime.text import MIMEText
+import boto3
+from botocore.exceptions import NoCredentialsError
+from bs4 import BeautifulSoup
+
from dotenv import load_dotenv
import os
-load_dotenv()
+load_dotenv()
+api_key = os.getenv('FMP_API_KEY')
pb_admin_email = os.getenv('POCKETBASE_ADMIN_EMAIL')
pb_password = os.getenv('POCKETBASE_PASSWORD')
+aws_access_key_id = os.getenv('AWS_ACCESS_KEY_ID')
+aws_secret_access_key = os.getenv('AWS_SECRET_ACCESS_KEY')
+
+berlin_tz = pytz.timezone('Europe/Berlin')
pb = PocketBase('http://127.0.0.1:8090')
admin_data = pb.admins.auth_with_password(pb_admin_email, pb_password)
-
+pb_admin_email = os.getenv('POCKETBASE_ADMIN_EMAIL')
+pb_password = os.getenv('POCKETBASE_PASSWORD')
now = datetime.now()
one_month_ago = now - timedelta(days=30)
+def send_email(recipient):
+ # Replace the placeholders with your AWS SES credentials
+ region_name = 'eu-north-1' #email-smtp.eu-north-1.amazonaws.com
+
+ # Replace the placeholders with your sender email and password
+ sender_email = 'mrahimi@stocknear.com'
+
+ to_email = recipient # user email address
+ subject = f'Your Free Trial expired'
+
+ # Read the index.html file
+ with open('html_template/free_trial.html', 'r') as file:
+ html_content = file.read()
+
+
+ # Create a MIMEMultipart object
+ message = MIMEMultipart('alternative')
+ message['Subject'] = subject
+ message['From'] = sender_email
+ message['To'] = to_email
+
+ #Preheader text
+ preheader = MIMEText("Your free trial ended.", 'plain')
+
+ message.attach(MIMEText(html_content, 'html'))
+
+ # Use Amazon SES to send the email
+ ses_client = boto3.client(
+ 'ses',
+ aws_access_key_id=aws_access_key_id,
+ aws_secret_access_key=aws_secret_access_key,
+ region_name=region_name
+ )
+
+ try:
+ # Send the email
+ response = ses_client.send_raw_email(
+ Source=message['From'],
+ Destinations=[message['To']],
+ RawMessage={'Data': message.as_string()},
+ )
+ print("Email sent successfully!")
+ except NoCredentialsError:
+ print("AWS credentials not available")
+ except Exception as e:
+ print(f"Error sending email: {e}")
+
+
async def update_free_trial():
data = pb.collection("users").get_full_list(query_params = {"filter": f'freeTrial = True'})
@@ -29,5 +103,10 @@ async def update_free_trial():
"tier": 'Free',
"freeTrial": False,
})
+ try:
+ send_email(item.email)
+ except Exception as e:
+ print(e)
+
asyncio.run(update_free_trial())
\ No newline at end of file
diff --git a/app/cron_price_alert.py b/app/cron_price_alert.py
index 5075141..5bc62e8 100755
--- a/app/cron_price_alert.py
+++ b/app/cron_price_alert.py
@@ -147,7 +147,7 @@ async def run():
}
pb.collection('notifications').create(newNotification)
#send alert via email
- recipient = (pb.collection('users').get_one(item.user)).email
+ recipient = item.email
send_email(recipient, symbol, item.asset_type, current_price, target_price, item.condition)
try:
asyncio.run(run())
diff --git a/app/html_template/free_trial.html b/app/html_template/free_trial.html
new file mode 100644
index 0000000..06ead3b
--- /dev/null
+++ b/app/html_template/free_trial.html
@@ -0,0 +1,16 @@
+
+
+
+
+
|
|
Free Trial | | - Your free trial has ended. To continue enjoying unlimited access to the platform and support our project, please consider subscribing to the
+ Pro Tier.
- To cover the costs of service, servers, and data licensing, we offer a monthly subscription at $1.99 or an annual plan at $19.99, saving you an additional 16%.
- Stocknears’ primary goal is to remain transparent and consumer-friendly. Consider this an experiment to see if a project built on ethical design can thrive, compared to others in the industry that are often abusive and absurdly priced.
|
|
|
|
+
+
+
+
+