예제 #1
0
"""
from random import randint
from time import time

from django.conf import settings
from django.core.cache import cache

import requests
from django_statsd.clients import statsd
from FuelSDK import ET_Client, ET_DataExtension_Row, ET_TriggeredSend

from basket.news.backends.common import get_timer_decorator, NewsletterException, \
                                 NewsletterNoResultsException


time_request = get_timer_decorator('news.backends.sfmc')


HERD_TIMEOUT = 60
AUTH_BUFFER = 300  # 5 min
MAX_BUFFER = HERD_TIMEOUT + AUTH_BUFFER


class ETRefreshClient(ET_Client):
    token_cache_key = 'backends:sfmc:auth:tokens'
    authTokenExpiresIn = None
    token_property_names = [
        'authToken',
        'authTokenExpiration',
        'internalAuthToken',
        'refreshKey',
예제 #2
0
파일: sfmc.py 프로젝트: mozmar/basket
"""
from random import randint
from time import time

from django.conf import settings
from django.core.cache import cache

import requests
from django_statsd.clients import statsd
from FuelSDK import ET_Client, ET_DataExtension_Row, ET_TriggeredSend

from basket.news.backends.common import get_timer_decorator, NewsletterException, \
                                 NewsletterNoResultsException


time_request = get_timer_decorator('news.backends.sfmc')


HERD_TIMEOUT = 60
AUTH_BUFFER = 300  # 5 min
MAX_BUFFER = HERD_TIMEOUT + AUTH_BUFFER


class ETRefreshClient(ET_Client):
    token_cache_key = 'backends:sfmc:auth:tokens'
    authTokenExpiresIn = None
    token_property_names = [
        'authToken',
        'authTokenExpiration',
        'internalAuthToken',
        'refreshKey',
예제 #3
0
def cast_lower(value):
    return value.lower()


def strip_whitespace(value):
    """if the value can be stripped of leading/trailing whitespace, do it"""
    try:
        value = value.strip()
    except AttributeError:
        pass

    return value


time_request = get_timer_decorator("news.backends.sfdc")
LAST_NAME_DEFAULT_VALUE = "_"
SFDC_SESSION_CACHE_KEY = "backends:sfdc:auth:sessionid"
AUTH_BUFFER = 300  # 5 min
HERD_TIMEOUT = 60
FIELD_MAP = {
    "id": "Id",
    "record_type": "RecordTypeId",
    "email": "Email",
    "email_id": "Email_Id__c",
    "first_name": "FirstName",
    "last_name": "LastName",
    "format": "Email_Format__c",
    "country": "MailingCountryCode",
    "postal_code": "MailingPostalCode",
    "lang": "Email_Language__c",
예제 #4
0
from django.conf import settings
from django.core.cache import cache
from django_statsd.clients import statsd

import sentry_sdk
from requests_oauthlib import OAuth2Session
from oauthlib.oauth2 import BackendApplicationClient

from basket.news.backends.common import get_timer_decorator
from basket.news.country_codes import SFDC_COUNTRIES_LIST, convert_country_3_to_2
from basket.news.newsletters import (
    newsletter_slugs,
    is_supported_newsletter_language,
)

time_request = get_timer_decorator("news.backends.ctms")


class CTMSError(Exception):
    """Base class for exceptions raised by CTMS functions."""


# Map CTMS group / name pairs to basket flat format names
# Missing basket names from pre-2021 SFDC integration:
#  record_type - Identify MoFo donors with an associated opportunity
#  postal_code - Extra data for MoFo petitions
#  source_url - Set-once source URL, now per-newsletter
#  fsa_* - Firefox Student Ambassadors, deprecated
#  cv_* - Common Voice, moved to MoFo
#  payee_id - Stripe payee ID for MoFo donations
#  fxa_last_login - Imported into Acoustic periodically from FxA