Skip to content

Commit

Permalink
bumped to 0.05
Browse files Browse the repository at this point in the history
  • Loading branch information
jbilcke committed Jun 18, 2012
1 parent eda0ef2 commit 19fafa4
Show file tree
Hide file tree
Showing 25 changed files with 636 additions and 487 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
test/tmp.*
examples/test.json
examples/test.yaml
examples/test.yml
Expand Down
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
test/tmp.*
examples/test.json
examples/test.yaml
examples/test.yml
Expand Down
28 changes: 25 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,16 @@ recorder.write "hello"
recorder.write foo: "hello", bar: "world"
recorder.write new Buffer()

# in the future, you will be able to add an event at a specific time
# not yet implemented, but soon you will be able to add an event at a specific time
# recorder.writeAt moment(1982,1,1), "cold wave"

# also, don't forget to close the recorder when you don't use it anymore
# the reason is that a recorder start some background processes
# (eg. async synchronization of database) that need to be stopped manually
# if there is not more data to record.
recorder.stop()


```

Playback
Expand Down Expand Up @@ -152,6 +159,8 @@ recorder = new StreamRecorder record
myInputStream.pipe(recorder)

# that's all folks!
# you don't need to close explicitely the StreamRecorder (unlike SimpleRecorder)
# since it can detect automatically 'close' events from input stream
```


Expand Down Expand Up @@ -192,8 +201,13 @@ Piping

### Playing with Twitter Stream

Here I am using some environment variables to define the Twitter tokens (à la Heroku),
so don't forget to change this to fit your own environment.
NOTE 1: you need to install ntwitter manually before running the example:

$ npm install -g ntwitter

I didn't include it as a dependency to keep dependencies light.

NOTE 2: you need to have some some environment variables containing your Twitter tokens

``` coffeescript

Expand Down Expand Up @@ -231,6 +245,7 @@ twit.stream 'statuses/sample', (stream) ->
stream.on 'data', (data) ->
timeline.write moment(data.created_at), data.text
delay duration*1000, ->
recorder.close()
log "playing tweets back"
new sampler.SimplePlayer timeline,
speed: 2.0
Expand All @@ -246,6 +261,13 @@ twit.stream 'statuses/sample', (stream) ->

## Changelog

### 0.0.5

* now we can load a json file! and it's tested!
* more bugfixes
* more tests
* addd a recorder.close() function

### 0.0.4

* Fixed broken YAML dependency
Expand Down
12 changes: 12 additions & 0 deletions examples/playback.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env coffee

# standard node library
{log,inspect} = require 'util'

# sampler modules
sampler = require '../lib/sampler'
delay = (t, f) -> setTimeout f, t

new sampler.SimplePlayer "file://twitter.smp",
speed: 2.0
onData: (data) -> log "TWEET: #{data}"
Binary file removed examples/test.sample
Binary file not shown.
10 changes: 7 additions & 3 deletions examples/twitter.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ sampler = require '../lib/sampler'
delay = (t, f) -> setTimeout f, t

# PARAMETERS
duration = 15
duration = 8
timeline = new sampler.Record "file://twitter.smp"
twit = new Twitter
consumer_key: process.env.TWITTER_CONSUMER_KEY
Expand All @@ -26,12 +26,16 @@ twit.stream 'statuses/sample', (stream) ->
recorder = new sampler.SimpleRecorder timeline
stream.on 'error', (err) ->
log "twitter error: #{inspect err}"
if err.code?
log "this is a serious error. exiting"
process.exit()

if err.text?
timeline.write moment(err.created_at), err.text
stream.on 'data', (data) ->
timeline.write moment(data.created_at), data.text
delay duration*1000, ->
log "recording terminated"
log "recording terminated, will soon exit.."
stream.destroy() # clean exit?
#process.exit() # problem; is we exit during a write(), everything in the file is lost
delay 5000, -> process.exit()
log "listening for #{duration} seconds"
89 changes: 74 additions & 15 deletions lib/simple.js → lib/api/simple.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 19fafa4

Please sign in to comment.