Explorar o código

check msg.html also

marton levente hai 4 meses
pai
achega
8eb1e42f24
Modificáronse 2 ficheiros con 8 adicións e 4 borrados
  1. 3 2
      mail_alert.py
  2. 5 2
      mail_alert2.py

+ 3 - 2
mail_alert.py

@@ -119,8 +119,9 @@ def mail_alert2(event=None):
                     if msg.uid not in container:
                         soup = BeautifulSoup(msg.html, 'html.parser')
                         msg_text = soup.prettify().replace('<br/>', '').replace('<html>', '').replace('<head>', '').replace('</head>', '').replace('<body>', '').replace('<div>', '').replace('</div>', '').replace('</body>', '').replace('</html>', '')
+                        msg_text = msg_text[:msg_text.find('Intraday transactions')]
                         try:
-                            if len(msg.text) != 0:
+                            if len(msg.text) or len(msg.html) != 0:
                                 bot2.send_message(chat_id=config['AUTH']['chatid'], text=msg_text)
                             else:
                                 bot2.send_message(chat_id=config['AUTH']['chatid'], text=msg_text)
@@ -128,7 +129,7 @@ def mail_alert2(event=None):
                             print('message appended', len(container))
                         except BadRequest:
                             try:
-                                if len(msg.text) != 0:
+                                if len(msg.text) or len(msg.html) != 0:
                                     bot2.send_message(chat_id=config['AUTH']['chatid'], text=msg_text // 5)
                                 else:
                                     bot2.send_message(chat_id=config['AUTH']['chatid'], text=msg_text // 5)

+ 5 - 2
mail_alert2.py

@@ -45,12 +45,15 @@ def mail_alert():
             msgs = [msgs for msgs in mailbox.fetch(AND(seen=False), mark_seen=True)]
             for msg in msgs:
                 chk = mask(msg, 'account')
+                # print(chk)
                 if chk:
                     if msg.uid not in container:
+                        # print(f'{msg.uid} not in container')
                         soup = BeautifulSoup(msg.html, 'html.parser')
                         msg_text = soup.prettify().replace('<br/>', '').replace('<html>', '').replace('<head>', '').replace('</head>', '').replace('<body>', '').replace('<div>', '').replace('</div>', '').replace('</body>', '').replace('</html>', '')
+                        msg_text = msg_text[:msg_text.find('Intraday transactions')]
                         try:
-                            if len(msg.text) != 0:
+                            if len(msg.text) or len(msg.html) != 0:
                                 bot.send_message(chat_id=config['AUTH']['chatid'], text=msg_text)
                             else:
                                 bot.send_message(chat_id=config['AUTH']['chatid'], text=msg_text)
@@ -58,7 +61,7 @@ def mail_alert():
                             print('message appended', len(container))
                         except BadRequest:
                             try:
-                                if len(msg.text) != 0:
+                                if len(msg.text) or len(msg.html) != 0:
                                     bot.send_message(chat_id=config['AUTH']['chatid'], text=msg_text // 5)
                                 else:
                                     bot.send_message(chat_id=config['AUTH']['chatid'], text=msg_text // 5)