twitter2vk 0.2.6 → 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/ChangeLog CHANGED
@@ -1,3 +1,9 @@
1
+ == 0.3 (Суп)
2
+ * Repost retweets.
3
+ * Add last format, which will be add to status after trimmed text.
4
+ * Add Twitter OAuth authentication.
5
+ * Use rvk gem to post status to VK.
6
+
1
7
  == 0.2.6 (Йорурт)
2
8
  * Fix for Ruby Enterprise Edition.
3
9
 
data/README.markdown CHANGED
@@ -33,17 +33,23 @@ You can follow author @andrey_sitnik to receive last updates info.
33
33
  Config is a YAML files with options:
34
34
 
35
35
  * `vk_session` – session ID to access to VK.
36
- * `twitter` your Twitter login.
36
+ * `twitter_token`, `twitter_secret` data to access to Twitter by OAuth.
37
37
  * `exclude` – list of text or regexp patterns to exclude statuses from your VK.
38
- Code `:reply` will exclude your replies to another Twitter users.
38
+ Code `:reply` will exclude your replies to another users, `:retweet` will
39
+ exclude retweets by you.
39
40
  * `include` – list of text or regexp patterns to repost excluded statuses.
40
41
  * `format` – format reposted status. `%status%` will be replaced by status text,
41
42
  `%url%` by status link on Twitter.
43
+ * `last` — text after `format`. If status will be longer that VK allow,
44
+ `format` will be trim first. So `last` it useful, to set link to Twitter
45
+ status.
46
+ * `retweet` — format of retweet. `%status%` will be replaced by text,
47
+ `%author%` will be replace by tweet author.
42
48
  * `replace` – list of array with 2 elements to replace text in status. Code
43
49
  `:user_to_url` will replace user name to his Twitter link.
44
50
  * `last_message` – file to contain ID of last reposted message.
45
51
 
46
- ## Russian
52
+ ## По-русски
47
53
 
48
54
  Автоматический скрипт для публикации статусов Twitter’а во В Контакте. Так же
49
55
  в отдельном пакете есть консольная утилита для создания настроек и добавления
@@ -79,13 +85,19 @@ Config is a YAML files with options:
79
85
  Настройки хранятся в YAML файле с полями:
80
86
 
81
87
  * `vk_session` – ID сессии для доступка к В Контакте.
82
- * `twitter` — логин от вашего Twitter’а.
88
+ * `twitter_token`, `twitter_secret`данные для доступа к Twitter’у через
89
+ OAuth.
83
90
  * `exclude` — список слов или regexp’ов статусов, которые не нужно публиковать
84
- во В Контакте. Код `:reply` исключ ваши ответы другим пользователя
85
- Twitter.
91
+ во В Контакте. Код `:reply` исключит ваши ответы другим пользователя,
92
+ `:retweet` — ретвиты от вас.
86
93
  * `include` — список слов или regexp’ов для отмены exclude.
87
- * `format` — вид статуса во В Контакте. `%status%` будет заменен на текст
94
+ * `format` — вид статуса во В Контакте. `%status%` будет заменён на текст
88
95
  статуса, `%url%` — на ссылку на статус в Twitter’е.
96
+ * `last` — текст после `format`. Если статус больше допустимого во В Контакте,
97
+ то первым делом обрезается `format`, поэтому `last` удобен для указания ссылки
98
+ на твит.
99
+ * `retweet` — вид ретвита. `%status%` будет заменён на текст, `%author%` — на
100
+ автора твита.
89
101
  * `replace` — список массивов из двух элементов для замены текста в статусе. Код
90
102
  `:user_to_url` заменит имена пользователей на ссылку на их Twitter.
91
103
  * `last_message` — файл, чтобы хранить ID последнего полученного сообщения.
data/bin/i18n/en.yml CHANGED
@@ -3,7 +3,7 @@ vk:
3
3
  email: 'VK e-mail: '
4
4
  password: 'VK password: '
5
5
  error: 'Error: VK e-mail or password is incorrect.'
6
- twitter: 'Twitter name: '
6
+ twitter: "Open in browser %1\nAnd enter the number they give you: "
7
7
  config: 'Config path: '
8
8
  update_error: Overwrite config, because previous version can be loaded.
9
9
  last_message: 'File with last message ID: '
data/bin/i18n/ru.yml CHANGED
@@ -3,7 +3,8 @@ vk:
3
3
  email: 'E-mail от В Контакте: '
4
4
  password: 'Пароль от В Контакте: '
5
5
  error: 'Ошибка: e-mail и пароль для В Контакте неправильны.'
