sheep-sebastian 0.0.1 → 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.
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ *.swp
@@ -1,10 +1,15 @@
1
- hello.
1
+ hello2.
2
2
 
3
3
  == install
4
4
 
5
- gem install sheep-sebastion
5
+ gem install sheep-sebastian
6
6
 
7
7
  == setup
8
8
 
9
- == todo
9
+ You should write `sheeprc.rb'.
10
10
 
11
+ See https://github.com/dan5/sheep-sebastian/blob/master/sheeprc_default.rb
12
+
13
+ == run
14
+
15
+ ruby -r sheep-sebastian -r ./sheeprc.rb -e 'SheepSebastian.new()'
@@ -1,7 +1,56 @@
1
1
  require "sheep-sebastian/version"
2
+ require 'twitter'
3
+ require 'yaml'
2
4
 
3
- module Sheep
4
- module Sebastian
5
- # Your code goes here...
5
+ class SheepSebastian
6
+ module DB
7
+ def self.load(filename, default)
8
+ db = _load(filename, default)
9
+ def db.filename=(fname) @fname = fname end
10
+ def db.save() File.open(@fname, 'w') {|f| f.write(self.to_yaml) } end
11
+ db.filename = filename
12
+ db
13
+ end
14
+
15
+ def self._load(filename, default)
16
+ YAML::load(File.read(filename)) rescue default
17
+ end
18
+ end
19
+
20
+ def tweets(db)
21
+ since_id = db[:since_id]
22
+ opts = since_id ? { :since_id => since_id } : {}
23
+ tweets = Twitter.user_timeline(Target_screen_name, opts)
24
+ unless tweets.empty?
25
+ db[:since_id] = tweets.first.id
26
+ db.save
27
+ end
28
+ tweets
29
+ end
30
+
31
+ def hit?(text, recipe)
32
+ recipe[:keywords].all? {|keyword| text[keyword] }
33
+ end
34
+
35
+ def atend_new_post(text, recipe)
36
+ p text
37
+ tmp, month, day = text.match(/(1?\d)\/([1-3]?\d)/).to_a
38
+ tmp, hour, minutes = text.match(/([12]?\d):([0-5]?\d)/).to_a
39
+ at = sprintf("%04d-%02d-%02d", Time.now.year, month, day) # todo: next year...
40
+ at_time = sprintf("%02d:%02d", hour, minutes)
41
+ template = Post_template
42
+ template[:started_at] = at
43
+ template[:started_at_time] = at_time
44
+ p template
45
+ end
46
+
47
+ def initialize()
48
+ db = DB.load(DB_filename, {:since_id => nil})
49
+ recipe = Recipe
50
+ tweets(db).each do |tweet|
51
+ if hit?(tweet.text, recipe)
52
+ __send__ recipe[:handle], tweet.text, recipe
53
+ end
54
+ end
6
55
  end
7
56
  end
@@ -1,5 +1,5 @@
1
1
  module Sheep
2
2
  module Sebastian
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+ class SheepSebastian
3
+ DB_filename = 'db'
4
+
5
+ Target_screen_name = '.TODO'
6
+
7
+ #Twitter_name = 'TODO'
8
+ #Twitter_login_password = 'TODO'
9
+
10
+ Recipe = {
11
+ :keywords => ['pattern1', 'pattern2'],
12
+ :handle => :atend_new_post,
13
+ }
14
+
15
+ Post_template = {
16
+ :title => "title",
17
+ :catch => "",
18
+ :description => "",
19
+ #:started_at => "0000-00-00",
20
+ #:started_at_time => "00:00",
21
+ #:ended_at => "0000-00-00",
22
+ #:ended_at_time => "23:55",
23
+ :limit => "",
24
+ :place => "",
25
+ :address => "",
26
+ :url => "",
27
+ :image => "",
28
+ :recommended_twitter_account => "",
29
+ :hash_tag => "",
30
+ }
31
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sheep-sebastian
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -25,6 +25,7 @@ files:
25
25
  - lib/sheep-sebastian.rb
26
26
  - lib/sheep-sebastian/version.rb
27
27
  - sheep-sebastian.gemspec
28
+ - sheeprc_default.rb
28
29
  homepage: https://github.com/dan5/sheep-sebastion
29
30
  licenses: []
30
31
  post_install_message: