goodbye_chatwork 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dd79d9ad1791ace1aca8e01b0e99939ba788d4a8
4
- data.tar.gz: 5c2743edc592a375f1ffe875b4e4c903298467f0
3
+ metadata.gz: 95e08046dc6a9519d244415e3e7cb68a05129eb4
4
+ data.tar.gz: 07c973e5d847863b9dc4c9f21290f100a5c70ac6
5
5
  SHA512:
6
- metadata.gz: a636abf280485000a82afb69bbbebd960b4d98ec2cc7743a6024f9f5779ba46383a2c951f83b38965c085bd664fbbd2f66be8a1c79efa28e206e0dcc9b0948df
7
- data.tar.gz: 537a3dbcf29e44f6e3505d813200369b6063d42e4b2541808215e97d7e60f64805ac492fb9e1c4349c97c140d190f951590af84cebaaca566327bace8f2ce86a
6
+ metadata.gz: 68499d112ee6f83e03339f32a6ebe9dee6182a778f78bc9265349415f4741be65b59ca0049f08f70d2560f7ea14da414a8bc66313fc2e0a5c7b29028d753a8fe
7
+ data.tar.gz: 550a9a66c1e79778d14d7bb43386b03537019cc2c71bc72fd60b4e18dc4abc7dcb88759c7027119c10e1ab70b919055877ab6e3f1cad3648810e95cb96537efb
data/README.md CHANGED
@@ -14,14 +14,22 @@ show chat room list (output: room_id room_name count)
14
14
  11111 chatroom1 24
15
15
  11112 chatroom1 42
16
16
 
17
- export logs (chat logs only: -e option)
17
+ export specified room's chat logs (chat logs only: -e option)
18
18
 
19
19
  $ goodbye_chatwork -i example@example.com -p your_password -e room_id
20
20
 
21
- export logs (chat logs and attachment files: -x option)
21
+ export specified room's chat logs (chat logs and attachment files: -x option)
22
22
 
23
23
  $ goodbye_chatwork -i example@example.com -p your_password -x room_id
24
24
 
25
+ export all room's chat logs (chat logs only: -e option)
26
+
27
+ $ goodbye_chatwork -i example@example.com -p your_password -e all
28
+
29
+ export all room's chat logs (chat logs and attachment files: -x option)
30
+
31
+ $ goodbye_chatwork -i example@example.com -p your_password -x all
32
+
25
33
  ## Information
26
34
 
27
35
  Copyright (c) 2014 swdyh
@@ -13,8 +13,10 @@ if opts['h'] || !email || !password
13
13
  Usage: goodbye_chatwork
14
14
  -i your chatwork id
15
15
  -p your chatwork password
