-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c29560c
Showing
8 changed files
with
220 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
TWITTER_CONSUMER_KEY= | ||
TWITTER_CONSUMER_SECRET= | ||
TWITTER_OAUTH_TOKEN= | ||
TWITTER_OAUTH_TOKEN_SECRET= |
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,40 @@ | ||
### https://raw.github.com/github/gitignore/fceac113a3a20e00718d6317e468eec27f6e2d99/ruby.gitignore | ||
|
||
*.gem | ||
*.rbc | ||
/.config | ||
/coverage/ | ||
/InstalledFiles | ||
/pkg/ | ||
/spec/reports/ | ||
/spec/examples.txt | ||
/test/tmp/ | ||
/test/version_tmp/ | ||
/tmp/ | ||
|
||
## Specific to RubyMotion: | ||
.dat* | ||
.repl_history | ||
build/ | ||
|
||
## Documentation cache and generated files: | ||
/.yardoc/ | ||
/_yardoc/ | ||
/doc/ | ||
/rdoc/ | ||
|
||
## Environment normalization: | ||
/.bundle/ | ||
/vendor/bundle | ||
/lib/bundler/man/ | ||
|
||
# for a library or gem, you might want to ignore these files since the code is | ||
# intended to run in multiple environments; otherwise, check them in: | ||
# Gemfile.lock | ||
# .ruby-version | ||
# .ruby-gemset | ||
|
||
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this: | ||
.rvmrc | ||
|
||
.env |
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,6 @@ | ||
source 'https://rubygems.org' | ||
gem 'foreman' | ||
gem 'userstream', :git => 'git://github.com/mitukiii/userstream.git' | ||
gem 'twitter' | ||
gem 'dotenv' | ||
gem 'pry' |
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,76 @@ | ||
GIT | ||
remote: git://github.com/mitukiii/userstream.git | ||
revision: f37e7931f7f934422ae6cbdee10da40715c6b68b | ||
specs: | ||
userstream (1.4.0) | ||
hashie (~> 1.2.0) | ||
oauth (~> 0.4.7) | ||
yajl-ruby (~> 1.1.0) | ||
|
||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
addressable (2.4.0) | ||
buftok (0.2.0) | ||
coderay (1.1.0) | ||
domain_name (0.5.25) | ||
unf (>= 0.0.5, < 1.0.0) | ||
dotenv (2.1.0) | ||
equalizer (0.0.10) | ||
faraday (0.9.2) | ||
multipart-post (>= 1.2, < 3) | ||
foreman (0.78.0) | ||
thor (~> 0.19.1) | ||
hashie (1.2.0) | ||
http (0.9.8) | ||
addressable (~> 2.3) | ||
http-cookie (~> 1.0) | ||
http-form_data (~> 1.0.1) | ||
http_parser.rb (~> 0.6.0) | ||
http-cookie (1.0.2) | ||
domain_name (~> 0.5) | ||
http-form_data (1.0.1) | ||
http_parser.rb (0.6.0) | ||
json (1.8.3) | ||
memoizable (0.4.2) | ||
thread_safe (~> 0.3, >= 0.3.1) | ||
method_source (0.8.2) | ||
multipart-post (2.0.0) | ||
naught (1.1.0) | ||
oauth (0.4.7) | ||
pry (0.10.3) | ||
coderay (~> 1.1.0) | ||
method_source (~> 0.8.1) | ||
slop (~> 3.4) | ||
simple_oauth (0.3.1) | ||
slop (3.6.0) | ||
thor (0.19.1) | ||
thread_safe (0.3.5) | ||
twitter (5.15.0) | ||
addressable (~> 2.3) | ||
buftok (~> 0.2.0) | ||
equalizer (= 0.0.10) | ||
faraday (~> 0.9.0) | ||
http (>= 0.4, < 0.10) | ||
http_parser.rb (~> 0.6.0) | ||
json (~> 1.8) | ||
memoizable (~> 0.4.0) | ||
naught (~> 1.0) | ||
simple_oauth (~> 0.3.0) | ||
unf (0.1.4) | ||
unf_ext | ||
unf_ext (0.0.7.1) | ||
yajl-ruby (1.1.0) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
dotenv | ||
foreman | ||
pry | ||
userstream! | ||
|
||
BUNDLED WITH | ||
1.11.2 |
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 @@ | ||
MentionItToBalsers: bundle exec ruby bin/observe | ||
|
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,7 @@ | ||
#!/usr/bin/env ruby -Ku | ||
require File.join(".", File.dirname(__FILE__), "..", "lib", "initialize") | ||
|
||
require 'pry' | ||
|
||
Util.new.exec | ||
|
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,5 @@ | ||
APPLICATION_ROOT = File.absolute_path(File.join(File.dirname(__FILE__),"..")) | ||
# puts "Application Root: %s" % APPLICATION_ROOT | ||
$: << APPLICATION_ROOT | ||
|
||
require 'lib/util' |
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,80 @@ | ||
require 'dotenv' | ||
require 'twitter' | ||
require 'user_stream' | ||
|
||
class Util | ||
def initialize | ||
Dotenv.load | ||
setup_twitter | ||
end | ||
|
||
def setup_twitter | ||
UserStream.configure do |config| | ||
config.consumer_key = ENV['TWITTER_CONSUMER_KEY'] | ||
config.consumer_secret = ENV['TWITTER_CONSUMER_SECRET'] | ||
config.oauth_token = ENV['TWITTER_OAUTH_TOKEN'] | ||
config.oauth_token_secret = ENV['TWITTER_OAUTH_TOKEN_SECRET'] | ||
end | ||
|
||
@client = Twitter::REST::Client.new do |config| | ||
config.consumer_key = ENV['TWITTER_CONSUMER_KEY'] | ||
config.consumer_secret = ENV['TWITTER_CONSUMER_SECRET'] | ||
config.access_token = ENV['TWITTER_OAUTH_TOKEN'] | ||
config.access_token_secret = ENV['TWITTER_OAUTH_TOKEN_SECRET'] | ||
end | ||
end | ||
|
||
def exec | ||
begin | ||
# UserStream.client.sample({'lang'=>'ja'}) do |status| | ||
UserStream.client.user do |status| | ||
analyze status | ||
end | ||
rescue => ex | ||
STDERR.puts ex | ||
retry | ||
rescue UserStream::RateLimited => ex | ||
STDERR.puts 'sleep 300 second...' | ||
sleep 300 | ||
retry | ||
rescue Timeout::Error => ex | ||
STDERR.puts ex.class | ||
STDERR.puts ex | ||
if ex.class == UserStream::RateLimited | ||
STDERR.puts 'sleep 300 second...' | ||
sleep 300 | ||
end | ||
retry | ||
end | ||
end | ||
|
||
def analyze status | ||
user = status.user | ||
text = status.text | ||
if text and user | ||
s = text.gsub(/([[:ascii:]]|[[:punct:]])/,'') | ||
puts s | ||
if text !~ /^RT / and text !~ /(@|at)/ and text !~ /http/ and text =~ /バルス/ | ||
if bals_density_high?(text) | ||
puts user.screen_name | ||
puts text | ||
@client.update("at #{status.user.screen_name} " + random_message, in_reply_to_status_id: status.id) | ||
@client.favorite(status.id) | ||
#binding.pry | ||
end | ||
end | ||
end | ||
end | ||
|
||
def random_message | ||
array = ['ナイスバルス', 'これはいいバルス', 'いいバルスでしたよ〜'] | ||
array.sample + '!' * rand(1..10) | ||
end | ||
|
||
def bals_density_high? str | ||
return false if str.length == 0 | ||
s = str.gsub(/([[:ascii:]]|[[:punct:]])/,'') | ||
t = s.gsub(/バルス/,'') | ||
t.length.to_f / s.length.to_f < 0.5 | ||
end | ||
end |