<commit_before>import json
import os
from datetime import date

import boto3
import requests
from googlemaps import Client
from twilio.rest import TwilioRestClient

s3 = boto3.resource('s3')


def run_poll(event, context):
    """ Update S3 with latest trackpoints from Spot. """
    s3_history = get_history_from_s3()
    s3_latest_timeStamp = s3_history[-1]['timeStamp']
    spot_new = get_history_from_spot( s3_latest_timeStamp )
    if spot_new:
        combined_history = s3_history + spot_new
        write_to_s3(combined_history)
        notify_by_text(s3_history[-1], combined_history[-1])
    else:
        pass


def latest_status():
    """ Return a textual summary of the latest trackpoint. """
    latest = get_history_from_s3()[-1]
    return '{}\'s last tracked location was {} at {}.'.format(latest['name'], latest['location'], latest['timeStamp'])


def is_newer_than(s3_latest_timeStamp, spot_message):
    return s3_latest_timeStamp < str(spot_message['dateTime'])


def get_history_from_spot(s3_latest_timeStamp):
    gmaps = _get_gmaps()
    def _build_track_point(spot_message):
        def _reverse_geocode(lat, lon):
            try:
                for addr in gmaps.reverse_geocode((lat, lon))[0]['address_components']:
                    if 'postal_town' in addr['types']:
                        return addr['long_name']
            except:<commit_msg>Support NZ geocoding<commit_after>import json
import os
from datetime import date

import boto3
import requests
from googlemaps import Client
from twilio.rest import TwilioRestClient

s3 = boto3.resource('s3')


def run_poll(event, context):
    """ Update S3 with latest trackpoints from Spot. """
    s3_history = get_history_from_s3()
    s3_latest_timeStamp = s3_history[-1]['timeStamp']
    spot_new = get_history_from_spot( s3_latest_timeStamp )
    if spot_new:
        combined_history = s3_history + spot_new
        write_to_s3(combined_history)
        notify_by_text(s3_history[-1], combined_history[-1])
    else:
        pass


def latest_status():
    """ Return a textual summary of the latest trackpoint. """
    latest = get_history_from_s3()[-1]
    return '{}\'s last tracked location was {} at {}.'.format(latest['name'], latest['location'], latest['timeStamp'])


def is_newer_than(s3_latest_timeStamp, spot_message):
    return s3_latest_timeStamp < str(spot_message['dateTime'])


def get_history_from_spot(s3_latest_timeStamp):
    gmaps = _get_gmaps()
    def _build_track_point(spot_message):
        def _reverse_geocode(lat, lon):
            try:
                #Hack
                googleResp = gmaps.reverse_geocode((lat, lon))[0]['address_components']
                for addr in googleResp:
                    if 'postal_town' in addr['types']:
                        return addr['long_name']
                for addr in googleResp:
                    if 'locality' in addr['types']:
                        return addr['long_name']
            except:
{'fraction_non_alphanumeric': 0.1016150740242261, 'fraction_numerical': 0.014804845222072678, 'mean_word_length': 3.112033195020747, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '1898400', 'n_tokens_mistral': 948, 'n_tokens_neox': 922, 'n_words': 212}