This repository has been archived by the owner on Nov 28, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/historics' into develop
- Loading branch information
Showing
21 changed files
with
986 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/bash | ||
ruby historics/$3.rb $1 $2 ${@:4} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# This script creates a new Historics query from a file containing CSDL. | ||
# | ||
# NB: Most of the error handling (exception catching) has been removed for | ||
# the sake of simplicity. Nearly everything in this library may throw | ||
# exceptions, and production code should catch them. See the documentation | ||
# for full details. | ||
# | ||
|
||
# Function to display usage instructions with an optional error message. | ||
def usage(message = '', end_of_story = true) | ||
puts message + '\n' unless message.length() == 0 | ||
puts | ||
puts 'Usage: create-from-csdl <username> <api_key> \\' | ||
puts ' <csdl_filename> <start> <end> <sources> <name> <sample>' | ||
puts | ||
puts 'Where: csdl_filename = the stream hash the query should run' | ||
puts ' start = the start date for the query (YYYYMMDDHHMMSS)' | ||
puts ' end = the end date for the query (YYYYMMDDHHMMSS)' | ||
puts ' sources = comma separated list of data sources (e.g. twitter)' | ||
puts ' name = a friendly name for the query' | ||
puts ' sample = the sample rate' | ||
puts | ||
puts 'Example' | ||
puts ' create-from-csdl csdl.txt 20120101000000 20120101235959 \\' | ||
puts ' twitter HistoricsQuery123 100' | ||
puts | ||
exit 1 unless not end_of_story | ||
end | ||
|
||
# Include the shared Env class | ||
require File.dirname(__FILE__) + '/env' | ||
|
||
# Create the env object. This reads the command line arguments, creates the | ||
# user object, and provides access to both along with helper functions. | ||
env = Env.new() | ||
|
||
# Check that we have enough arguments | ||
usage() unless env.args.size() == 6 | ||
|
||
# Read the arguments | ||
csdl_filename = env.args[0] | ||
start_date = env.args[1] | ||
end_date = env.args[2] | ||
sources = env.args[3].split(',') | ||
name = env.args[4] | ||
sample = env.args[5] | ||
|
||
# Parse the dates | ||
start_date = DateTime.strptime(start_date, '%Y%m%d%H%M%S') | ||
end_date = DateTime.strptime(end_date, '%Y%m%d%H%M%S') | ||
|
||
# Read the CSDL | ||
csdl = File.open(csdl_filename, 'r').read | ||
|
||
begin | ||
# Create the definition | ||
definition = env.user.createDefinition(csdl) | ||
|
||
# Create the Historics query | ||
historic = definition.createHistoric(start_date, end_date, sources, name, sample) | ||
|
||
# Prepare the query | ||
historic.prepare() | ||
|
||
# Display the details | ||
env.displayHistoricDetails(historic) | ||
|
||
puts 'Rate limit remainining: ' + String(env.user.rate_limit_remaining) | ||
rescue DataSift::DataSiftError => err | ||
puts 'ERR: ' + err | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# This script creates a new Historics query from a stream hash. | ||
# | ||
# NB: Most of the error handling (exception catching) has been removed for | ||
# the sake of simplicity. Nearly everything in this library may throw | ||
# exceptions, and production code should catch them. See the documentation | ||
# for full details. | ||
# | ||
|
||
# Function to display usage instructions with an optional error message. | ||
def usage(message = '', end_of_story = true) | ||
puts message + '\n' unless message.length() == 0 | ||
puts | ||
puts 'Usage: create-from-hash \\' | ||
puts ' <username> <api_key> <hash> <start> <end> <sources> <name> <sample>' | ||
puts | ||
puts 'Where: hash = the stream hash the query should run' | ||
puts ' start = the start date for the query (YYYYMMDDHHMMSS)' | ||
puts ' end = the end date for the query (YYYYMMDDHHMMSS)' | ||
puts ' sources = comma separated list of data sources (e.g. twitter)' | ||
puts ' name = a friendly name for the query' | ||
puts ' sample = the sample rate' | ||
puts | ||
puts 'Example' | ||
puts ' create-from-hash <hash> 20120101000000 20120101235959 \\' | ||
puts ' twitter HistoricsQuery123 100' | ||
puts | ||
exit 1 unless not end_of_story | ||
end | ||
|
||
# Include the shared Env class | ||
require File.dirname(__FILE__) + '/env' | ||
|
||
# Create the env object. This reads the command line arguments, creates the | ||
# user object, and provides access to both along with helper functions. | ||
env = Env.new() | ||
|
||
# Check that we have enough arguments | ||
usage() unless env.args.size() == 6 | ||
|
||
# Read the arguments | ||
stream_hash = env.args[0] | ||
start_date = env.args[1] | ||
end_date = env.args[2] | ||
sources = env.args[3].split(',') | ||
name = env.args[4] | ||
sample = env.args[5] | ||
|
||
# Parse the dates | ||
start_date = DateTime.strptime(start_date, '%Y%m%d%H%M%S') | ||
end_date = DateTime.strptime(end_date, '%Y%m%d%H%M%S') | ||
|
||
begin | ||
# Create the Historics query | ||
historic = env.user.createHistoric(stream_hash, start_date, end_date, sources, name, sample) | ||
|
||
# Prepare the query | ||
historic.prepare() | ||
|
||
# Display the details | ||
env.displayHistoricDetails(historic) | ||
|
||
puts 'Rate limit remainining: ' + String(env.user.rate_limit_remaining) | ||
rescue DataSift::DataSiftError => err | ||
puts 'ERR: ' + err | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# This script deletes Historics queries from your account. | ||
# | ||
# NB: Most of the error handling (exception catching) has been removed for | ||
# the sake of simplicity. Nearly everything in this library may throw | ||
# exceptions, and production code should catch them. See the documentation | ||
# for full details. | ||
# | ||
|
||
# Include the shared Env class | ||
require File.dirname(__FILE__) + '/env' | ||
|
||
# Create the env object. This reads the command line arguments, creates the | ||
# user object, and provides access to both along with helper functions. | ||
env = Env.new() | ||
|
||
# Make sure we have something to do | ||
abort('Please specify one or more playback IDs') unless env.args.size() > 0 | ||
|
||
begin | ||
for playback_id in env.args | ||
historic = env.user.getHistoric(playback_id) | ||
print 'Deleting ' + playback_id + ', "' + historic.name + '"...' | ||
historic.delete() | ||
puts 'done' | ||
end | ||
|
||
puts 'Rate limit remainining: ' + String(env.user.rate_limit_remaining) | ||
rescue DataSift::DataSiftError => err | ||
puts 'ERR: ' + err.inspect | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# This class is used by the Historics examples to remove the noise of | ||
# dealing with command line arguments. | ||
# | ||
|
||
# Include the DataSift library | ||
require File.dirname(__FILE__) + '/../../lib/datasift' | ||
|
||
class Env | ||
attr_reader :user, :args | ||
|
||
def initialize(args = false) | ||
if args === false | ||
args = ARGV | ||
end | ||
|
||
abort('Please specify your DataSift username and API key as the first two command line arguments!') unless args.size() >= 2 | ||
|
||
username = args.shift | ||
api_key = args.shift | ||
@user = DataSift::User.new(username, api_key) | ||
|
||
@args = args | ||
end | ||
|
||
def displayHistoricDetails(historic) | ||
puts 'Playback ID: ' + historic.hash | ||
puts 'Stream hash: ' + historic.stream_hash | ||
puts 'Name: ' + historic.name | ||
puts 'Start time: ' + historic.start_date.strftime('%Y-%m-%d %H:%M:%S') | ||
puts 'End time: ' + historic.end_date.strftime('%Y-%m-%d %H:%M:%S') | ||
puts 'Sources: ' + historic.sources.join(', ') | ||
puts 'Sample: ' + String(historic.sample) | ||
puts 'Created at: ' + (historic.created_at.nil? ? 'None' : historic.created_at.strftime('%Y-%m-%d %H:%M:%S')) | ||
puts 'Status: ' + historic.status | ||
puts '--' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# This script lists Historics queries in your account. | ||
# | ||
# NB: Most of the error handling (exception catching) has been removed for | ||
# the sake of simplicity. Nearly everything in this library may throw | ||
# exceptions, and production code should catch them. See the documentation | ||
# for full details. | ||
# | ||
|
||
# Include the shared Env class | ||
require File.dirname(__FILE__) + '/env' | ||
|
||
# Create the env object. This reads the command line arguments, creates the | ||
# user object, and provides access to both along with helper functions. | ||
env = Env.new() | ||
|
||
begin | ||
historics = env.user.listHistorics() | ||
|
||
if historics['historics'].size() == 0 | ||
puts 'No Historics queries exist in your account.' | ||
else | ||
for historic in historics['historics'] | ||
env.displayHistoricDetails(historic) | ||
end | ||
end | ||
|
||
puts 'Rate limit remainining: ' + String(env.user.rate_limit_remaining) | ||
rescue DataSift::DataSiftError => err | ||
puts 'ERR: ' + err.inspect | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# This script starts Historics queries in your account. | ||
# | ||
# NB: Most of the error handling (exception catching) has been removed for | ||
# the sake of simplicity. Nearly everything in this library may throw | ||
# exceptions, and production code should catch them. See the documentation | ||
# for full details. | ||
# | ||
|
||
# Include the shared Env class | ||
require File.dirname(__FILE__) + '/env' | ||
|
||
# Create the env object. This reads the command line arguments, creates the | ||
# user object, and provides access to both along with helper functions. | ||
env = Env.new() | ||
|
||
# Make sure we have something to do | ||
abort('Please specify one or more playback IDs') unless env.args.size() > 0 | ||
|
||
begin | ||
for playback_id in env.args | ||
historic = env.user.getHistoric(playback_id) | ||
print 'Starting ' + playback_id + ', "' + historic.name + '"...' | ||
historic.start() | ||
puts 'done' | ||
end | ||
|
||
puts 'Rate limit remainining: ' + String(env.user.rate_limit_remaining) | ||
rescue DataSift::DataSiftError => err | ||
puts 'ERR: ' + err.inspect | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# This script stops Historics queries in your account. | ||
# | ||
# NB: Most of the error handling (exception catching) has been removed for | ||
# the sake of simplicity. Nearly everything in this library may throw | ||
# exceptions, and production code should catch them. See the documentation | ||
# for full details. | ||
# | ||
|
||
# Include the shared Env class | ||
require File.dirname(__FILE__) + '/env' | ||
|
||
# Create the env object. This reads the command line arguments, creates the | ||
# user object, and provides access to both along with helper functions. | ||
env = Env.new() | ||
|
||
# Make sure we have something to do | ||
abort('Please specify one or more playback IDs') unless env.args.size() > 0 | ||
|
||
begin | ||
for playback_id in env.args | ||
historic = env.user.getHistoric(playback_id) | ||
print 'Stopping ' + playback_id + ', "' + historic.name + '"...' | ||
historic.stop() | ||
puts 'done' | ||
end | ||
|
||
puts 'Rate limit remainining: ' + String(env.user.rate_limit_remaining) | ||
rescue DataSift::DataSiftError => err | ||
puts 'ERR: ' + err.inspect | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# This script views Historics queries in your account. | ||
# | ||
# NB: Most of the error handling (exception catching) has been removed for | ||
# the sake of simplicity. Nearly everything in this library may throw | ||
# exceptions, and production code should catch them. See the documentation | ||
# for full details. | ||
# | ||
|
||
# Include the shared Env class | ||
require File.dirname(__FILE__) + '/env' | ||
|
||
# Create the env object. This reads the command line arguments, creates the | ||
# user object, and provides access to both along with helper functions. | ||
env = Env.new() | ||
|
||
# Make sure we have something to do | ||
abort('Please specify one or more playback IDs') unless env.args.size() > 0 | ||
|
||
begin | ||
for playback_id in env.args | ||
historic = env.user.getHistoric(playback_id) | ||
env.displayHistoricDetails(historic) | ||
end | ||
|
||
puts 'Rate limit remainining: ' + String(env.user.rate_limit_remaining) | ||
rescue DataSift::DataSiftError => err | ||
puts 'ERR: ' + err.inspect | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.