16
- -e room id (export chat logs)
17
- -x room id (export chat logs and download attachment files)
16
+ -e room id (export specified room's chat logs)
17
+ -x room id (export specified room's chat logs and download attachment files)
18
+ -e all (export all room's chat logs)
19
+ -x all (export all room's chat logs and download attachment files)
18
20
  -d dir
19
21
 
20
22
  Example:
@@ -22,13 +24,21 @@ show room list
22
24
 
23
25
  $ goodbye_chatwork -i example@example.com -p your_password
24
26
 
25
- export logs (-e: chat logs only)
27
+ export specified room's chat logs (-e: chat logs only)
26
28
 
27
29
  $ goodbye_chatwork -i example@example.com -p your_password -e room_id
28
30
 
29
- export logs (-x: chat logs and attachment files)
31
+ export specified room's chat logs (-x: chat logs and attachment files)
30
32
 
31
33
  $ goodbye_chatwork -i example@example.com -p your_password -x room_id
34
+
35
+ export all room's chat logs (-e: chat logs only)
36
+
37
+ $ goodbye_chatwork -i example@example.com -p your_password -e all
38
+
39
+ export all room's chat logs (-x: chat logs and attachment files)
40
+
41
+ $ goodbye_chatwork -i example@example.com -p your_password -x all
32
42
  EOS
33
43
  exit
34
44
  end
@@ -43,18 +53,26 @@ if opts['x'] || opts['e']
43
53
  FileUtils.mkdir_p log_dir
44
54
  end
45
55
  room_id = opts['x'] || opts['e']
46
- room = list.find { |i| i[0] == room_id.to_s }
47
- unless room
48
- puts 'no room'
49
- exit 1
50
- end
51
- room_name = room[1].gsub(/[[:cntrl:]\s\/\:]/, '')
52
- out = File.join(log_dir, "#{room_id}_#{room_name}.csv")
53
- file_dir = File.join(log_dir, "#{room_id}_files_#{room_name}")
54
- if opts['x']
55
- gcw.export_csv(room_id, out, { include_file: true, dir: file_dir })
56
- else
57
- gcw.export_csv(room_id, out)
56
+ rooms = if room_id == "all"
57
+ list
58
+ else
59
+ room = list.find { |i| i[0] == room_id.to_s }
60
+ unless room
61
+ puts 'no room'
62
+ exit 1
63
+ end
64
+ [room]
65
+ end
66
+ rooms.each do |room|
67
+ room_id = room[0]
68
+ room_name = room[1].gsub(/[[:cntrl:]\s\/\:]/, '')
69
+ out = File.join(log_dir, "#{room_id}_#{room_name}.csv")
70
+ file_dir = File.join(log_dir, "#{room_id}_files_#{room_name}")
71
+ if opts['x']
72
+ gcw.export_csv(room_id, out, { include_file: true, dir: file_dir })
73
+ else
74
+ gcw.export_csv(room_id, out)
75
+ end
58
76
  end
59
77
  else
60
78
  puts list.map { |i| i.join(' ') }
@@ -72,7 +72,21 @@ module GoodbyeChatwork
72
72
 
73
73
  def old_chat room_id, first_chat_id = 0
74
74
  self.info "get old chat #{first_chat_id}- ..."
75
- res = @client.get "https://www.chatwork.com/gateway.php?cmd=load_old_chat&myid=#{@myid}&_v=1.80a&_av=4&_t=#{@token}&ln=ja&room_id=#{room_id}&last_chat_id=0&first_chat_id=#{first_chat_id}&jump_to_chat_id=0&unread_num=0&file=1&desc=1"
75
+ begin
76
+ res = @client.get do |req|
77
+ req.url "#{@client.url_prefix.to_s}gateway.php?cmd=load_old_chat&myid=#{@myid}&_v=1.80a&_av=4&_t=#{@token}&ln=ja&room_id=#{room_id}&last_chat_id=0&first_chat_id=#{first_chat_id}&jump_to_chat_id=0&unread_num=0&file=1&desc=1"
78
+ req.options.timeout = 5 # open/read timeout in seconds
79
+ req.options.open_timeout = 1000 # connection open timeout in seconds
80
+ end
81
+ rescue Faraday::ConnectionFailed => e
82
+ retry_count ||= 0
83
+ retry_count += 1
84
+ if retry_count < 5
85
+ retry
86
+ else
87
+ raise e
88
+ end
89
+ end
76
90
  self.wait
77
91
  r = JSON.parse(res.body)
78
92
  r['result']['chat_list'].sort_by { |i| - i['id'] }
@@ -105,7 +119,11 @@ module GoodbyeChatwork
105
119
 
106
120
  def file_info(file_id)
107
121
  self.info "get file info #{file_id} ..."
108
- r = @client.get "https://www.chatwork.com/gateway.php?cmd=download_file&bin=1&file_id=#{file_id}"
122
+ r = @client.get do |req|
123
+ req.url "#{@client.url_prefix.to_s}gateway.php?cmd=download_file&bin=1&file_id=#{file_id}"
124
+ req.options.timeout = 5 # open/read timeout in seconds
125
+ req.options.open_timeout = 10 # connection open timeout in seconds
126
+ end
109
127
  self.wait
110
128
  b = r.headers['Content-disposition'].match(/filename="=\?UTF-8\?B\?(.+)\?="/).to_a[1]
111
129
  { url: r.headers['Location'], filename: b.unpack('m')[0] }
@@ -1,3 +1,3 @@
1
1
  module GoodbyeChatwork
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: goodbye_chatwork
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - swdyh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-18 00:00:00.000000000 Z
11
+ date: 2016-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -104,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
104
  version: '0'
105
105
  requirements: []
106
106
  rubyforge_project:
107
- rubygems_version: 2.0.3
107
+ rubygems_version: 2.0.14.1
108
108
  signing_key:
109
109
  specification_version: 4
110
110
  summary: export Chatwork(chatwork.com) logs