<commit_before>from flask import Flask, jsonify, request
from pushbullet import PushBullet
import json, urllib2, os

from utils import jsonp
from models import is_safe

from flask.ext.mandrill import Mandrill

app = Flask(__name__)
app.config.from_object('settings')

mandrill = Mandrill(app)

def geocode_ip(ip_addr):
    """ Geocodes a given IP Address """
    data = json.load(urllib2.urlopen("http://ip-api.com/json/%s" % ip_addr))
    print "Geocoded data: %s" % data
    return data

def send_push(pushbullet_token, message):
    """ Sends a foo location to Pushbullet """
    pb = PushBullet(pushbullet_token)
    pb.push_address("Login from suspicious location detected!", "40.4086, -3.6922")

@app.route("/test/push")
def token_push():
    send_push(os.environ.get('PUSHBULLET_TOKEN'), 'foo')
    return "push sent"

@app.route("/test/ip")
def ip_locate():
    if len(request.access_route) > 1:
        ip = request.access_route[-1]
    else:
        ip = request.access_route[0]
    return jsonify(ip=geocode_ip(ip), route=request.access_route)

@app.route('/')
def hello():
    return "Hello World!"

@app.route('/auth', methods=['POST'])
@jsonp
def auth():
    return jsonify(safe=is_safe(request.form, mandrill)) # ugh

@app.route('/config')
def config():
    if request.method == 'GET':
        return jsonify(data=None)
    return jsonify(status='ok')

if __name__ == '__main__':
    app.debug = True
    app.run()<commit_msg>Use first IP in access route<commit_after>from flask import Flask, jsonify, request
from pushbullet import PushBullet
import json, urllib2, os

from utils import jsonp
from models import is_safe

from flask.ext.mandrill import Mandrill

app = Flask(__name__)
app.config.from_object('settings')

mandrill = Mandrill(app)

def geocode_ip(ip_addr):
    """ Geocodes a given IP Address """
    data = json.load(urllib2.urlopen("http://ip-api.com/json/%s" % ip_addr))
    print "Geocoded data: %s" % data
    return data

def send_push(pushbullet_token, message):
    """ Sends a foo location to Pushbullet """
    pb = PushBullet(pushbullet_token)
    pb.push_address("Login from suspicious location detected!", "40.4086, -3.6922")

@app.route("/test/push")
def token_push():
    send_push(os.environ.get('PUSHBULLET_TOKEN'), 'foo')
    return "push sent"

@app.route("/test/ip")
def ip_locate():
    ip = request.access_route[0]
    return jsonify(ip=geocode_ip(ip), route=request.access_route)

@app.route('/')
def hello():
    return "Hello World!"

@app.route('/auth', methods=['POST'])
@jsonp
def auth():
    return jsonify(safe=is_safe(request.form, mandrill)) # ugh

@app.route('/config')
def config():
    if request.method == 'GET':
        return jsonify(data=None)
    return jsonify(status='ok')

if __name__ == '__main__':
    app.debug = True
    app.run()
{'fraction_non_alphanumeric': 0.14499465621660135, 'fraction_numerical': 0.010687566797292483, 'mean_word_length': 4.209647495361781, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1701752', 'n_tokens_mistral': 999, 'n_tokens_neox': 971, 'n_words': 236}