twitter2vk_reposter 0.1.2 → 0.2

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.
Files changed (4) hide show
  1. data/ChangeLog +5 -0
  2. data/README.markdown +21 -11
  3. data/bin/twitter2vk_reposter +20 -2
  4. metadata +2 -2
data/ChangeLog CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.2 (Желе)
2
+ * Add format to config to change reposted status view.
3
+ * Add replace to config to change reposted status text.
4
+ * Fix installer: expand path to reposter.
5
+
1
6
  == 0.1.2 (Лаваш)
2
7
  * Fix installer: expand all paths in config.
3
8
  * Fix json dependency in responser gem.
data/README.markdown CHANGED
@@ -32,11 +32,16 @@ You can follow author @andrey_sitnik to receive last updates info.
32
32
  ### Config
33
33
  Config is a YAML files with options:
34
34
 
35
- * vk_session – session ID to access to VK.
36
- * twitter – your Twitter login.
37
- * exclude – list of text or regexp patterns to exclude statuses from your VK.
38
- * include list of text or regexp patterns to repost excluded statuses.
39
- * last_messagefile to contain ID of last reposted message.
35
+ * `vk_session` – session ID to access to VK.
36
+ * `twitter` – your Twitter login.
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.
39
+ * `include`list of text or regexp patterns to repost excluded statuses.
40
+ * `format` – format reposted status. `%status%` will be replaced by status text,
41
+ `%url%` by status link on Twitter.
42
+ * `replace` – list of array with 2 elements to replace text in status. Code
43
+ `:user_to_url` will replace user name to his Twitter link.
44
+ * `last_message` – file to contain ID of last reposted message.
40
45
 
41
46
  ## Russian
42
47
 
@@ -73,9 +78,14 @@ Config is a YAML files with options:
73
78
  ### Настройки
74
79
  Настройки хранятся в YAML файле с полями:
75
80
 
76
- * vk_session – ID сессии для доступка к В Контакте.
77
- * twitter — логин от вашего Twitter’а.
78
- * exclude — список слов или regexp’ов для статусов, которые не нужно публиковать
79
- во В Контакте.
80
- * include — список слов или regexp’ов для отмены exclude.
81
- * last_messageфайл, чтобы хранить ID последнего полученного сообщения.
81
+ * `vk_session` – ID сессии для доступка к В Контакте.
82
+ * `twitter` — логин от вашего Twitter’а.
83
+ * `exclude` — список слов или regexp’ов статусов, которые не нужно публиковать
84
+ во В Контакте. Код `:reply` исключ ваши ответы другим пользователя
85
+ Twitter.
86
+ * `include`список слов или regexp’ов для отмены exclude.
87
+ * `format` — вид статуса во В Контакте. `%status%` будет заменен на текст
88
+ статуса, `%url%` — на ссылку на статус в Twitter’е.
89
+ * `replace` — список массивов из двух элементов для замены текста в статусе. Код
90
+ `:user_to_url` заменит имена пользователей на ссылку на их Twitter.
91
+ * `last_message` — файл, чтобы хранить ID последнего полученного сообщения.
@@ -16,6 +16,8 @@ if ARGV.empty? or '--help' == ARGV.first or '-h' == ARGV.first
16
16
  end
17
17
 
18
18
  def check(text, pattern)
19
+ pattern = /^@\w/ if :reply == pattern
20
+
19
21
  if pattern.is_a? String
20
22
  text.index(pattern)
21
23
  elsif pattern.is_a? Regexp
@@ -41,6 +43,20 @@ def load_vk_activityhash(session)
41
43
  profile.match(/<input type='hidden' id='activityhash' value='([^']+)'>/)[1]
42
44
  end
43
45
 
46
+ def format_status(status, config)
47
+ format = config['format'] || '%status%'
48
+ text = format.gsub('%status%', status['text']).gsub('%url%',
49
+ "twitter.com/#{status['user']['screen_name']}/#{status['id']}")
50
+
51
+ Array(config['replace']).each do |replace|
52
+ replace = [/@([a-zA-Z0-9_]+)/, 'twitter.com/\\1'] if :user_to_url == replace
53
+ text.gsub!(replace[0], replace[1])
54
+ end
55
+
56
+ text = text[0...159] + '…' if text.length > 160
57
+ text
58
+ end
59
+
44
60
  def set_status_to_vk(text, session, activityhash)
45
61
  url = URI.parse('http://vk.com/profile.php')
46
62
  request = Net::HTTP::Post.new(url.path)
@@ -61,12 +77,14 @@ request = open('http://twitter.com/statuses/user_timeline/' +
61
77
  "#{config['twitter']}.json?#{query}")
62
78
  statuses = JSON.parse(request.read.to_s)
63
79
 
80
+ statuses.delete statuses.last
64
81
  unless statuses.empty?
65
82
  activityhash = load_vk_activityhash(config['vk_session'])
66
83
 
67
84
  statuses.each do |status|
68
- next unless repost? status['text'], config
69
- set_status_to_vk(status['text'], config['vk_session'], activityhash)
85
+ text = format_status(status, config)
86
+ next unless repost? text, config
87
+ set_status_to_vk(text, config['vk_session'], activityhash)
70
88
  sleep 10 unless statuses.last == status
71
89
  end
72
90
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twitter2vk_reposter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: "0.2"
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: 2009-10-11 00:00:00 +04:00
12
+ date: 2009-10-13 00:00:00 +04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency