Add a little bit of functionality.... in theory it should be able to run.... in theory, not yet tested
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
import email
|
||||
import imaplib
|
||||
import time
|
||||
from SubjectHandler import SubjectHandler
|
||||
|
||||
SubHandler = SubjectHandler()
|
||||
|
||||
mail_addr = None
|
||||
mail_pwd = None
|
||||
|
||||
"""
|
||||
CONFIG SECTION
|
||||
@@ -8,6 +14,13 @@ CONFIG SECTION
|
||||
imap_port = 993
|
||||
imap_server = "imap.gmail.com"
|
||||
mail_domain = "gmail.com"
|
||||
mail_time_delta = 30 # in seconds
|
||||
|
||||
secrets_file = "./secrets.txt"
|
||||
|
||||
# add all nodes here in this(↓) pattern
|
||||
# SubHandler += SubjectHandler.Node(regex, function)
|
||||
SubHandler += SubjectHandler.Node("Test[0-9]*", lambda x: print(str(x)))
|
||||
|
||||
"""
|
||||
END OF CONFIG SECTION
|
||||
@@ -20,6 +33,8 @@ def import_secrets(file):
|
||||
:param file: path to file: content is '[MAIL]\n[PWD]'
|
||||
:return: secrets, that can be saved to global variables
|
||||
"""
|
||||
global mail_addr
|
||||
global mail_pwd
|
||||
with open(file) as f:
|
||||
mail_addr = f.readline()
|
||||
mail_pwd = f.readline()
|
||||
@@ -53,5 +68,12 @@ def mail_handling():
|
||||
return messages
|
||||
|
||||
|
||||
import_secrets(secrets_file)
|
||||
while True:
|
||||
SubHandler.run(mail_handling())
|
||||
time.sleep(mail_time_delta)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import re
|
||||
|
||||
|
||||
class SubjectHandler:
|
||||
"""
|
||||
class for managing all the sub-functions(nodes)
|
||||
"""
|
||||
class Node:
|
||||
"""
|
||||
node containing a sub-function
|
||||
"""
|
||||
def __init__(self, regex, f):
|
||||
"""
|
||||
creating node
|
||||
:param regex: regex checked against subject
|
||||
:param f: function to be called if keyword in subject
|
||||
"""
|
||||
self.regex = regex
|
||||
self.func = f
|
||||
|
||||
def __init__(self):
|
||||
self.nodes = []
|
||||
|
||||
def __add__(self, other):
|
||||
"""
|
||||
adding node to self
|
||||
:param other: node
|
||||
:return: self with added node
|
||||
"""
|
||||
self.nodes.append(other)
|
||||
return self
|
||||
|
||||
def __len__(self):
|
||||
return len(self.nodes)
|
||||
|
||||
def run(self, messages):
|
||||
"""
|
||||
running the class and checking if there's a regex match in any node and then running the node
|
||||
:param messages: array of messages, which should be checked
|
||||
:return: -
|
||||
"""
|
||||
for message in messages:
|
||||
subject = message[0]
|
||||
for node in self.nodes:
|
||||
if re.match(node.regex, subject):
|
||||
node.func(message)
|
||||
@@ -0,0 +1 @@
|
||||
setuptools~=46.4.0
|
||||
@@ -0,0 +1,2 @@
|
||||
mail@example.com
|
||||
Password123
|
||||
Reference in New Issue
Block a user