Skip to content

Instantly share code, notes, and snippets.

@andy-pi
andy-pi / get_subscription_id_from_Chargify_by_email.py
Last active May 13, 2016 23:33
List all your chargify customers, and find the subscription id, given an email address
from chargify import Chargify # import this module https://github.com/hindsightlabs/chargify-python
CHARGIFY_API_KEY="MY_API_KEY" # insert your api key here
CHARGIFY_SUBDOMAIN="MY_SUBDOMAIN" # insert your subdomain here
chargify = Chargify(CHARGIFY_API_KEY,CHARGIFY_SUBDOMAIN)
def get_subscription_id_from_Chargify(email):
'''
Interface with chargify API to get their subscription_id, given a customer email address
'''
@andy-pi
andy-pi / chargify_webhook_endpoint.py
Last active February 27, 2017 16:47
How to Recieive a webhook from Chargify to a Flask API endpoint
from flask import Flask, request, Response, abort
from flask.ext.restful import Api, Resource,
from hashlib import sha256
import hmac, redis
CHARGIFY_SHARED_KEY= "XYZ789"
REDIS_HOST="ip_address"
REDIS_PORT="1234"
FLASK_HOST="ip_address"
FLASK_PORT="1234"
import pandas as pd
import glob
csv_files = glob.glob("/*.CSV") # get list of files in directory
for csv_file in csv_files: # loop over all files in directory
data = pd.read_csv(csv_file) # load csv file
data = data[data["Fee"] != 0] # remove all rows where fee=0 (aka non purchases)
data = data[data["Gross"] > 0] # remove all rows where income < 0 (i.e. -ve)
data = data[['Subject', 'Gross']] # choose only subject and gross income columns