-
Notifications
You must be signed in to change notification settings - Fork 13
feat:send activity log every 30 days #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| FROM "cred" | ||
| WHERE "created_at" >= %s | ||
prashant4dev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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" | ||
|
||
| )) | ||
| 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() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
prashant4dev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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." |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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-2025branchUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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