Skip to content

Instantly share code, notes, and snippets.

@yannski
Created February 7, 2017 10:46
Show Gist options
  • Save yannski/f6a3ff936121d11be2b1b01ce202af25 to your computer and use it in GitHub Desktop.
Save yannski/f6a3ff936121d11be2b1b01ce202af25 to your computer and use it in GitHub Desktop.
func LastMinutesTweets() ([]InfluxValue, error) {
queryString := "SELECT SUM('value') FROM 'tweets'"
queryString += " WHERE hashtag = '" + config.E["HASHTAG"] + "'"
queryString += " AND time >= now() - 60m"
queryString += " GROUP BY time(1m) fill(none) ORDER BY time DESC LIMIT 60"
return executeQuery(queryString)
}
func executeQuery(queryString string) ([]InfluxValue, error) {
client, _ := influx.NewHTTPClient(influx.HTTPConfig{
Addr: config.InfluxConnectionInformation.Host,
Username: config.InfluxConnectionInformation.User,
Password: config.InfluxConnectionInformation.Password,
})
defer client.Close()
response, _ := client.Query(influx.Query{
Command: queryString,
Database: config.InfluxConnectionInformation.Database,
})
if response.Error() != nil {
panic(response.Error())
}
return convertResults(response)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment