-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessage.py
85 lines (65 loc) · 2.99 KB
/
message.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# -*- coding: utf-8 -*-
import smtplib
from email.mime.text import MIMEText
from datetime import datetime
from slacker import Slacker
import mongo
import telegram
date = datetime.now().strftime('%Y-%m-%d %H:%M')
def mail_push():
with open('result.txt', 'rt', encoding='UTF8') as file:
contents = file.read()
# ------------------ 메일보내기 https://yeolco.tistory.com/93 --- 참고
# 세션생성
s = smtplib.SMTP('smtp.gmail.com', 587)
# TLS 보안 시작
s.starttls()
# 로그인 인증
s.login('[email protected]', 'opjjhvlrvidyfzdo')
# 보낼 메시지 설정
msg = MIMEText(contents)
msg['Subject'] = date + ' 공고문 스크랩'
# 메일 보내기 (보내는사람, 받을사람, 내용)
s.sendmail("[email protected]", "[email protected]", msg.as_string())
s.sendmail("[email protected]", "[email protected]", msg.as_string())
s.sendmail("[email protected]", "[email protected]", msg.as_string())
# 세션 종료
s.quit()
def slack_push():
with open('result.txt', 'rt', encoding='UTF8') as file:
contents = file.read()
# slack 메세지 보내기
token = "xoxp-612642071956-608238527025-608321031505-4f7c38c1646cc67698aef010e2dd1b76"
slack = Slacker(token)
num = mongo.count()
if num:
slack.chat.post_message("#todays-posts", ("새로운 공고문이 " + str(num) + "개 올라왔습니다."))
else:
slack.chat.post_message("#todays-posts", "새로운 공고문이 없습니다.")
slack.chat.post_message("#todays-posts",contents)
def telegram_push():
with open('result.txt', 'rt', encoding='UTF8') as file:
contents = file.read()
# chat_id 확인
# https://api.telegram.org/bot818222067:AAFJWKcasPwz2DPRZu6HSFmzv8CerHHsm_k/getUpdates
API_KEY = '818222067:AAFJWKcasPwz2DPRZu6HSFmzv8CerHHsm_k'
bot = telegram.Bot(token=API_KEY)
try :
# 대표님 톡방
chat_id = "-1001360438299"
num = mongo.count()
ment = "새로운 공고문이 " + str(num) + "개 올라왔습니다. \n자세히 보기 : http://bvpost.shop/"
bot.sendMessage(chat_id=chat_id, text= ment)
# 우리톡방
chat_id2 = "-1001447356505"
bot.sendMessage(chat_id=chat_id2, text= contents)
except Exception:
mail_push()
bot.sendMessage(chat_id=chat_id2, text=date+ '결과 \n메세지가 너무길어서 결과를 메일로 보내드렸습니다.')
def site_error_push(name):
API_KEY = '818222067:AAFJWKcasPwz2DPRZu6HSFmzv8CerHHsm_k'
bot = telegram.Bot(token=API_KEY)
content = name+" - 오류가 발생하였습니다."
# 우리톡방
chat_id2 = "-1001447356505"
bot.sendMessage(chat_id=chat_id2, text= content, encodeing="UTF8")