twitter2vk_reposter 0.3.9 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +5 -0
- data/bin/twitter2vk_reposter +40 -9
- metadata +3 -4
data/ChangeLog
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
== 0.4 (Тефтели)
|
2
|
+
* Fix Twitter OAuth in reposter.
|
3
|
+
* Add --debug option to reposter.
|
4
|
+
* Show error messages from Twitter on reposting.
|
5
|
+
|
1
6
|
== 0.3.9 (Мармелад)
|
2
7
|
* Remove Twitter OAuth consumer key and secret from sources. Twitter policy deny
|
3
8
|
open API keys in sources, so now you must create your own Twitter app to use
|
data/bin/twitter2vk_reposter
CHANGED
@@ -14,10 +14,25 @@ require 'yaml'
|
|
14
14
|
require 'open-uri'
|
15
15
|
require 'net/http'
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
help = false
|
18
|
+
debug = false
|
19
|
+
config_path = nil
|
20
|
+
ARGV.each do |arg|
|
21
|
+
if '--help' == arg or '-h' == arg
|
22
|
+
help = true
|
23
|
+
elsif '--debug' == arg
|
24
|
+
debug = true
|
25
|
+
else
|
26
|
+
config_path = arg
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
if help or config_path.nil?
|
31
|
+
puts 'Usage: twitter2vk_reposter.rb [OPTION] CONFIG'
|
19
32
|
puts 'Repost Twitter statuses to VK.com. Call twitter2vk script to create ' +
|
20
33
|
'config and add cron task.'
|
34
|
+
puts 'You can use --debug option to show next message to repost. Program ' +
|
35
|
+
'would not repost it or save it ID in last_message_id file.'
|
21
36
|
exit 0
|
22
37
|
end
|
23
38
|
|
@@ -89,7 +104,7 @@ default = {
|
|
89
104
|
'last' => '',
|
90
105
|
'retweet' => 'RT %author%: %status%'
|
91
106
|
}
|
92
|
-
config = default.merge(YAML.load_file(
|
107
|
+
config = default.merge(YAML.load_file(config_path))
|
93
108
|
|
94
109
|
missed = %w{twitter_token twitter_secret last_message vk_session} - config.keys
|
95
110
|
unless missed.empty?
|
@@ -104,15 +119,25 @@ end
|
|
104
119
|
last_message = nil unless last_message =~ /^\d/
|
105
120
|
|
106
121
|
begin
|
107
|
-
twitter = TwitterOAuth::Client.new(
|
108
|
-
:
|
109
|
-
:
|
122
|
+
twitter = TwitterOAuth::Client.new(
|
123
|
+
:consumer_key => config['twitter_consumer_key'],
|
124
|
+
:consumer_secret => config['twitter_consumer_secret'],
|
125
|
+
:token => config['twitter_token'],
|
126
|
+
:secret => config['twitter_secret'])
|
110
127
|
if last_message
|
111
128
|
query = { :since_id => last_message }
|
112
129
|
else
|
113
130
|
query = { :count => 1 }
|
114
131
|
end
|
115
|
-
|
132
|
+
tweets = twitter.user_timeline(query)
|
133
|
+
retweets = twitter.retweeted_by_me(query)
|
134
|
+
[tweets, retweets].each do |array|
|
135
|
+
unless array.is_a? Array
|
136
|
+
STDERR.puts 'Wrong answer from Twitter: ' + array.inspect
|
137
|
+
exit 1
|
138
|
+
end
|
139
|
+
end
|
140
|
+
statuses = tweets + retweets
|
116
141
|
statuses.sort! { |a, b| a['id'] <=> b['id'] }
|
117
142
|
rescue JSON::ParserError => e
|
118
143
|
exit 1
|
@@ -128,11 +153,17 @@ unless statuses.empty?
|
|
128
153
|
next unless repost? status, config
|
129
154
|
text = format_status(status, config)
|
130
155
|
last_message_id = status['id']
|
131
|
-
|
156
|
+
if debug
|
157
|
+
puts "Message to VK:\n#{text}"
|
158
|
+
else
|
159
|
+
vk.set_status(text)
|
160
|
+
end
|
132
161
|
break
|
133
162
|
end
|
134
163
|
|
135
164
|
if last_message_id
|
136
|
-
|
165
|
+
unless debug
|
166
|
+
File.open(config['last_message'], 'w') { |io| io << last_message_id }
|
167
|
+
end
|
137
168
|
end
|
138
169
|
end
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twitter2vk_reposter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
|
10
|
-
version: 0.3.9
|
8
|
+
- 4
|
9
|
+
version: "0.4"
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Andrey "A.I." Sitnik
|