예제 #1
0
파일: ongair.py 프로젝트: ongair/whatsapp
    def onFailure(self, entity):
        self.connected = False
        self.phone_number = self.getProp('ongair.account')
        logger.info("Login Failed - %s, reason: %s" %(self.phone_number, entity.getReason()))

        # TODO: Where is the notification?
        if entity.getReason() == "not-authorized":
            _session = self.session()
            account = _session.query(Account).filter_by(phone_number=self.phone_number).scalar()
            account.setup = False       
            notify_slack("Account %s (%s) failed authentication. " %(account.name, account.phone_number))     
            _session.commit()

        sys.exit(0)  # does not restart
예제 #2
0
파일: agg.py 프로젝트: williamlief/COVID-19
def main(cal_path, bay_path, scc_path, hook_path=None):
    """
    Fetch data and write a cleaned csv for each of California, 
    the Bay Area, and Santa Clara County. Send a slack notification if
    hook_path is provided.
    """

    cases, deaths, tests = fetch_data(hook_path)

    cal_agg(cases, deaths, tests, cal_path)
    bay_agg(cases, deaths, tests, bay_path)
    scc_agg(cases, deaths, tests, scc_path)

    if hook_path:
        notify_slack('updated COVID-19 data', hook_path)
예제 #3
0
    def onFailure(self, entity):
        self.connected = False
        self.phone_number = self.getProp('ongair.account')
        logger.info("Login Failed - %s, reason: %s" %
                    (self.phone_number, entity.getReason()))

        # TODO: Where is the notification?
        if entity.getReason() == "not-authorized":
            _session = self.session()
            account = _session.query(Account).filter_by(
                phone_number=self.phone_number).scalar()
            account.setup = False
            notify_slack("Account %s (%s) failed authentication. " %
                         (account.name, account.phone_number))
            _session.commit()

        sys.exit(0)  # does not restart
예제 #4
0
#!/usr/bin/env python

from config import *
from util import notify_slack
from citadels import check_citadels
from pos import check_pos

if __name__ == '__main__':
    messages = []
    try:
        messages += check_citadels()
        messages += check_pos()
    except Exception, e:
        if DEBUG:
            raise
        if e.message:
            messages.append(e.message)
        else:
            raise
    if messages:
        messages.insert(
            0, ' Upcoming {} Structure Maintenence Tasks'.format(
                CORPORATION_NAME))
        notify_slack(sorted(messages))
예제 #5
0
#!/usr/bin/env python

from config import *
from util import notify_slack
from citadels import check_citadels
from pos import check_pos

if __name__ == '__main__':
    messages = []
    messages += check_citadels(CORPORATION_ID)
    messages += check_pos()
    if messages:
        messages.insert(0, 'Upcoming Structure Maintenence Tasks')
        notify_slack(messages)
예제 #6
0
def authorization_notification(payload):

    amzn_id = payload["AuthorizationNotification"]["AuthorizationDetails"][
        "AmazonAuthorizationId"]

    # trim everything after the last dash - seems like there should be a more
    # straightforward way to do this
    match = re.search("^(.*)[-]", amzn_id)
    amzn_id = match.group(1)
    logging.info(amzn_id)

    client = AmazonPayClient(
        mws_access_key=MWS_ACCESS_KEY,
        mws_secret_key=MWS_SECRET_KEY,
        merchant_id=AMAZON_MERCHANT_ID,
        region="na",
        currency_code="USD",
        sandbox=AMAZON_SANDBOX,
    )
    response = client.get_order_reference_details(
        amazon_order_reference_id=amzn_id)
    response = response.to_dict()

    logging.info(json.dumps(response, indent=4))

    details = response["GetOrderReferenceDetailsResponse"][
        "GetOrderReferenceDetailsResult"]["OrderReferenceDetails"]

    amount = details["OrderTotal"]["Amount"]
    logging.info(amount)
    name = HumanName(details["Buyer"]["Name"])
    first_name = name.first
    last_name = name.last
    email = details["Buyer"]["Email"]
    zipcode = get_zip(details=details)
    description = details["SellerOrderAttributes"]["StoreName"]

    logging.info("----Getting contact....")
    contact = Contact.get_or_create(email=email,
                                    first_name=first_name,
                                    last_name=last_name,
                                    zipcode=zipcode)
    logging.info(contact)

    if contact.first_name == "Subscriber" and contact.last_name == "Subscriber":
        logging.info(f"Changing name of contact to {first_name} {last_name}")
        contact.first_name = first_name
        contact.last_name = last_name
        contact.save()

    if contact.first_name != first_name or contact.last_name != last_name:
        logging.info(
            f"Contact name doesn't match: {contact.first_name} {contact.last_name}"
        )

    if zipcode and not contact.created and contact.mailing_postal_code != zipcode:
        contact.mailing_postal_code = zipcode
        contact.save()

    logging.info("----Adding opportunity...")

    opportunity = Opportunity(contact=contact, stage_name="Closed Won")
    opportunity.amount = amount
    opportunity.description = description
    opportunity.lead_source = "Amazon Alexa"
    opportunity.amazon_order_id = amzn_id
    opportunity.campaign_id = AMAZON_CAMPAIGN_ID
    opportunity.name = (
        f"[Alexa] {contact.first_name} {contact.last_name} ({contact.email})")
    opportunity.save()
    logging.info(opportunity)
    notify_slack(contact=contact, opportunity=opportunity)
    if contact.duplicate_found:
        send_multiple_account_warning(contact)
