Skip to content

Commit

Permalink
add: translate, resolved #3
Browse files Browse the repository at this point in the history
  • Loading branch information
p7e4 committed Jul 18, 2022
1 parent f40e589 commit c309da1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
## Feature

- 支持关键词筛选([@cantgis](https://github.com/p7e4/CVE-Alert/issues/1))
- 支持翻译描述([@cantgis](https://github.com/p7e4/CVE-Alert/issues/3))
- 支持自定义消息模板([@cantgis](https://github.com/p7e4/CVE-Alert/issues/5))


Expand Down
8 changes: 8 additions & 0 deletions cvealert.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
"""

# 翻译描述(翻译效果可能不是很好)
translate = False

# ------------------ conf end -------------------------------
from calendar import timegm
from string import Template
Expand All @@ -40,6 +43,7 @@
}
keywordRegx = [re.compile(f"({i})", re.I) for i in keywords]


def getCve(lastRunTimestamp):
now = time.strftime("%Y-%m-%dT%X:000 UTC", time.gmtime(time.time()))
last = time.strftime("%Y-%m-%dT%X:000 UTC", time.gmtime(lastRunTimestamp))
Expand Down Expand Up @@ -67,6 +71,10 @@ def getCve(lastRunTimestamp):
description = i.sub("**\\1**", description)
if not khit: continue

if translate:
r = requests.get(f"http://fanyi.youdao.com/translate?doctype=json&type=EN2ZH_CN&i={description}").json()
description = r['translateResult'][0][0]['tgt']

data.append(Template(template).safe_substitute({key: value for key, value in vars().items() if key in templateVars}))

return data
Expand Down

0 comments on commit c309da1

Please sign in to comment.