Skip to content

Instantly share code, notes, and snippets.

View lloydw's full-sized avatar

Lloyd Weehuizen lloydw

View GitHub Profile
from urllib2 import urlopen
import csv
import os
import tempfile
def importUrl(url):
response = urlopen(url)
code = response.getcode()
if code != 200:
raise Exception('Invalid response', code)
@lloydw
lloydw / requery.py
Last active August 2, 2019 12:58
Simple query object for combining multiple redash queries
#
# Simple query object for combining multiple redash queries
#
# Example usage:
# Find all users who have logged in in the last 8 weeks who have sent an email by analysing the logstash logs
# Then group the results by the week they signed up on and their emailed yes/no status
#
# import requery
# userQuery = 'SELECT * FROM user WHERE lastSeen > DATE_SUB(NOW(), INTERVAL 8 WEEK)'
# emailQuery = '{ "index" : "logstash-*", "query": { "query_string": { "query": "action:sendEmail" } }, "size" : 1000 }
@lloydw
lloydw / gist:865bbcc0508288576648bff17c871234
Created May 26, 2016 22:27
ElasticSearch sample outputs
import json
data1 = json.loads("""{
"took": 19,
"timed_out": false,
"_shards": {
"total": 40,
"successful": 40,
"failed": 0
},