get_env('/Users/yamna/Projets/Bankeschon/Script/database_credentials.env') get_env('/Users/yamna/Projets/Bankeschon/Script/sendgrid.env') connection = psycopg2.connect(database=os.getenv('DB_NAME'), user=os.getenv('DB_USER'), password=os.getenv('DB_USER_PASSWORD'), host=os.getenv('DB_HOST'), port=os.getenv('DB_PORT')) # Récuperation des donnees client query = '''SELECT surname, name, mail ,adapted_offers from prospects where is_customer = 1 order by id''' customers_array = [] query_to_array(connection, customers_array, query) # Parcours du tableau et envoie de mail aux clients correspondants length = len(customers_array) for i in range(0, length): adapted_offers_array = customers_array[i]['adapted_offers'].split('-', 3) customers_email = customers_array[i]['mail'] sender_email = '*****@*****.**' customers_name = customers_array[i]['surname'] customers_first_name = customers_array[i]['name'] subject = 'Vos offres' separator = ', ' adapted_offers = separator.join(adapted_offers_array) logo_url = 'https://i.ibb.co/9wKPR0S/bankeschon-logo.png' html = '''
import os import psycopg2 from functions import get_env, query_to_array get_env('database_credentials.env') connection = psycopg2.connect(database=os.getenv('DB_NAME'), user=os.getenv('DB_USER'), password=os.getenv('DB_USER_PASSWORD'), host=os.getenv('DB_HOST'), port=os.getenv('DB_PORT')) query = '''SELECT * FROM history WHERE order by id''' not_accepted_array = [] query_to_array(connection, not_accepted_array, query) length = len(not_accepted_array) for i in range(0, length): print(not_accepted_array[i]) print(length)
#! /usr/bin/env python import datetime import json import os import psycopg2 from functions import get_env, query_to_array get_env('database_credentials.env') connection = psycopg2.connect(database=os.getenv('DB_NAME'), user=os.getenv('DB_USER'), password=os.getenv('DB_USER_PASSWORD'), host=os.getenv('DB_HOST'), port=os.getenv('DB_PORT')) query = '''SELECT * FROM prospects WHERE last_contact < CURRENT_DATE - INTERVAL '1 month' AND is_customer = 0 ORDER BY id''' customers_to_contact = [] query_to_array(connection, customers_to_contact, query) length = len(customers_to_contact) for i in range(0, length): customers_json = json.dumps(customers_to_contact[i], default=str) print(customers_json)