<commit_before>package cmds

import "github.com/weirdtales/senor-rosado/slack"


// Weather reports the current forecast for an airport code
func Weather(m slack.Message, r *slack.Reply) error {
    r.Text = "YmmL??"
    return nil
}

// Hello says hello
func Hello(m slack.Message, r *slack.Reply) error {
    r.Text = "Hola"
    return nil
}
<commit_msg>add lat long query via google<commit_after>package cmds

import "fmt"
import "os"

import "encoding/json"
import "io/ioutil"
import "net/http"

import "github.com/jmespath/go-jmespath"
import "github.com/weirdtales/senor-rosado/slack"


// Weather reports the current forecast for an airport code
func Weather(m slack.Message, r *slack.Reply) error {
    token := os.Getenv("DARKSKY_API")
    if token == "" {
        r.Text = "I got no DARKSKY_API token in my env. Sort it."
        return nil
    }

    if m.Subcommand == "" {
        r.Text = "Specify a location, fool, then I can help."
        return nil
    }

    lat, lng, err := getLongLat(m.Subcommand)
    if err != nil {
        return err
    }
    fmt.Printf("lat=%f lng=%f\n\n", lat, lng)
    return nil
}

func getLongLat(q string) (lat float64, lng float64, err error) {
    url := fmt.Sprintf("http://maps.googleapis.com/maps/api/geocode/json?address=%s&sensor=false", q)
    r, err := http.Get(url)
    if err != nil {
        return
    }
    if r.StatusCode != 200 {
        err = fmt.Errorf("Error: status code: %d", r.StatusCode)
        return
    }

    body, err := ioutil.ReadAll(r.Body)
    defer r.Body.Close()
    if err != nil {
        return
    }

    var data interface{}
    err = json.Unmarshal(body, &data)
    if err != nil {
        return
    }

    v, err := jmespath.Search("results[0].geometry.location", data)
    if err != nil {
        return
    }
    vals := v.(map[string]interface{})

    return vals["lat"].(float64), vals["lng"].(float64), nil
}

{'fraction_non_alphanumeric': 0.13693599160545644, 'fraction_numerical': 0.0062959076600209865, 'mean_word_length': 2.5845864661654137, 'pattern_counts': {'":': 0, '<': 3, '<?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': '603537', 'n_tokens_mistral': 685, 'n_tokens_neox': 660, 'n_words': 179}