twitterpunch 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/twitterpunch +23 -3
- data/lib/twitterpunch.rb +1 -1
- data/lib/twitterpunch/configuration.rb +3 -0
- data/lib/twitterpunch/sprite.rb +65 -0
- data/lib/twitterpunch/streamer.rb +17 -3
- data/lib/twitterpunch/viewer.rb +101 -0
- data/resources/Tahoma Bold.ttf +0 -0
- metadata +28 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96c566d4bdc10313e9efc77b92c9cfa407048617
|
4
|
+
data.tar.gz: 59b7a93bd2cdda89c79cc1b99f2811a77b1230e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17cfa29c54696a7dcdecb8ee77c03b3cdbd2c2c0d30479b77abce4722a2f519159939e3d37037da74ea6dda61f235c18fb33e4a0e7261bfbf11278c733e8cf29
|
7
|
+
data.tar.gz: fc1a39f9a4a93b7896510d48242f3ad968a7ccf8721ee3d966195c0286ab470c706b87fa7b84ffc266d01114d71a7ba5e53feef3bc838e07cb67b58f9ef04e71
|
data/bin/twitterpunch
CHANGED
@@ -32,6 +32,10 @@ optparse = OptionParser.new { |opts|
|
|
32
32
|
config[:action] = :stream
|
33
33
|
end
|
34
34
|
|
35
|
+
opts.on("--view", "Run photo viewer only.") do
|
36
|
+
config[:action] = :view
|
37
|
+
end
|
38
|
+
|
35
39
|
opts.on("-g", "--genconfig", "Create a default configuration file.") do
|
36
40
|
config[:action] = :configure
|
37
41
|
end
|
@@ -54,20 +58,35 @@ optparse = OptionParser.new { |opts|
|
|
54
58
|
}
|
55
59
|
optparse.parse!
|
56
60
|
|
61
|
+
config[:action] = :post if ARGV.size > 0 and config[:action].nil?
|
57
62
|
config[:resources] = File.expand_path("#{File.dirname(__FILE__)}/../resources")
|
58
|
-
config[:action] = :post if ARGV.size > 0 and config[:action].nil?
|
59
63
|
|
60
64
|
case config[:action]
|
61
65
|
when :stream
|
62
66
|
require 'twitterpunch/streamer'
|
63
|
-
|
64
|
-
|
67
|
+
require 'twitterpunch/viewer'
|
68
|
+
|
69
|
+
statefile = File.expand_path('~/.twitterpunch.state')
|
70
|
+
config[:state] = YAML.load_file(statefile) rescue {}
|
71
|
+
|
72
|
+
Twitterpunch::Streamer.new(config).thread
|
73
|
+
Twitterpunch::Viewer.new(config)
|
74
|
+
|
75
|
+
File.open(statefile, 'w') {|f| f.write(config[:state].to_yaml) }
|
65
76
|
|
66
77
|
when :post
|
67
78
|
require 'twitterpunch/poster'
|
68
79
|
client = Twitterpunch::Poster.new(config)
|
69
80
|
client.post(ARGV)
|
70
81
|
|
82
|
+
when :view
|
83
|
+
require 'twitterpunch/viewer'
|
84
|
+
|
85
|
+
statefile = File.expand_path('~/.twitterpunch.state')
|
86
|
+
config[:state] = YAML.load_file(statefile) rescue {}
|
87
|
+
|
88
|
+
client = Twitterpunch::Viewer.new(config)
|
89
|
+
|
71
90
|
when :configure
|
72
91
|
require 'twitterpunch/configuration'
|
73
92
|
cfg = Twitterpunch::Configuration.new(configfile).save
|
@@ -80,3 +99,4 @@ else
|
|
80
99
|
puts "Run twitterpunch --help for usage."
|
81
100
|
exit 1
|
82
101
|
end
|
102
|
+
|
data/lib/twitterpunch.rb
CHANGED
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rubygame'
|
3
|
+
|
4
|
+
module Twitterpunch
|
5
|
+
class Sprite
|
6
|
+
include Rubygame
|
7
|
+
include Sprites::Sprite
|
8
|
+
|
9
|
+
def initialize(dimensions, image, text)
|
10
|
+
# Invoking the base class constructor is important and yet easy to forget:
|
11
|
+
super()
|
12
|
+
|
13
|
+
@dimensions = dimensions
|
14
|
+
|
15
|
+
@rate = rand(35..150)
|
16
|
+
@zoom = rand(50..100) / 100.0
|
17
|
+
|
18
|
+
# @image and @rect are expected by the Rubygame sprite code
|
19
|
+
@image = Surface.load(image).zoom(@zoom)
|
20
|
+
|
21
|
+
max_width = dimensions[0] * 0.75
|
22
|
+
if @image.width > max_width
|
23
|
+
@image = @image.zoom(max_width/@image.width)
|
24
|
+
end
|
25
|
+
|
26
|
+
@top = 0 - @image.height
|
27
|
+
@left = (dimensions[0] - @image.width ) * rand
|
28
|
+
@rect = @image.make_rect
|
29
|
+
|
30
|
+
if text
|
31
|
+
@text = $font.render_utf8(text, true, Color[:black], Color[:gray])
|
32
|
+
@text.alpha = 150
|
33
|
+
|
34
|
+
# Determine the dimensions in pixels of the area used to render the text. The
|
35
|
+
# "topleft" of the returned rectangle is at [ 0, 0]
|
36
|
+
rt = @text.make_rect
|
37
|
+
|
38
|
+
# Re-use the "topleft" of the rectangle to indicate where the text should
|
39
|
+
# appear on screen ( lower left corner )
|
40
|
+
#rt.topleft = [ 12, @image.height - rt.height - 8]
|
41
|
+
rt.topleft = [ 0, @image.height - rt.height]
|
42
|
+
|
43
|
+
# Copy the pixels of the rendered text to the image
|
44
|
+
@text.blit(@image, rt)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Animate this object. "seconds_passed" contains the number of ( real-world)
|
49
|
+
# seconds that have passed since the last time this object was updated and is
|
50
|
+
# therefore useful for working out how far the object should move ( which
|
51
|
+
# should be independent of the frame rate)
|
52
|
+
def update(seconds_passed)
|
53
|
+
@top += seconds_passed * @rate
|
54
|
+
@rect.topleft = [ @left, @top ]
|
55
|
+
end
|
56
|
+
|
57
|
+
def draw(on_surface)
|
58
|
+
@image.blit(on_surface, @rect)
|
59
|
+
end
|
60
|
+
|
61
|
+
def visible
|
62
|
+
@top < @dimensions[1]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -16,6 +16,12 @@ module Twitterpunch
|
|
16
16
|
FileUtils.mkdir_p(@output) unless File.directory?(@output)
|
17
17
|
end
|
18
18
|
|
19
|
+
def thread
|
20
|
+
Thread.new do
|
21
|
+
stream
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
19
25
|
def stream
|
20
26
|
begin
|
21
27
|
@client.filter(:track => @config[:hashtag]) do |tweet|
|
@@ -23,9 +29,11 @@ module Twitterpunch
|
|
23
29
|
@logger.info(tweet.text)
|
24
30
|
@logger.log(tweet.user.screen_name, tweet.text)
|
25
31
|
|
32
|
+
content = tweet.text.gsub(/ http\S*/,'').gsub(/#\S*/,'')
|
33
|
+
|
26
34
|
|
27
35
|
unless tweet.user.screen_name == @config[:handle]
|
28
|
-
message = "#{tweet.user.name} says #{
|
36
|
+
message = "#{tweet.user.name} says #{content}"
|
29
37
|
|
30
38
|
case RUBY_PLATFORM
|
31
39
|
when /mingw|cygwin/
|
@@ -42,12 +50,18 @@ module Twitterpunch
|
|
42
50
|
request = Net::HTTP::Get.new(uri.request_uri)
|
43
51
|
response = http.request(request)
|
44
52
|
|
45
|
-
File.
|
53
|
+
image = File.basename uri.path
|
54
|
+
|
55
|
+
File.open("#{@output}/#{image}", 'wb') do |file|
|
46
56
|
file.write(response.body)
|
47
57
|
end
|
48
58
|
|
59
|
+
unless tweet.user.screen_name == @config[:handle]
|
60
|
+
@config[:state][image] = content
|
61
|
+
end
|
62
|
+
|
49
63
|
# OS X screensaver doesn't reload images dynamically. This kinda sucks.
|
50
|
-
if RUBY_PLATFORM =~ /darwin/
|
64
|
+
if RUBY_PLATFORM =~ /darwin/ and not @config.has_key? :viewer
|
51
65
|
system('osascript', '-e', 'tell application "System Events" to stop current screen saver')
|
52
66
|
system('osascript', '-e', 'tell application "System Events" to start current screen saver')
|
53
67
|
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rubygame'
|
3
|
+
require 'yaml'
|
4
|
+
require 'twitterpunch/sprite'
|
5
|
+
|
6
|
+
module Twitterpunch
|
7
|
+
class Viewer
|
8
|
+
include Rubygame
|
9
|
+
|
10
|
+
def initialize(config)
|
11
|
+
@config = config
|
12
|
+
@state = YAML.load_file(File.expand_path('~/.twitterpunch.state')) rescue {}
|
13
|
+
srand
|
14
|
+
|
15
|
+
if @config.has_key? :viewer
|
16
|
+
run
|
17
|
+
else
|
18
|
+
puts 'Press enter to exit'
|
19
|
+
STDIN.gets
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def run
|
24
|
+
onscreen = @config[:viewer][:count] || 5
|
25
|
+
|
26
|
+
# Set up the TrueType Font module
|
27
|
+
TTF.setup
|
28
|
+
point_size = 20
|
29
|
+
$font = TTF.new("#{@config[:resources]}/Tahoma Bold.ttf", point_size)
|
30
|
+
|
31
|
+
#@screen = Screen.open [ 640, 480]
|
32
|
+
default_depth = 0
|
33
|
+
maximum_resolution = Screen.get_resolution
|
34
|
+
|
35
|
+
screen = Screen.open(maximum_resolution, default_depth, [ HWSURFACE, DOUBLEBUF, FULLSCREEN])
|
36
|
+
|
37
|
+
screen.show_cursor = false
|
38
|
+
|
39
|
+
clock = Clock.new
|
40
|
+
clock.target_framerate = 60
|
41
|
+
|
42
|
+
# Ask Clock.tick() to return ClockTicked objects instead of the number of
|
43
|
+
# milliseconds that have passed:
|
44
|
+
clock.enable_tick_events
|
45
|
+
|
46
|
+
# Create a new group of sprites so that all sprites in the group may be updated
|
47
|
+
# or drawn with a single method invocation.
|
48
|
+
sprites = Sprites::Group.new
|
49
|
+
Sprites::UpdateGroup.extend_object(sprites)
|
50
|
+
onscreen.times do
|
51
|
+
sprites << Twitterpunch::Sprite.new(maximum_resolution, *next_image)
|
52
|
+
end
|
53
|
+
|
54
|
+
#@background = Surface.load("background.png").zoom_to(maximum_resolution[0], maximum_resolution[1])
|
55
|
+
# Create a background image and copy it to the screen. With no image, it's just black.
|
56
|
+
background = Surface.new(maximum_resolution)
|
57
|
+
background.blit(screen, [ 0, 0])
|
58
|
+
|
59
|
+
event_queue = EventQueue.new
|
60
|
+
event_queue.enable_new_style_events
|
61
|
+
|
62
|
+
should_run = true
|
63
|
+
while should_run do
|
64
|
+
seconds_passed = clock.tick().seconds
|
65
|
+
|
66
|
+
event_queue.each do |event|
|
67
|
+
case event
|
68
|
+
when Events::QuitRequested, Events::KeyReleased
|
69
|
+
should_run = false
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# remove all sprites who've gone out of sight
|
74
|
+
sprites.reject { |sprite| sprite.visible }.each do |sprite|
|
75
|
+
sprite.kill
|
76
|
+
sprites << Twitterpunch::Sprite.new(maximum_resolution, *next_image)
|
77
|
+
end
|
78
|
+
|
79
|
+
# "undraw" all of the sprites by drawing the background image at their
|
80
|
+
# current location ( before their location has been changed by the animation)
|
81
|
+
sprites.undraw(screen, background)
|
82
|
+
|
83
|
+
# Give all of the sprites an opportunity to move themselves to a new location
|
84
|
+
sprites.update(seconds_passed)
|
85
|
+
|
86
|
+
# Draw all of the sprites
|
87
|
+
sprites.draw(screen)
|
88
|
+
|
89
|
+
screen.flip
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
def next_image
|
95
|
+
image = Dir.glob(File.expand_path("#{@config[:photodir]}/*")).sample
|
96
|
+
text = @config[:state][File.basename(image)]
|
97
|
+
return image, text
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
end
|
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twitterpunch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Ford
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubygame
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description: "Twitterpunch\n===============\n\nTwitterpunch is designed to work with
|
56
70
|
PhotoBooth and OS X Folder Actions.\nWhen this script is called with the name of
|
57
71
|
an image file, it will post the\nimage to Twitter, along with a message randomly
|
@@ -114,7 +128,10 @@ files:
|
|
114
128
|
- lib/twitterpunch/configuration.rb
|
115
129
|
- lib/twitterpunch/logger.rb
|
116
130
|
- lib/twitterpunch/poster.rb
|
131
|
+
- lib/twitterpunch/sprite.rb
|
117
132
|
- lib/twitterpunch/streamer.rb
|
133
|
+
- lib/twitterpunch/viewer.rb
|
134
|
+
- resources/Tahoma Bold.ttf
|
118
135
|
- resources/Twitterpunch.workflow/Contents/Info.plist
|
119
136
|
- resources/Twitterpunch.workflow/Contents/QuickLook/Thumbnail.png
|
120
137
|
- resources/Twitterpunch.workflow/Contents/document.wflow
|
@@ -123,7 +140,16 @@ files:
|
|
123
140
|
homepage: http://binford2k.com
|
124
141
|
licenses: []
|
125
142
|
metadata: {}
|
126
|
-
post_install_message:
|
143
|
+
post_install_message: |2+
|
144
|
+
|
145
|
+
************************************************************************
|
146
|
+
Be aware that RubyGame is BROKEN on OSX right now. You will need this
|
147
|
+
patch before Twitterpunch will work properly:
|
148
|
+
|
149
|
+
https://github.com/xrs1133/ruby-sdl-ffi/commit/0b721ac4659b4c08cda5aa2f418561a8a311e85b
|
150
|
+
|
151
|
+
************************************************************************
|
152
|
+
|
127
153
|
rdoc_options: []
|
128
154
|
require_paths:
|
129
155
|
- lib
|