Giter VIP home page Giter VIP logo

django-sacredheartcs's People

Watchers

 avatar  avatar

django-sacredheartcs's Issues

Synchronize contacts

Overview

Figure out optimal strategy for synchronizing contacts between CC and backup db. Recommended approach appears to be bulk export activities:

Strategy

  • Bulk export on a weekly/bi-weekly cron.
    • Create bulk_export activity (see "Creating a Export Contacts Activity" in the API docs)
    • Check status for 201 (which denotes export succeeded)
    • Once status is 201, call get_activity and extract file URI for the file
    • Download file using requests with Basic Auth (CTCT API does not provide a call for downloading bulk exports)
    • Archive contacts whose email is no longer among Active contacts; create contact entries for new emails.
  • Alternate strategy: Create backup db using an initial bulk export, then use API call for searching for contacts by last updated

Code

To download bulk export CSV, need to use requests with Basic Auth

import requests 
from requests.auth import HTTPBasicAuth
from sacredheartcs.api_key import API_KEY, USER, PASSWORD
cc_user = '%'.join((API_KEY, USER))
#TODO: Get activity record, which contains URI to bulk export CSV
file_name = activity['file_name']
url = 'https://api.constantcontact.com' + file_name
response = requests.get(url, auth=HTTPBasicAuth(cc_user, PASSWORD))

Refactors

  • package requests-based calls (needed for downloads) and official client API into a single Facade api
  • move retries (and all code related to interacting with API) to fetch_bulk_contacts_export

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.