예제 #7
0
def add_donation(form=None,
                 customer=None,
                 donation_type=None,
                 bad_actor_request=None):
    """
    Add a contact and their donation into SF. This is done in the background
    because there are a lot of API calls and there's no point in making the
    payer wait for them. It sends a notification about the donation to Slack (if configured).
    """
    bad_actor_response = BadActor(bad_actor_request=bad_actor_request)
    quarantine = bad_actor_response.quarantine

    form = clean(form)
    first_name = form["first_name"]
    last_name = form["last_name"]
    period = form["installment_period"]
    email = form["stripeEmail"]
    zipcode = form["zipcode"]

    logging.info("----Getting contact....")
    contact = Contact.get_or_create(email=email,
                                    first_name=first_name,
                                    last_name=last_name,
                                    zipcode=zipcode)
    logging.info(contact)

    if contact.first_name == "Subscriber" and contact.last_name == "Subscriber":
        logging.info(f"Changing name of contact to {first_name} {last_name}")
        contact.first_name = first_name
        contact.last_name = last_name
        contact.mailing_postal_code = zipcode
        contact.save()

    if contact.first_name != first_name or contact.last_name != last_name:
        logging.info(
            f"Contact name doesn't match: {contact.first_name} {contact.last_name}"
        )

    if zipcode and not contact.created and contact.mailing_postal_code != zipcode:
        contact.mailing_postal_code = zipcode
        contact.save()

    if contact.duplicate_found:
        send_multiple_account_warning(contact)

    if period is None:
        logging.info("----Creating one time payment...")
        opportunity = add_opportunity(contact=contact,
                                      form=form,
                                      customer=customer,
                                      quarantine=quarantine)
        try:
            charge(opportunity)
            logging.info(opportunity)
            notify_slack(contact=contact, opportunity=opportunity)
        except ChargeException as e:
            e.send_slack_notification()
        except QuarantinedException:
            bad_actor_response.notify_bad_actor(transaction_type="Opportunity",
                                                transaction=opportunity)
        return True

    elif donation_type == "circle":
        logging.info("----Creating circle payment...")
        rdo = add_circle_membership(contact=contact,
                                    form=form,
                                    customer=customer,
                                    quarantine=False)
    else:
        logging.info("----Creating recurring payment...")
        rdo = add_recurring_donation(contact=contact,
                                     form=form,
                                     customer=customer,
                                     quarantine=quarantine)

    # get opportunities
    opportunities = rdo.opportunities()
    today = datetime.now(tz=ZONE).strftime("%Y-%m-%d")
    opp = [
        opportunity for opportunity in opportunities
        if opportunity.expected_giving_date == today
    ][0]
    try:
        charge(opp)
        logging.info(rdo)
        notify_slack(contact=contact, rdo=rdo)
    except ChargeException as e:
        e.send_slack_notification()
    except QuarantinedException:
        bad_actor_response.notify_bad_actor(transaction_type="RDO",
                                            transaction=rdo)
    return True
