Skip to content

Instantly share code, notes, and snippets.

{
"name": "ESG Tracker",
"nodes": [
{
"parameters": {
"httpMethod": "POST",
"path": "esg-query",
"options": {}
},
"type": "n8n-nodes-base.webhook",
from flask import Blueprint, request, jsonify
from flask_jwt_extended import jwt_required, get_jwt_identity
from datetime import datetime, timedelta
from sqlalchemy.exc import SQLAlchemyError
from app.extensions import db
from app.models import Loan, User, RepaymentSchedule, LoanProduct
from app.models.loan import LoanStatus
from app.models.loan_products import RepaymentFrequencies
from app.models.repaymentSchedule import RepaymentStatus
# LOANROUTE
from flask import Blueprint, request, jsonify
from flask_jwt_extended import jwt_required, get_jwt_identity
from datetime import datetime, timedelta
from sqlalchemy.exc import SQLAlchemyError
from app.extensions import db
from app.models import Loan, User, RepaymentSchedule, LoanProduct
from app.models.loan import LoanStatus
from app.models.loan_products import RepaymentFrequencies
# CLIENT.PY
import requests
from flask import current_app
from requests.auth import HTTPBasicAuth
import base64
def get_access_token():
"""
This func. helps generate an OAuth access token from Safaricom
M-Pesa API. The token is needed to authorize all other API requests (like STK Push).
from datetime import datetime
from pathlib import Path
import json
orders_path = Path(__file__).parent / "orders.json"
with open(orders_path, 'r',) as file:
orders_data = json.load(file)
# from order's note, extract affiliate_id and tracking product_id
def get_ids(note):
OBJECTIVE
Process order data and calculate commissions for affiliate partners based on their sales
- TASK1: Filters orders for a specific affiliate ID
- FROM orders_data -> [{order1}, {order2}, {order3}, {order4}, ....]
.SELECT each order, .STRIP affliate_id from order['notes']
- TASK2: Matches line items with the tracked product ID
- .STRIP product_ID from order['notes']
- .LOOP through an order line items and MATCH with product_ID
- .SET product_ID to filtered affliate_ID
- TASK3: Calculates total commission for that affiliate