actir 1.3.1 → 1.4.0

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: 4b904ce416932f09ab858ed1c1dc89cea7db0f81
4
- data.tar.gz: 5e0b1d3d0a0aa65b8c26addaaa58092f682202f6
3
+ metadata.gz: 27433c3533caed0417a12e065175d9c3724fa333
4
+ data.tar.gz: b5fc2249a62dbd097ff732cc631840d6aa9098f7
5
5
  SHA512:
6
- metadata.gz: 15f5ffdb6691788e9bda1ae1b77d2f5e3096d529d75be2579b26b9b2d9668089a82074299f79a23a4c07f2a014b55bd7ba327366c571742d2dfae7c0799854d3
7
- data.tar.gz: 9547b0964f9b4b85608c1bf0bf8f04e60616dcfe2237742a9ea02459c05403baff8f4fb323ce59787c22097ab8a5efbf0e50971718651a5990054b7c8cbf83e6
6
+ metadata.gz: 2fd1547beb07768fdc19c1b3c30c302832a04c22e18ddee211e58b2583ce913637819dc339058fddad1f0a0394444bb6424051596f8284bfbbbcabe22bcafe8b
7
+ data.tar.gz: 3adf250ea0091676d483f3864eb4e0c879d3dc594b88aba4fd3811503862d97d137a4603ed215bec1134bf2cd006c7898cd89415f03d60f9c37ab2650175bd78
@@ -14,7 +14,7 @@ module Actir
14
14
 
15
15
  class << self
16
16
 
17
- attr_accessor :config_dir
17
+ attr_accessor :default_config_dir
18
18
 
19
19
  #
20
20
  # 从yaml文件中读取youzan的cookies
@@ -23,10 +23,10 @@ module Actir
23
23
  #
24
24
  # @return [Hash] youzan的cookies的hash
25
25
  #
26
- def youzan_cookies(youzan_user)
27
- cfg_str = "cookies." + youzan_user
28
- get(cfg_str)
29
- end
26
+ # def youzan_cookies(youzan_user)
27
+ # cfg_str = "cookies." + youzan_user
28
+ # get(cfg_str)
29
+ # end
30
30
 
31
31
  #
32
32
  # 从yaml文件中读取出所有内容
@@ -53,7 +53,7 @@ module Actir
53
53
  #
54
54
  # @return [Hash] 对应配置项的hash
55
55
  #
56
- def get(key)
56
+ def get(key, config_path = nil)
57
57
  #按照点分割字符串
58
58
  key_array = key.split(".")
59
59
  #先取出数组中的第一个元素当做配置文件名称,并从数组中移除此元素
@@ -62,8 +62,8 @@ module Actir
62
62
  cfg_name = key_array.shift
63
63
  hash = {}
64
64
  #加载yaml配置文件,加锁
65
- lock(file_name) do
66
- hash = cfg_name ? load_file(file(file_name))[cfg_name] : load_file(file(file_name))
65
+ lock(file_name, config_path) do
66
+ hash = cfg_name ? load_file(file(file_name, config_path))[cfg_name] : load_file(file(file_name, config_path))
67
67
  end
68
68
  #遍历key数组
69
69
  until key_array.empty? do
@@ -84,16 +84,16 @@ module Actir
84
84
  #
85
85
  # value : [String] 要修改的值的字符串
86
86
  #
87
- def set(key, value)
87
+ def set(key, value, config_path = nil)
88
88
  #按照点分割字符串
89
89
  key_array = key.split(".")
90
90
  #先取出数组中的第一个元素当做配置文件名称,并从数组中移除此元素
91
91
  file_name = key_array.shift
92
92
  cfg_str = key_array.shift
93
93
  old_value = ""
94
- lock(file_name) do
94
+ lock(file_name, config_path) do
95
95
  #先读出所有的内容
96
- str_array = IO.readlines(file(file_name))
96
+ str_array = IO.readlines(file(file_name, config_path))
97
97
  str_array.each_with_index do |line, index|
