<commit_before>from flask import Flask, render_template
from flask.ext.script import Manager
from flask.ext.bootstrap import Bootstrap
import pandas as pd
import boto
import io
import os
import re


app = Flask(__name__)
bootstrap = Bootstrap(app)
manager = Manager(app)


def load_data_from_S3():
    print('Loading data from S3...')

    # Load the data from S3
    #https://s3-us-west-1.amazonaws.com/bike-parking/sf_bike_public_parking.csv
    s3_bucket = 'bike-parking'
    s3_key = 'sf_bike_public_parking.csv'

    conn = boto.connect_s3()

    bucket = conn.get_bucket(s3_bucket)
    str_data = bucket.get_key(s3_key).get_contents_as_string()
    str_data = io.StringIO(unicode(str_data, 'utf-8'))

    df = pd.read_csv(str_data)
    lat_lng_values = df.COORDINATES.apply(parse_lat_long_values, axis=0)

def parse_lat_long_values(coord_str, axis):
    RE = r'\((?P<lat>-?\d+\.\d+)\,\s*(?P<lng>-?\d+\.\d+)\)'
    m = re.search(RE, coord_str)
    if m and len(m.groups()) == 2:
        lat, lng = lat_lng_to_numeric(m.group('lat'), m.group('lng'))
        return (lat, lng)
    else:
        print('Unable to parse coordinates string: {}'.format(coord_str))
        return (None, None)

def lat_lng_to_numeric(lat_str, lng_str):
    try:
        lat = float(lat_str)
        lng = float(lng_str)
    except:
        print('Unable to convert {}, {} to numeric values'.
              format(lat_str, lng_str))
        lat, lng = None, None
    return lat, lng
<commit_msg>Use requests<commit_after>import os
import io
import re

import requests

import pandas as pd

from flask import Flask, render_template
from flask.ext.script import Manager
from flask.ext.bootstrap import Bootstrap


app = Flask(__name__)
bootstrap = Bootstrap(app)
manager = Manager(app)


def load_data_from_S3():
    print('Loading data from S3...')

    url = 'https://s3-us-west-1.amazonaws.com/bike-parking/sf_bike_public_parking.csv'
    csv_str = requests.get(url).content
    csv_buffer = io.StringIO(unicode(csv_str, 'utf-8'))
    df = pd.read_csv(csv_buffer)
    lat_lng_values = df.COORDINATES.apply(parse_lat_long_values, axis=0)

def parse_lat_long_values(coord_str, axis):
    RE = r'\((?P<lat>-?\d+\.\d+)\,\s*(?P<lng>-?\d+\.\d+)\)'
    m = re.search(RE, coord_str)
    if m and len(m.groups()) == 2:
        lat, lng = lat_lng_to_numeric(m.group('lat'), m.group('lng'))
        return (lat, lng)
    else:
        print('Unable to parse coordinates string: {}'.format(coord_str))
        return (None, None)

def lat_lng_to_numeric(lat_str, lng_str):
    try:
        lat = float(lat_str)
        lng = float(lng_str)
    except:
        print('Unable to convert {}, {} to numeric values'.
              format(lat_str, lng_str))
        lat, lng = None, None
    return lat, lng

{'fraction_non_alphanumeric': 0.13816738816738816, 'fraction_numerical': 0.007215007215007215, 'mean_word_length': 3.253067484662577, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '39312', 'n_tokens_mistral': 1042, 'n_tokens_neox': 1006, 'n_words': 219}