Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
H
HappyKit
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mobile
HappyKit
Commits
a0eff2bd
Commit
a0eff2bd
authored
Mar 30, 2019
by
汪洋
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ok
parent
4f618a93
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
32 deletions
+34
-32
notify_release_date_by_email.rb
notify_release_date_by_email.rb
+34
-32
No files found.
notify_release_date_by_email.rb
View file @
a0eff2bd
#! /bin/ruby
require
'httparty'
require
'json'
require
"ostruct"
require
'net/smtp'
require
'mail'
=begin
知识点:网络请求库 HTTParty
gem HTTParty 一个现成的网络请求,用法简单到有些奇怪。当然也可以用ruby原生的请求方法,只是很繁琐
知识点:JSON转模型,ostruct
gem ostruct 提供了一行代码将json string转模型的能力
例如:obj = JSON.parse(json_string, object_class: OpenStruct)
就直接得到了模型。注意OpenStruct为固定写法,不需要改变
知识点:JSON解析
gem json 提供了JSON解析
类如:JSON.parse(json_string),就可以将这段string转为相应的模型
知识点:发送邮件
gem mail 提供了邮件能力。具体见send_email方法的实现
=end
# TODO: 将登录帐号及邮箱换成只在内网使用的,比如jaguar
def
login
# 登录
options
=
{
...
...
@@ -16,7 +32,13 @@ def login
}
login
=
HTTParty
.
post
(
"http://wiki.wanmeizhensuo.com/dologin.action"
,
options
)
# puts login.to_s
$cookie
=
login
.
headers
[
'set-cookie'
]
cookie
=
login
.
headers
[
'set-cookie'
]
$event_headers
=
{
:headers
=>
{
'Cookie'
=>
cookie
,
'Accept'
=>
'application/json, text/javascript, */*; q=0.01'
},
}
end
def
today
...
...
@@ -32,16 +54,10 @@ def dev_end_time
return
today
>>
1
end
def
get_event
event_headers
=
{
:headers
=>
{
'Cookie'
=>
$cookie
,
'Accept'
=>
'application/json, text/javascript, */*; q=0.01'
},
}
def
get_dev_events_response
dev_event_id
=
"3bcd7d25-37d0-4624-83d2-691c456a76a8"
event_query
=
"subCalendarId=
#{
dev_event_id
}
&userTimeZoneId=Asia%2FShanghai&start=
#{
dev_start_time
}
T00%3A00%3A00Z&end=
#{
dev_end_time
}
T00%3A00%3A00Z&_=1552802345400"
events
=
HTTParty
.
get
(
"http://wiki.wanmeizhensuo.com/rest/calendar-services/1.0/calendar/events.json?
#{
event_query
}
"
,
event_headers
)
events
=
HTTParty
.
get
(
"http://wiki.wanmeizhensuo.com/rest/calendar-services/1.0/calendar/events.json?
#{
event_query
}
"
,
$
event_headers
)
end
class
Deliver
...
...
@@ -51,26 +67,17 @@ class Deliver
@title
=
title
@date
=
date
end
end
# 参数:版本号
# 返回值:发版时间
# 开发的第三的时间,与发版时间肯定有先后顺序
# 返回值:Deliver
def
get_deliver_info
event_headers
=
{
:headers
=>
{
'Cookie'
=>
$cookie
,
'Accept'
=>
'application/json, text/javascript, */*; q=0.01'
},
}
# 以后端上线时间为准,保证程序员不被其它工作量压到下一个迭代的开发周
# dev_event_id = "e1c8aef8-130e-40bf-8f6c-fe0e5c5dbd9c" # 提交时间
backend_deploy_event_id
=
"8389fda3-a06c-49b5-af85-788c4af12071"
# 后端上线时间
event_query
=
"subCalendarId=
#{
backend_deploy_event_id
}
&userTimeZoneId=Asia%2FShanghai&start=
#{
dev_start_time
}
T00%3A00%3A00Z&end=
#{
dev_end_time
}
T00%3A00%3A00Z&_=1552802345400"
events
=
HTTParty
.
get
(
"http://wiki.wanmeizhensuo.com/rest/calendar-services/1.0/calendar/events.json?
#{
event_query
}
"
,
event_headers
)
events
=
HTTParty
.
get
(
"http://wiki.wanmeizhensuo.com/rest/calendar-services/1.0/calendar/events.json?
#{
event_query
}
"
,
$
event_headers
)
obj
=
JSON
.
parse
(
events
.
body
,
object_class:
OpenStruct
)
# 发版时间大于今天,则是这个版本的发版时间
for
event
in
obj
.
events
deploy_date
=
Date
.
parse
(
event
.
start
)
if
deploy_date
>
today
...
...
@@ -80,11 +87,8 @@ def get_deliver_info
end
def
should_send_email_today
events
=
get_event
# events.body 这样就得到了body string
# 用OpenStruct就直接生成了一个类
# ruby是动态语言
obj
=
JSON
.
parse
(
events
.
body
,
object_class:
OpenStruct
)
response
=
get_dev_events_response
obj
=
JSON
.
parse
(
response
.
body
,
object_class:
OpenStruct
)
for
event
in
obj
.
events
start
=
Date
.
parse
(
event
.
start
)
if
start
==
today
...
...
@@ -110,15 +114,13 @@ def send_email(deliver_info)
}
end
mail_subject
=
"更美app
#{
deliver_info
.
title
}
版本商店物料信息"
mail_body
=
"Hi,All,
#{
deliver_info
.
title
}
时间为
#{
deliver_info
.
date
.
to_s
}
,请准备商店相关的物料信息(是否更换APP icon和商店海报),谢谢~"
mail
=
Mail
.
deliver
do
# 其实下面都是方法调用,不要被迷惑了
# to ['dujuan@igengmei.com', 'hualu@igengmei.com', 'wangjun@igengmei.com', 'lizhen@igengmei.com', 'sunwenhui@igengmei.com', 'tanchenshuai@igengmei.com', 'zhucuicui@igengmei.com', 'huchunhe@igengmei.com', 'dongqiang@igengmei.com', 'SJ-liuxiao@igengmei.com']
to
[
'igiu_1988@126.com'
]
from
'wangyang@igengmei.com'
subject
mail_subject
body
mail_body
subject
"更美app
#{
deliver_info
.
title
}
商店物料信息"
body
"Hi,All,
#{
deliver_info
.
title
}
时间为
#{
deliver_info
.
date
.
to_s
}
,请准备商店相关的物料信息(是否更换APP icon和商店海报),谢谢~"
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment