Skip to content

Commit

Permalink
fix: 🐛 A vulnerability information acquisition scraping program runs …
Browse files Browse the repository at this point in the history
…daily.
  • Loading branch information
Kobayashi123 committed Jul 2, 2023
1 parent 3e0a65f commit 324cdb3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
12 changes: 4 additions & 8 deletions vuln_info_bot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@
"""

__author__ = 'pigeon-sable'
__version__ = '1.0.1'
__date__ = '2023/05/14 (Created: 2023/04/19)'
__version__ = '1.0.2'
__date__ = '2023/06/02 (Created: 2023/04/19)'

import sys

import discord
from dotenv import load_dotenv

from web import scraping
from discord import notify_info
import notify_info


def main() -> int:
Expand All @@ -40,14 +39,11 @@ def main() -> int:

load_dotenv() # .envファイルから環境変数を読み込む

table_today_vulnerabilities = scraping.table_of_jvn_info(
'https://jvndb.jvn.jp/index.html')

client = discord.Client(intents=discord.Intents.default(),
messages=discord.Intents.messages,
activity=discord.Game(name="/vuln"))

notify_info.event_method(client, table_today_vulnerabilities)
notify_info.event_method(client)

return 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"""

__author__ = 'pigeon-sable'
__version__ = '1.0.1'
__date__ = '2023/05/14 (Created: 2023/05/14)'
__version__ = '1.0.2'
__date__ = '2023/06/02 (Created: 2023/05/14)'

import datetime
import os
Expand All @@ -30,8 +30,13 @@
import discord
from discord.ext import tasks

import scraping

def event_method(client: discord.Client, table_today_vulnerabilities: tuple) -> None:
GET_TIME = '00:00'
NOTIFY_TIME = '12:00'


def event_method(client: discord.Client) -> None:
"""
Discord ボットでの処理を書きます。
イベントが発生したときに、自動的に呼び出されます。
Expand Down Expand Up @@ -61,11 +66,11 @@ async def on_ready():
@tasks.loop(seconds=60)
async def loop():
notify_room = client.get_channel(room_id["VULNERABILITY_ROOM_ID"])
now = datetime.datetime.now(datetime.timezone(
datetime.timedelta(hours=9))).strftime('%H:%M')
if now == '00:00':
now = datetime.datetime.now().strftime('%H:%M')
if now == GET_TIME:
table_today_vulnerabilities = scraping.table_of_jvn_info() # スクレイピングで脆弱性情報を取得する
if now == NOTIFY_TIME:
await notify_room.send('=' * 40)
print(now)
await notify_room.send(f'{datetime.datetime.now().date()} の脆弱性情報をお知らせします。')
await notify_room.send('-' * 40)
for summary, hyper_reference, severity in table_today_vulnerabilities:
Expand Down
21 changes: 19 additions & 2 deletions vuln_info_bot/web/scraping.py → vuln_info_bot/scraping.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@

__author__ = 'pigeon-sable'
__version__ = '1.0.1'
__date__ = '2023/05/14 (Created: 2023/05/14)'
__date__ = '2023/06/02 (Created: 2023/05/14)'

import datetime
import re
import requests
import sys

from bs4 import BeautifulSoup


def table_of_jvn_info(the_url_string: str) -> tuple:
def table_of_jvn_info() -> tuple:
"""
JVNのWebページをウェブスクレイピングし、サマリーとハイパーリンク、CVSSレベルのタプルを作って応答します。
抽出できない場合には、Noneを応答します。
Expand All @@ -42,6 +43,8 @@ def table_of_jvn_info(the_url_string: str) -> tuple:
tuple: サマリーとハイパーリンク、CVSSレベルのタプル
"""

the_url_string = 'https://jvndb.jvn.jp/index.html'

response = requests.get(the_url_string)
if response.status_code != 200:
return None
Expand Down Expand Up @@ -85,3 +88,17 @@ def table_of_jvn_info(the_url_string: str) -> tuple:
table.append([summary, hyper_reference, severity])

return table


def main() -> int:
"""
ライブラリとして提供する table_of_jvn_info() が正しく動作するかチェックする。
"""
table = table_of_jvn_info('https://jvndb.jvn.jp/index.html')
print(table)

return 0


if __name__ == '__main__': # このスクリプトファイルが直接実行されたときだけ、以下の部分を実行する。
sys.exit(main())

0 comments on commit 324cdb3

Please sign in to comment.