ztil 0.1.0 → 0.1.1

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: a6839a88f4cf0db429b404edc3bb25acaa89858a
4
- data.tar.gz: bd86cc3540ac94f42bc2d335859c4dd44ef78283
3
+ metadata.gz: c2974ee4ce44cb15628960237d66cb73a4fa3c71
4
+ data.tar.gz: 1cdcf63f5455c12fd8480b74358881e5e82ef996
5
5
  SHA512:
6
- metadata.gz: 5911a3f795394899e5dbec597da51e59cf7102e61757d9e4961673f8a2e898d74daf6ead357b909d3024eaab3a792336578e6a3ee27b7fa0ef284b693f462537
7
- data.tar.gz: 8e644cdeabfa1a94bda6c3959370b283fb3199f4bed72442ed1a8a2d9d36882d7dae43dac85c5a36801f02ab48886749035bb129a539906186aa7c725e4a298a
6
+ metadata.gz: fcd8899b8124c52648a13a808e292b73a660952ea43f09b5c1c0ff4232fef584c56d54421e0056868f55345fa7d0f28978b855affea16e4a2dc2c1d20bea230b
7
+ data.tar.gz: f2e2bec7bc0ea6c69b3aba11209629da62ae4f919b3e153b7cb511d31dcc00fc071c9850b5aa575dd200ad3ae2ef76db8a94407422e39cd38ff1d84a408c96ad
data/lib/ztil/baidu.rb ADDED
@@ -0,0 +1,26 @@
1
+ require 'rest-client'
2
+ require 'json'
3
+
4
+ # 百度的地理位置API | http://developer.baidu.com/map/index.php?title=webapi/guide/webservice-geocoding
5
+ module Ztil
6
+ module Baidu
7
+
8
+ BAIDU_AK = 'A0f00186ba072b824d88d6300c9f7f86'
9
+ BAIDU_URL = 'http://api.map.baidu.com'
10
+
11
+ class << self
12
+
13
+ def geocoder(address, options = {})
14
+ r = JSON.parse RestClient.get("#{BAIDU_URL}/geocoder/v2/", { params: {address: address, output: :json, ak: BAIDU_AK, city: options[:city]} })
15
+ JSON.pretty_generate(r)
16
+ end
17
+
18
+ def coordcoder(location, options = {})
19
+ r = JSON.parse RestClient.get("#{BAIDU_URL}/geocoder/v2/", { params: {location: location, output: :json, ak: BAIDU_AK, coordtype: options[:coordtype]} })
20
+ JSON.pretty_generate(r)
21
+ end
22
+
23
+ end
24
+
25
+ end
26
+ end
data/lib/ztil/command.rb CHANGED
@@ -1,34 +1,23 @@
1
1
  # encoding: utf-8
2
2
  require 'thor'
3
- require 'rest-client'
4
- require 'json'
5
3
 
6
4
  module Ztil
7
5
  class Command < Thor
8
6
  include Thor::Actions
9
7
 
10
- def self.source_root
11
- File.expand_path File.join( File.dirname(__FILE__), '../../', 'Backup' )
12
- end
13
-
14
- BAIDU_AK = 'A0f00186ba072b824d88d6300c9f7f86'
15
- BAIDU_URL = 'http://api.map.baidu.com'
16
-
17
- # 百度的地理位置API | http://developer.baidu.com/map/index.php?title=webapi/guide/webservice-geocoding
18
-
19
8
  desc 'geocoder ADDRESS', '根据百度API, 将地址转换成经纬度'
20
9
  method_option :city, desc: '地址所在的城市', required: false
21
10
  def geocoder(address)
22
- r = JSON.parse RestClient.get("#{BAIDU_URL}/geocoder/v2/", { params: {address: address, output: :json, ak: BAIDU_AK, city: options[:city]} })
23
- say JSON.pretty_generate(r)
11
+ require 'ztil/baidu'
12
+ say Baidu.geocoder(address, options)
24
13
  end
25
14
 
26
15
  desc 'coordcoder LOCATION', '根据百度API, 将经纬度转换成地址, 纬度(小)在前, 经度在后, 逗号分隔'
27
16
  method_option :coordtype, desc: '坐标的类型', default: 'wgs84ll', required: false, aliases: 't',
28
17
  desc: '目前支持的坐标类型包括:bd09ll(百度经纬度坐标)、gcj02ll(国测局经纬度坐标)、wgs84ll( GPS经纬度)'
29
18
  def coordcoder(location)
30
- r = JSON.parse RestClient.get("#{BAIDU_URL}/geocoder/v2/", { params: {location: location, output: :json, ak: BAIDU_AK, coordtype: options[:coordtype]} })
31
- say JSON.pretty_generate(r)
19
+ require 'ztil/baidu'
20
+ say Baidu.coordcoder(location, options)
32
21
  end
33
22
 
34
23
  # 备份数据库 | https://github.com/meskyanichi/backup
@@ -36,12 +25,13 @@ module Ztil
36
25
  # 关心的是数据库,存储以及执行时间和邮件通知
37
26
  #
38
27
  # @example
39
- # ztil backup --databases="mysql,mongodb" --storages="qi_niu" --email="xxx@xxx.com" --schedule="1.day&4:30 am"
28
+ # ztil backup --databases="mysql,mongodb" --storages="qi_niu" --email="xxx@xxx.com" --schedule="1.day&4:30 am" --run_prefix="bundle exec"
40
29
  desc 'backup DATABASE_NAME', '备份数据库, 传入all表示所有databases'
41
- method_option :databases, desc: '需要备份的数据库类型, 支持mysql以及mongodb', required: true
42
- method_option :storages, desc: '备份数据的存储方式, 支持存储到七牛'
43
- method_option :email, desc: '备份成功后通知的邮箱'
44
- method_option :schedule, desc: '按计划执行, 默认只执行一次'
30
+ method_option :databases, desc: '需要备份的数据库类型, 支持mysql以及mongodb', required: true
31
+ method_option :storages, desc: '备份数据的存储方式, 支持存储到七牛'
32
+ method_option :email, desc: '备份成功后通知的邮箱'
33
+ method_option :schedule, desc: '按计划执行, 默认只执行一次'
34
+ method_option :run_prefix, desc: '运行命令的前缀, 例如bundle exec'
45
35
  def backup(name)
46
36
  storages = options[:storages] || 'local'
47
37
 
@@ -104,11 +94,11 @@ module Ztil
104
94
  append_to_file( File.join(schedule_config_path, 'schedule.rb') ) do
105
95
  <<-SCH
106
96
  every #{time}, :at => '#{at}' do
107
- command "backup_zh perform -t #{name}"
97
+ command "#{options[:run_prefix]} backup_zh perform -t #{name}"
108
98
  end
109
99
  SCH
110
100
  end
111
- run "whenever -f #{File.join(schedule_config_path, 'schedule.rb')}"
101
+ run "whenever -f #{File.join(schedule_config_path, 'schedule.rb')} --update-crontab"
112
102
  else
113
103
  run "backup_zh perform -t #{name}"
114
104
  end
data/lib/ztil.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ztil
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ztil
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - zires
@@ -79,6 +79,7 @@ files:
79
79
  - Rakefile
80
80
  - bin/ztil
81
81
  - lib/ztil.rb
82
+ - lib/ztil/baidu.rb
82
83
  - lib/ztil/command.rb
83
84
  homepage: https://github.com/zires/ztil
84
85
  licenses: