Skip to content

Instantly share code, notes, and snippets.

@aborruso
Created March 19, 2014 09:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aborruso/9638501 to your computer and use it in GitHub Desktop.
Save aborruso/9638501 to your computer and use it in GitHub Desktop.
import logging, importio, threading, json
# We define a latch class as python doesn't have a counting latch built in
class _Latch(object):
def __init__(self, count=1):
self.count = count
self.lock = threading.Condition()
def countDown(self):
with self.lock:
self.count -= 1
if self.count <= 0:
self.lock.notifyAll()
def await(self):
with self.lock:
while self.count > 0:
self.lock.wait()
logging.basicConfig(level=logging.INFO)
# Initialise the library
client = importio.ImportIO(host="https://query.import.io", userId="465f52fd-1413-4cfa-a705-a3c5630267f0", apiKey="My_Key")
client.connect()
# Use a latch to stop the program from exiting
latch = _Latch(1)
def callback(query, message):
if message["type"] == "MESSAGE":
print "Got data!"
print json.dumps(message["data"],indent = 4)
if query.finished(): latch.countDown()
# Query for tile benisequestraticonfiscati_01
client.query({
"connectorGuids": [
"cb7e9ac4-d121-466e-9217-1478374ff64c"
],
"input": {
"webpage/url": "My_URL"
}
}, callback)
# Wait until queries complete
latch.await()
client.disconnect()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment