Skip to content

Instantly share code, notes, and snippets.

View craigderington's full-sized avatar
🚀
Automate Everything

Craig Derington craigderington

🚀
Automate Everything
View GitHub Profile
#!/usr/bin/env python
import argparse
import csv
import json
from types import *
def main():
from random import randrange
def get_random_ip():
"""
Create a random IP address
:return: ipv4 address
"""
return ".".join(str(randrange(1, 255)) for i in range(4))
@craigderington
craigderington / send_email.py
Last active January 8, 2019 19:30
Sending email with the Python standard library
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
# sender details
sender = '[email protected]'
recipients = ['[email protected]', '[email protected]', '[email protected]', ]
# create a MIME obj
msg = MIMEMultipart()
@craigderington
craigderington / check.py
Created December 13, 2018 19:23
Check our Data
if request.method == 'POST':
form_data = {
"message_id": request.form.get('Message-Id', None),
"x_mail_gun_sid": request.form.get('X-Mailgun-Sid', None),
"domain": request.form.get('domain', 'email.com'),
"event": request.form.get('event', 'delivered'),
"timestamp": request.form.get('timestamp', None),
"recipient": request.form.get('recipient', None),
"signature": request.form.get('signature', None),
@craigderington
craigderington / app.py
Created December 13, 2018 19:21
Flask REST Mailgun Webhook v3
try:
lead = db.session.query(Lead).filter(
Lead.email_addr == mg_recipient
).first()
if lead:
email = lead.email
lead_id = lead.id
event = form_data['event']
@craigderington
craigderington / verify.py
Created December 13, 2018 19:20
Signature Verification
import hashlib
import hmac
def verify(api_key, token, timestamp, signature):
hmac_digest = hmac.new(key=mailgun_api_key,
msg='{}{}'.format(timestamp, token).encode('utf-8'),
digestmod=hashlib.sha256).hexdigest()
return hmac.compare_digest(signature, hmac_digest)
@craigderington
craigderington / app.py
Created December 13, 2018 19:19
Flask REST Mailgun Webhook v2
@app.route('/api/v1/wh/mg/lead/email/delivered', methods=['POST'])
def lead_email_delivered():
"""
The lead email delivered webhook.
:return: json
"""
if request.method == 'POST':
form_data = {
"message_id": request.form.get('Message-Id', None),
@craigderington
craigderington / app.py
Last active December 13, 2018 19:22
Flask REST Mailgun Webhook app scaffold
from from import Flask, render_template, Response, jsonify, url_for, flash
from flask_sqlalchemy import SQLAlchemy
from flask_httpauth import HTTPBasicAuth
from models import User, Lead, Company
import config
app = Flask(__name__)
db = SQLAlchemy(app)
auth = HTTPBasicAuth()
DEBUG = True
@craigderington
craigderington / monitrc
Last active November 1, 2018 21:18 — forked from franck/monitrc
Ubuntu Monit config (Apache, RabbitMQ, MySQL, MongoDB, Redis)
###############################################################################
## Monit control file
###############################################################################
##
## Comments begin with a '#' and extend through the end of the line. Keywords
## are case insensitive. All path's MUST BE FULLY QUALIFIED, starting with '/'.
##
## Below you will find examples of some frequently used statements. For
## information about the control file and a complete list of statements and
## options, please have a look in the Monit manual.
@craigderington
craigderington / manage.py
Created October 9, 2018 19:52
Manage.py module for Celery project
import sys
import os
from click import echo
from flask_mail import Mail
from app import create_app
app = create_app('development')
app.config.update(dict(
MAIL_SERVER='localhost',
MAIL_PORT=1025,