4
4
<dict >
5
5
<key >bundleid </key >
6
6
<string >com.badtudou.jiumo-search </string >
7
- <key >category </key >
8
- <string >Internet </string >
9
7
<key >connections </key >
10
8
<dict >
11
9
<key >1AEE333F-4073-4E76-A286-91F869C65BE1 </key >
64
62
<key >version </key >
65
63
<integer >1 </integer >
66
64
</dict >
65
+ <dict >
66
+ <key >config </key >
67
+ <dict >
68
+ <key >autopaste </key >
69
+ <false />
70
+ <key >clipboardtext </key >
71
+ <string >{query} </string >
72
+ <key >transient </key >
73
+ <false />
74
+ </dict >
75
+ <key >type </key >
76
+ <string >alfred.workflow.output.clipboard </string >
77
+ <key >uid </key >
78
+ <string >1AEE333F-4073-4E76-A286-91F869C65BE1 </string >
79
+ <key >version </key >
80
+ <integer >2 </integer >
81
+ </dict >
67
82
<dict >
68
83
<key >config </key >
69
84
<dict >
84
99
<key >queuedelayimmediatelyinitially </key >
85
100
<false />
86
101
<key >queuedelaymode </key >
87
- <integer >0 </integer >
102
+ <integer >1 </integer >
88
103
<key >queuemode </key >
89
104
<integer >1 </integer >
90
105
<key >runningsubtext </key >
@@ -100,27 +115,27 @@ HOST_FREEGEOIP = 'https://freegeoip.net'
100
115
HOST_JIUMO = 'https://www.jiumodiary.com'
101
116
102
117
HEADERS = {
103
- 'Content-Type' => 'application/x-www-form-urlencoded',
104
- 'X-Requested-With' => 'XMLHttpRequest'
118
+ 'Content-Type' => 'application/x-www-form-urlencoded',
119
+ 'X-Requested-With' => 'XMLHttpRequest'
105
120
}
106
121
107
122
ICONS = {
108
- 'vdisk.weibo.com' => 'weipan.icns',
109
- 'ishare.iask.com' => 'aiwen.icns',
110
- 'local' => 'icon.png',
111
- 'yun.baidu.com' => 'baiduwangpan.icns',
112
- 'pan.baidu.com' => 'baiduwangpan.icns',
113
- '喜马拉雅 (ximalaya.com)' => 'ximalaya.icns',
114
- 'gitbook.com' => 'gitbook.icns',
115
- 'error' => 'error.icns'
123
+ 'vdisk.weibo.com' => 'weipan.icns',
124
+ 'ishare.iask.com' => 'aiwen.icns',
125
+ 'local' => 'icon.png',
126
+ 'yun.baidu.com' => 'baiduwangpan.icns',
127
+ 'pan.baidu.com' => 'baiduwangpan.icns',
128
+ '喜马拉雅 (ximalaya.com)' => 'ximalaya.icns',
129
+ 'gitbook.com' => 'gitbook.icns',
130
+ 'error' => 'error.icns'
116
131
}
117
132
118
133
ERRORS = {
119
- 'tooshort' => '您查询的图书标题长度过短, 请重试',
120
- 'exceed' => '您的查询已达到今日的最高次数',
121
- 'none' => '没有找到相关的文档',
122
- 'network' => '网络错误,请保持网络畅通',
123
- 'default' => '未知错误'
134
+ 'tooshort' => '您查询的图书标题长度过短, 请重试',
135
+ 'exceed' => '您的查询已达到今日的最高次数',
136
+ 'none' => '没有找到相关的文档',
137
+ 'network' => '网络错误,请保持网络畅通',
138
+ 'default' => '未知错误'
124
139
}
125
140
126
141
RESPONSE_SUCCEED = 'succeed'
@@ -129,70 +144,62 @@ NETWORK_ERROR = 'network'
129
144
130
145
keywords = ARGV[0]
131
146
132
- def get_remote_ip
133
- uri = URI("#{HOST_FREEGEOIP}/json/")
134
- res = JSON.parse(Net::HTTP.get(uri))
135
- res['ip']
136
- end
137
-
138
-
139
147
def serch_books(keywords)
140
- remote_ip = get_remote_ip()
141
- url_str = << EOF
142
- #{HOST_JIUMO}/init_hubs.php?q=#{URI::encode(keywords)}& remote_ip=#{remote_ip}& time_int=#{Time.now.to_i}
148
+ url_str = << EOF
149
+ #{HOST_JIUMO}/init_hubs.php?q=#{URI::encode(keywords)}& time_int=#{Time.now.to_i}
143
150
EOF
144
- uri = URI(url_str)
145
- res = Net::HTTP.post_form(uri, HEADERS)
146
- if res.is_a?(Net::HTTPSuccess)
147
- res = JSON.parse(res.body)
148
- raise res['status'] if res['status'] != RESPONSE_SUCCEED
149
- res['id']
150
- end
151
+ uri = URI(url_str)
152
+ res = Net::HTTP.post_form(uri, HEADERS)
153
+ if res.is_a?(Net::HTTPSuccess)
154
+ res = JSON.parse(res.body)
155
+ raise res['status'] if res['status'] != RESPONSE_SUCCEED
156
+ res['id']
157
+ end
151
158
end
152
159
153
160
def fetch_result(id, set=0)
154
- url_str = << EOF
161
+ url_str = << EOF
155
162
#{HOST_JIUMO}/ajax_fetch_hubs.php?id=#{id}& set=#{set}
156
163
EOF
157
- uri = URI(url_str)
158
- res = Net::HTTP.post_form(uri, HEADERS)
159
- if res.is_a?(Net::HTTPSuccess)
160
- res = JSON.parse(res.body)
161
- end
164
+ uri = URI(url_str)
165
+ res = Net::HTTP.post_form(uri, HEADERS)
166
+ if res.is_a?(Net::HTTPSuccess)
167
+ res = JSON.parse(res.body)
168
+ end
162
169
end
163
170
164
171
def parse_result(result)
165
- raise RESULT_NONE if result['sources'].empty?
166
- xml = REXML::Document.new
167
- book_index = 0
168
- element = xml.add_element ('items')
169
- result['sources'].each do |item|
170
- item['details']['data'].each do |book|
171
- book_index += 1
172
- item_xml = element.add_element('item')
173
- item_xml.add_element('title').add_text("#{book_index} . #{book['title']}")
174
- item_xml.add_element('subtitle').add_text("#{book['host']} - #{book['des']}")
175
- item_xml.add_element('arg').add_text(book['link'])
176
- item_xml.add_element('autocomplete').add_text(book['title'])
177
- item_xml.add_element('match').add_text(book['title'])
178
- item_xml.add_element('icon').add_text("#{Dir.pwd}/#{ICONS[book['host']]}")
179
- end
180
- end
181
- xml.write
172
+ raise RESULT_NONE if result['sources'].empty?
173
+ xml = REXML::Document.new
174
+ book_index = 0
175
+ element = xml.add_element ('items')
176
+ result['sources'].each do |item|
177
+ item['details']['data'].each do |book|
178
+ book_index += 1
179
+ item_xml = element.add_element('item')
180
+ item_xml.add_element('title').add_text("#{book_index} . #{book['title']}")
181
+ item_xml.add_element('subtitle').add_text("#{book['host']} - #{book['des']}")
182
+ item_xml.add_element('arg').add_text(book['link'])
183
+ item_xml.add_element('autocomplete').add_text(book['title'])
184
+ item_xml.add_element('match').add_text(book['title'])
185
+ item_xml.add_element('icon').add_text("#{Dir.pwd}/#{ICONS[book['host']]}")
186
+ end
187
+ end
188
+ xml.write
182
189
end
183
190
184
191
begin
185
- result = fetch_result( serch_books(keywords))
186
- parse_result(result)
192
+ result = fetch_result( serch_books(keywords))
193
+ parse_result(result)
187
194
rescue => exception
188
- message = exception.message
189
- message = NETWORK_ERROR if exception.instance_of? SocketError
190
- xml = REXML::Document.new
191
- element = xml.add_element ('items')
192
- item_xml = element.add_element('item')
193
- item_xml.add_element('title').add_text("错误: #{!ERRORS[message].nil? ? ERRORS[message]:ERRORS['default']}")
194
- item_xml.add_element('icon').add_text("#{Dir.pwd}/#{ICONS['error']}")
195
- xml.write
195
+ message = exception.message
196
+ message = NETWORK_ERROR if exception.instance_of? SocketError
197
+ xml = REXML::Document.new
198
+ element = xml.add_element ('items')
199
+ item_xml = element.add_element('item')
200
+ item_xml.add_element('title').add_text("错误: #{!ERRORS[message].nil? ? ERRORS[message]:ERRORS['default']}")
201
+ item_xml.add_element('icon').add_text("#{Dir.pwd}/#{ICONS['error']}")
202
+ xml.write
196
203
end
197
204
198
205
</string >
@@ -216,26 +223,11 @@ end
216
223
<key >version </key >
217
224
<integer >2 </integer >
218
225
</dict >
219
- <dict >
220
- <key >config </key >
221
- <dict >
222
- <key >autopaste </key >
223
- <false />
224
- <key >clipboardtext </key >
225
- <string >{query} </string >
226
- <key >transient </key >
227
- <false />
228
- </dict >
229
- <key >type </key >
230
- <string >alfred.workflow.output.clipboard </string >
231
- <key >uid </key >
232
- <string >1AEE333F-4073-4E76-A286-91F869C65BE1 </string >
233
- <key >version </key >
234
- <integer >2 </integer >
235
- </dict >
236
226
</array >
237
227
<key >readme </key >
238
- <string >Alfred workflow for Jiumo E-Book Search(鸠摩电子书搜索) </string >
228
+ <string >Alfred workflow for Jiumo E-Book Search(鸠摩电子书搜索)
229
+
230
+ https://github.com/duxiaodou/Alfred-workflow-Jiumo </string >
239
231
<key >uidata </key >
240
232
<dict >
241
233
<key >1AEE333F-4073-4E76-A286-91F869C65BE1 </key >
261
253
</dict >
262
254
</dict >
263
255
<key >version </key >
264
- <string >1.0 </string >
256
+ <string >1.1 </string >
265
257
<key >webaddress </key >
266
258
<string >https://github.com/BadTudou/alfred-workflow-jiumo </string >
267
259
</dict >
0 commit comments