6
- twitter: 'Имя в Twitter’е: '
6
+
7
+ twitter: "Откройте в браузере %1\nИ введите число, которое вам дали: "
7
8
  config: 'Путь к настройкам: '
8
9
  update_error: Старые настройки будут перезаписаны, поскольку их не удалось загрузить.
9
10
  last_message: 'Файл с ID последнего сообщения: '
data/bin/twitter2vk CHANGED
@@ -5,6 +5,9 @@ require 'rubygems'
5
5
  require 'highline/import'
6
6
  require 'r18n-desktop'
7
7
  require 'active_support'
8
+ require 'rvk'
9
+ require 'oauth'
10
+ require 'twitter_oauth'
8
11
 
9
12
  require 'fileutils'
10
13
  require 'net/http'
@@ -30,27 +33,45 @@ HighLine.track_eof = false
30
33
  email = ask(i18n.vk.email)
31
34
  password = ask(i18n.vk.password) { |q| q.echo = false }
32
35
 
33
- resource = Net::HTTP.post_form(URI.parse('http://login.vk.com/'),
34
- { 'email' => email, 'pass' => password, 'vk' => '', 'act' => 'login' })
35
- if resource.body.empty?
36
+ begin
37
+ vk = Vkontakte::User.new(email, password)
38
+ rescue Vkontakte::VkontakteError => e
36
39
  say i18n.vk.error
37
40
  exit
38
41
  end
42
+ config['vk_session'] = vk.session
39
43
 
40
- config['vk_session'] = resource.body.match(/id='s' value='([a-z0-9]+)'/)[1]
41
- config['twitter'] = ask(i18n.twitter)
44
+ KEY = 'lGdk5MXwNqFyQ6glsog0g'
45
+ SECRET = 'jHfpLGY11clNSh9M0Fqnjl7fzqeHwrKSWTBo4i8TUcE'
46
+ consumer = OAuth::Consumer.new(KEY, SECRET, :site => 'http://twitter.com/')
47
+ request = consumer.get_request_token
48
+ pin = ask(i18n.twitter(request.authorize_url))
49
+ access = request.get_access_token(:oauth_verifier => pin)
42
50
 
43
- path = ask(i18n.config) { |q| q.default = "./#{config['twitter']}.yml" }
51
+ config['twitter_token'] = access.token
52
+ config['twitter_secret'] = access.secret
53
+
54
+ twitter = TwitterOAuth::Client.new(:consumer_key => KEY,
55
+ :consumer_secret => SECRET, :token => access.token, :secret => access.secret)
56
+
57
+ path = ask(i18n.config) { |q|
58
+ q.default = "./#{twitter.info['screen_name']}.yml"
59
+ }
44
60
  path = File.expand_path(path)
45
61
 
46
62
  if File.exists? path
47
63
  (config = YAML.load_file(path).merge(config)) rescue puts i18n.update_error
48
64
  end
49
65
 
50
- config['exclude'] = ['#novk', :reply] unless config.has_key? 'exclude'
51
- config['include'] = ['#vk'] unless config.has_key? 'include'
52
- config['replace'] = [] unless config.has_key? 'replace'
53
- config['format'] = '%status%' unless config.has_key? 'format'
66
+ default = {
67
+ 'exclude' => ['#novk', :reply],
68
+ 'include' => ['#vk'],
69
+ 'replace' => [],
70
+ 'format' => '%status%',
71
+ 'last' => '',
72
+ 'retweet' => 'RT %author%: %status%'
73
+ }
74
+ config = default.merge(config)
54
75
 
55
76
  config['last_message'] = ask(i18n.last_message) do |q|
56
77
  q.default = "./#{config['twitter']}_last_message"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twitter2vk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: "0.3"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey "A.I." Sitnik
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-03-03 00:00:00 +03:00
12
+ date: 2010-03-22 00:00:00 +03:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,17 @@ dependencies:
20
20
  requirements:
21
21
  - - "="
22
22
  - !ruby/object:Gem::Version
23
- version: 0.2.6
23
+ version: "0.3"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: activesupport
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
24
34
  version:
25
35
  - !ruby/object:Gem::Dependency
26
36
  name: highline
@@ -32,6 +42,36 @@ dependencies:
32
42
  - !ruby/object:Gem::Version
33
43
  version: "0"
34
44
  version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: rvk
47
+ type: :runtime
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ - !ruby/object:Gem::Dependency
56
+ name: oauth
57
+ type: :runtime
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ - !ruby/object:Gem::Dependency
66
+ name: twitter_oauth
67
+ type: :runtime
68
+ version_requirement:
69
+ version_requirements: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
35
75
  - !ruby/object:Gem::Dependency
36
76
  name: r18n-desktop
37
77
  type: :runtime