Skip to content

Commit

Permalink
Add support for Nichinoken
Browse files Browse the repository at this point in the history
  • Loading branch information
Bas-Man committed Mar 30, 2022
1 parent 0285ca3 commit 0150815
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
FROM_KIDZDUO = "[email protected]"
FROM_GATE = "キッズセキュリティ ミマモルメ <[email protected]>"
FROM_TRAIN = "東急セキュリティ <[email protected]>"
FROM_NICHINOKEN = "[email protected]"

BUS_SUB = "エキッズ"
TRAIN_SUB = "エキッズ"
KIDZDUO_SUB = "入退室情報のお知らせ"
GATE_SUB = "【キッズセキュリティミマモルメ】通過のお知らせ"
NICHI_SUB = "日能研パス・サイン メール送信"


SUBJECTS = [BUS_SUB, TRAIN_SUB, KIDZDUO_SUB, GATE_SUB]
SUBJECTS = [BUS_SUB, TRAIN_SUB, KIDZDUO_SUB, GATE_SUB, NICHI_SUB]
10 changes: 10 additions & 0 deletions gmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ def handle_each_email(service, message_id, logger) -> tuple:
elif sender == constants.FROM_TRAIN:
data = patterns.findMatches(email_body, patterns.TRAIN_DATA)
notifier = "TRAIN"
elif sender == constants.FROM_NICHINOKEN:
data = patterns.findMatches(email_body, patterns.NICHI_DATE)
notifier = "NICHINOKEN"
else:
# This needs to be logged. Means failed to match sender.
# if notifier is None:
Expand Down Expand Up @@ -340,6 +343,13 @@ def main():
)
send_notification(message)
processed = True
elif notifier == "NICHINOKEN":
logger.debug("Nichinoken")
message = (f"{secrets.NAME} Nichinoken.\n"
f"{data['date']} at {data['time']}"
)
send_notification(message)
processed = True
elif notifier is None and data is not None:
logger.warning("Subject matched but From was not matched")
elif notifier is None and data is None:
Expand Down
5 changes: 5 additions & 0 deletions patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
r"「(?P<provider>[一-龯]+)・(?P<station>[一-龯]+)」を(?P<enterexit>[一-龯]+)"
)

NICHI_DATE = (
r"(?P<date>\d{2}月\d{2}日)\s(?P<time>\d{2}時\d{2}分)"
r"(?:(?:(?:\r)?\n)+[^\n]+)(?:\r)?\n「日能研 駒沢大学校 1」"
)


def findMatches(string, regex) -> dict:
"""
Expand Down

0 comments on commit 0150815

Please sign in to comment.