Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ STUDIO_TYPEORM_LOGGING=false

# WALLET_URL = http://wallet:5001/api/v1
WEB_URL=issuer-agent.demo.dhiway.com
REQUEST_URL_TOKEN=d53b731c-be91-458d-bd97-71d37d444e60
REQUEST_URL_TOKEN=d53b731c-be91-458d-bd97-71d37d444e60
SENDGRID_API_KEY=SG.xxxxxxxx.yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy # Replace with your actual SendGrid API key
DB_HOST=localhost
60 changes: 60 additions & 0 deletions src/scripts/fetch_creds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/python3
from dotenv import load_dotenv
import os
import psycopg2
from datetime import date, timedelta

load_dotenv()

db_config = {
"database": os.environ.get("STUDIO_TYPEORM_DATABASE", "issuer_agent"),
"user": os.environ.get("STUDIO_TYPEORM_USERNAME", "postgres"),
"password": os.environ.get("STUDIO_TYPEORM_PASSWORD", "secret"),
"host": os.environ.get("DB_HOST", "localhost"),
"port": int(os.environ.get("STUDIO_TYPEORM_PORT", 5574))
}


conn = psycopg2.connect(**db_config)

cur = conn.cursor()

# Date range: last 30 days
today = date.today()
hundred_days_ago = today - timedelta(days=30)

# Query to fetch Creds created in the last 30 days
query = """
SELECT "id", "identifier", "active", "schemaId", "fromDid", "credHash", "created_at"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are changes to the cred table , for e.g identifier is changed to credId.
Take a look at cordproof-2025 branch

Copy link
Author

@prashant4dev prashant4dev Jul 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can rebase this changes with the cordproof-2025
this changes are on top of main branch currently

FROM "cred"
WHERE "created_at" >= %s
ORDER BY "created_at" DESC
"""


args = (hundred_days_ago,)
cur.execute(query, args)
rows = cur.fetchall()

# Print formatted results
print("{:<40}, {:<20}, {:<7}, {:<10}, {:<20}, {:<64}, {}".format(
"ID", "Identifier", "Active", "SchemaID", "FromDID", "CredHash", "CreatedAt"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here , i have removed schemaId

))
print("-" * 180)

for row in rows:
id, identifier, active, schemaId, fromDid, credHash, created_at = row
print("{:<40}, {:<20}, {:<7}, {:<10}, {:<20}, {:<64}, {}".format(
id or '',
identifier or '',
str(active),
schemaId or '',
fromDid or '',
credHash or '',
created_at.strftime("%Y-%m-%d %H:%M:%S")
))

print(f"\nTotal credentials issued in last 30 days: {len(rows)}\n")

cur.close()
conn.close()
25 changes: 25 additions & 0 deletions src/scripts/send_activity.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
source $(dirname "$0")/../.env
today=$(date +%Y-%m-%d)
output=activity_file.${today}.txt
python3 $(dirname $0)/scripts/fetch_creds.py > $output

ATTACHMENT0=$(base64 -w 0 $output);


# echo $ACTIVE
# cat output_active.txt
# echo "-------"
# echo $NON_ACTIVE
# cat output_non_active.txt
# echo "-------"


curl --request POST \
--url https://api.sendgrid.com/v3/mail/send \
--header "Authorization: Bearer ${SENDGRID_API_KEY}" \
--header 'Content-Type: application/json' \
--data "{\"personalizations\": [{\"to\": [{\"email\": \"sales@dhiway.com\"}, {\"email\": \"satish@dhiway.com\"}, {\"email\": \"amar@dhiway.com\"}]}],\"from\": {\"email\": \"hello@dhiway.com\", \"name\": \"Issuer agentMessageBot\"},\"subject\":\"Activity Report\",\"content\": [{\"type\": \"text/html\",\"value\": \"Hi Team,<br>Please find the attachments. It contains details of activity done on issuer-agent on last 30 days.\"}], \"attachments\": [{\"content\": \"${ATTACHMENT0}\", \"type\": \"text/plain\", \"filename\": \"activity.csv\"}]}"


#rm $output
20 changes: 20 additions & 0 deletions src/scripts/setup_cron.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

SCRIPT_PATH="/home/developer/issuer-agent/scripts/send_activity.sh"
CRON_JOB="0 9 1 * * $SCRIPT_PATH >> /home/developer/issuer-agent/send.log 2>&1"

# Ensure script is executable
if [ ! -x "$SCRIPT_PATH" ]; then
chmod +x "$SCRIPT_PATH"
echo "Made $SCRIPT_PATH executable."
fi

# Remove old instance if exists
crontab -l 2>/dev/null | grep -v "$SCRIPT_PATH" > /tmp/current_cron

# Add new cron job
echo "$CRON_JOB" >> /tmp/current_cron
crontab /tmp/current_cron
rm /tmp/current_cron

echo "✅ Cron job installed to run every 30 days."