98
98
  if ( cfg_str != "" && line =~ /(\s*#{cfg_str}\:\s*)(.*)/ )
99
99
  cfg_key = $1
@@ -109,7 +109,7 @@ module Actir
109
109
  end
110
110
  end
111
111
  end
112
- config_file = File.open(file(file_name), "w")
112
+ config_file = File.open(file(file_name, config_path), "w")
113
113
  str_array.each do |line|
114
114
  config_file.puts line
115
115
  end
@@ -129,16 +129,16 @@ module Actir
129
129
  #
130
130
  # 不同则返回false
131
131
  #
132
- def is_same_day?(file_name)
132
+ def is_same_day?(file_name, config_path = nil)
133
133
  now_date = Time.new.strftime("%m-%d")
134
- modify_date = get_modify_time(file_name)
134
+ modify_date = get_modify_time(file_name, config_path)
135
135
  now_date == modify_date
136
136
  end
137
137
 
138
138
  #获取配置文件的修改时间(只精确到日期,不考虑具体时间)
139
139
  #返回String,格式为:04-27... 12-29
140
- def get_modify_time(file_name)
141
- sh_str = "ls -l " + file(file_name) + " | awk '{print $6 \"-\" $7}'"
140
+ def get_modify_time(file_name, config_path = nil)
141
+ sh_str = "ls -l " + file(file_name, config_path) + " | awk '{print $6 \"-\" $7}'"
142
142
  stat_str = `#{sh_str}`
143
143
  #从中取出月份和日期
144
144
  stat_str =~ /(\d+).*\-(\d+)/
@@ -155,8 +155,8 @@ module Actir
155
155
  end
156
156
 
157
157
  # 多进程操作文件时加锁
158
- def lock(file_name)
159
- File.open(file(file_name), 'r') do |f|
158
+ def lock(file_name, config_path = nil)
159
+ File.open(file(file_name, config_path), 'r') do |f|
160
160
  begin
161
161
  f.flock File::LOCK_EX
162
162
  yield
@@ -167,13 +167,14 @@ module Actir
167
167
  end
168
168
 
169
169
  #配置文件路径
170
- def file(file_name)
170
+ def file(file_name, config_path = nil)
171
+ config_dir = (config_path == nil) ? default_config_dir : config_path
171
172
  File.expand_path(File.join(config_dir, "/#{file_name}.yaml"), __FILE__)
172
173
  end
173
174
 
174
175
  #默认配置文件夹路径
175
- def config_dir
176
- @config_dir ||= File.join($project_path, "config")
176
+ def default_config_dir
177
+ @default_config_dir ||= File.join($project_path, "config")
177
178
  end
178
179
 
179
180
  private
@@ -60,7 +60,7 @@ module Actir
60
60
 
61
61
  #更新百度支付-百付宝的cookies
62
62
  #-u为强制更新,若没有加强制更新命令,则每天自动更新一次
63
- if options[:update] || !(Actir::Config.is_same_day?("cookies"))
63
+ if options[:update] || !(Actir::Config.is_same_day?("cookies", Actir::CookiesBaidu.cookies_path))
64
64
  begin
65
65
  Actir::CookiesBaidu.update_all
66
66
  rescue Exception => e
@@ -0,0 +1,12 @@
1
+ card1:
2
+ BAIDUID: "CA5C0BFFF8A6BCB719914F355E613A1E%3AFG%3D1"
3
+ BDUSS: "EFtRFVRZ3FQblIySk1xeTlvSTVRS3JPTEdyQ35iUXFxdGt1bFNmTXgzU3hZUE5XQUFBQUFBJCQAAAAAAAAAAAEAAAD-BrRddGVzdHdsMjAxNAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALHTy1ax08tWV"
4
+ card2:
5
+ BAIDUID:
6
+ BDUSS:
7
+ card3:
8
+ BAIDUID:
9
+ BDUSS:
10
+ card4:
11
+ BAIDUID:
12
+ BDUSS:
@@ -7,7 +7,17 @@ module Actir
7
7
 
8
8
  # 更新百度账号所有的配置文件
9
9
  def update_all(address = [])
10
- baidu_card = Actir::Config.get("cookies.baidu")
10
+ baidu_card = Actir::Config.get(baifubao_key)
11
+ # 确认目前可用的卡的数目和cookies文件上的是否匹配
12
+ # TODO 先不实现,cookies文件上的cards数量过多目前看不影响
13
+ # baidu_card_cookies = Actir::Config.get("cookies", cookies_path)
14
+ # if baidu_card_cookies != nill && baidu_card != nil
15
+ # if baidu_card_cookies.size > baidu_card.size
16
+ #
17
+ # end
18
+ # else
19
+ # raise "no baifubao cards"
20
+ # end
11
21
  baidu_card.each do |card, value|
12
22
  update_cookies(card, address)
13
23
  end
@@ -16,16 +26,16 @@ module Actir
16
26
  #将所有百度支付卡的available状态恢复为true
17
27
  def re_available
18
28
  #每次登陆都判断一下cookies文件的上一次修改时间和当前时间
19
- #如果日期不同,则刷新所有的cookies文件中baidu-card的状态
20
- unless Actir::Config.is_same_day?("cookies")
21
- Actir::Config.lock("cookies") do
22
- str_array = IO.readlines(cookies_file)
29
+ #如果日期不同,则刷新所有的pay文件中baidu-card的状态
30
+ unless Actir::Config.is_same_day?("cookies", cookies_path)
31
+ Actir::Config.lock("pay") do
32
+ str_array = IO.readlines(baifubao_account_file)
23
33
  str_array.each_with_index do |line, index|
24
34
  if line =~ /available\:\s*false/
25
35
  str_array[index] = line.gsub(/false/, 'true')
26
36
  end
27
37
  end
28
- cookiesfile = File.open(cookies_file, 'w')
38
+ cookiesfile = File.open(baifubao_account_file, 'w')
29
39
  str_array.each do |line|
30
40
  cookiesfile.puts line
31
41
  end
@@ -40,10 +50,14 @@ module Actir
40
50
  # old_config = Actir::Config.config_dir
41
51
  # Actir::Config.config_dir = script_config_path
42
52
  #通过配置文件判断取出可用的卡的参数
43
- baidu_card = Actir::Config.get("cookies.baidu")
53
+ baidu_card = Actir::Config.get(baifubao_key)
44
54
  card = {}
45
55
  baidu_card.each do |key, value|
46
56
  if value["available"] == true
57
+ # 顺便取一下cookies
58
+ baidu_card_cookies = Actir::Config.get("cookies." + key, cookies_path)
59
+ value["BAIDUID"] = baidu_card_cookies["BAIDUID"]
60
+ value["BDUSS"] = baidu_card_cookies["BDUSS"]
47
61
  #有可用的卡,取出cookies等参数
48
62
  card.store(key, value)
49
63
  break
@@ -56,7 +70,7 @@ module Actir
56
70
  # 设置不可用的卡
57
71
  # 入参传入卡的key
58
72
  def set_useless_card(card)
59
- Actir::Config.set("cookies.baidu." + card + "." + "available", "false")
73
+ Actir::Config.set(baifubao_key + "." + card + "." + "available", "false")
60
74
  end
61
75
 
62
76
  # 更新baidu_cookies失败后的清理操作。目前需要手动调用,后续优化
@@ -66,14 +80,12 @@ module Actir
66
80
  end
67
81
  end
68
82
 
69
- private
70
-
71
83
  # 更新配置文件中的baidu_cookies
72
84
  def update_cookies(card, address = [])
73
85
  #打开百付宝
74
86
  open_baifubao(address)
75
87
  #获取对应卡的账号密码
76
- args = Actir::Config.get("cookies.baidu." + card)
88
+ args = Actir::Config.get(baifubao_key + "." + card)
77
89
  #登录百付宝
78
90
  login_baifubao(args["username"], args["password"])
79
91
  #获取cookies
@@ -109,7 +121,7 @@ module Actir
109
121
 
110
122
  # 获取cookies
111
123
  def get_baifubao_cookies
112
- sleep 5
124
+ sleep 3
113
125
  id = @browser.cookies[:BAIDUID][:value]
114
126
  ss = @browser.cookies[:BDUSS][:value]
115
127
  @browser.close
@@ -120,20 +132,31 @@ module Actir
120
132
 
121
133
  def modify_cookies(card, cookies)
122
134
  cookies.each do |key, value|
123
- Actir::Config.set("cookies.baidu."+card+"."+key.to_s , "\""+value.to_s+"\"")
135
+ Actir::Config.set("cookies" + "." + card + "." + key.to_s , "\"" + value.to_s + "\"", cookies_path)
124
136
  end
125
137
  end
126
138
 
127
- # 配置文件所在文件夹的路径
128
- def script_config_path
129
- File.join(File.dirname(__FILE__), "config")
139
+ # 配置文件的上一级路径
140
+ def cookies_path
141
+ File.join(File.dirname(__FILE__), "cookies")
130
142
  end
131
143
 
132
144
  # 配置文件相对路径
133
145
  def cookies_file
134
- File.join(Actir::Config.config_dir, "/cookies.yaml")
146
+ File.join(File.dirname(__FILE__), "cookies", "/cookies.yaml")
135
147
  end
136
148
 
149
+ # 百度账号配置文件
150
+ def baifubao_account_file
151
+ File.join(Actir::Config.default_config_dir, "/pay.yaml")
152
+ end
153
+
154
+ def baifubao_key
155
+ "pay.baifubao"
156
+ end
157
+
158
+ private
159
+
137
160
  def text_baifubao_username
138
161
  @browser.text_field(:id => 'TANGRAM__PSP_4__userName')
139
162
  end
@@ -156,5 +179,3 @@ module Actir
156
179
 
157
180
  end
158
181
 
159
- #Actir::CookiesBaidu.re_available
160
-
@@ -1,3 +1,3 @@
1
1
  module Actir
2
- VERSION = "1.3.1"
2
+ VERSION = "1.4.0"
3
3
  end
@@ -75,6 +75,7 @@ class Browser
75
75
  if hasLoaded == 1
76
76
  break
77
77
  end
78
+ sleep(0.05)
78
79
  end
79
80
  end
80
81
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actir
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - hub
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-14 00:00:00.000000000 Z
11
+ date: 2016-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-unit
@@ -143,6 +143,7 @@ files:
143
143
  - lib/actir/parallel_tests/test/result.rb
144
144
  - lib/actir/parallel_tests/test/runner.rb
145
145
  - lib/actir/remote.rb
146
+ - lib/actir/script/cookies/cookies.yaml
146
147
  - lib/actir/script/cookies_baidu.rb
147
148
  - lib/actir/version.rb
148
149
  - lib/actir/webdriver/browser.rb