예제 #8
0
def add_business_membership(
    form=None,
    customer=None,
    donation_type="business_membership",
    bad_actor_request=None,
):
    """
    Adds a business membership. Both single and recurring.

    It will look for a matching Contact (or create one). Then it will look for a
    matching Account (or create one). Then it will add the single or recurring donation
    to the Account. Then it will add an Affiliation to link the Contact with the
    Account. It sends a notification to Slack (if configured). It will send email
    notification about the new membership.

    """

    form = clean(form)

    first_name = form["first_name"]
    last_name = form["last_name"]
    email = form["stripeEmail"]

    website = form["website"]
    business_name = form["business_name"]
    shipping_city = form["shipping_city"]
    shipping_street = form["shipping_street"]
    shipping_state = form["shipping_state"]
    shipping_postalcode = form["shipping_postalcode"]

    bad_actor_response = BadActor(bad_actor_request=bad_actor_request)
    quarantine = bad_actor_response.quarantine

    logging.info("----Getting contact....")
    contact = Contact.get_or_create(email=email,
                                    first_name=first_name,
                                    last_name=last_name)
    if contact.work_email is None:
        contact.work_email = email
        contact.save()
    logging.info(contact)

    if contact.first_name == "Subscriber" and contact.last_name == "Subscriber":
        logging.info(f"Changing name of contact to {first_name} {last_name}")
        contact.first_name = first_name
        contact.last_name = last_name
        contact.save()

    if contact.first_name != first_name or contact.last_name != last_name:
        logging.info(
            f"Contact name doesn't match: {contact.first_name} {contact.last_name}"
        )

    logging.info("----Getting account....")

    account = Account.get_or_create(
        record_type_name="Organization",
        website=website,
        name=business_name,
        shipping_street=shipping_street,
        shipping_city=shipping_city,
        shipping_state=shipping_state,
        shipping_postalcode=shipping_postalcode,
    )
    logging.info(account)

    if form["installment_period"] not in ["yearly", "monthly"]:
        raise Exception("Business membership must be either yearly or monthly")

    logging.info("----Creating recurring business membership...")
    rdo = add_business_rdo(account=account,
                           form=form,
                           customer=customer,
                           quarantine=False)
    logging.info(rdo)

    logging.info("----Getting affiliation...")

    affiliation = Affiliation.get_or_create(account=account,
                                            contact=contact,
                                            role="Business Member Donor")
    logging.info(affiliation)

    send_email_new_business_membership(account=account, contact=contact)

    # get opportunities
    opportunities = rdo.opportunities()
    today = datetime.now(tz=ZONE).strftime("%Y-%m-%d")
    opp = [
        opportunity for opportunity in opportunities
        if opportunity.expected_giving_date == today
    ][0]
    try:
        charge(opp)
        notify_slack(account=account, contact=contact, rdo=rdo)
    except ChargeException as e:
        e.send_slack_notification()
    except QuarantinedException:
        bad_actor_response.notify_bad_actor(transaction_type="RDO",
                                            transaction=rdo)

    if contact.duplicate_found:
        send_multiple_account_warning(contact)

    return True
예제 #9
0
파일: app.py 프로젝트: mgmtadmin/donations
def add_donation(form=None, customer=None):
    """
    Add a contact and their donation into SF. This is done in the background
    because there are a lot of API calls and there's no point in making the
    payer wait for them. It sends a notification about the donation to Slack (if configured).
    """
    form = clean(form)
    first_name = form["first_name"]
    last_name = form["last_name"]
    period = form["installment_period"]
    email = form["stripeEmail"]
    zipcode = form["zipcode"]

    logging.info("----Getting contact....")
    contact = Contact.get_or_create(email=email,
                                    first_name=first_name,
                                    last_name=last_name,
                                    zipcode=zipcode)
    logging.info(contact)

    if contact.first_name == "Subscriber" and contact.last_name == "Subscriber":
        logging.info(f"Changing name of contact to {first_name} {last_name}")
        contact.first_name = first_name
        contact.last_name = last_name
        contact.mailing_postal_code = zipcode
        contact.save()

    if contact.first_name != first_name or contact.last_name != last_name:
        logging.info(
            f"Contact name doesn't match: {contact.first_name} {contact.last_name}"
        )

    if zipcode and not contact.created and contact.mailing_postal_code != zipcode:
        contact.mailing_postal_code = zipcode
        contact.save()

    if period is None:
        logging.info("----Creating one time payment...")
        opportunity = add_opportunity(contact=contact,
                                      form=form,
                                      customer=customer)
        charge(opportunity)
        logging.info(opportunity)
        notify_slack(contact=contact, opportunity=opportunity)
    else:
        logging.info("----Creating recurring payment...")
        rdo = add_recurring_donation(contact=contact,
                                     form=form,
                                     customer=customer)
        # get opportunities
        opportunities = rdo.opportunities()
        today = datetime.now(tz=ZONE).strftime("%Y-%m-%d")
        opp = [
            opportunity for opportunity in opportunities
            if opportunity.expected_giving_date == today
        ][0]
        charge(opp)
        logging.info(rdo)
        notify_slack(contact=contact, rdo=rdo)

    if contact.duplicate_found:
        send_multiple_account_warning(contact)

    return True