Source plug-in settings

Create a folder notify

__init__.py

Copy the code
Import Settings
 Import the importlib 


DEF send_all (Content):
     for path_str in settings.NOTIFY_LIST:   # 1. one out of a string of 'notify.email.Email' 
        The module_path, path_str.rsplit class_name = ( ' . ' , maxsplit is =. 1)   # 2 from the right in accordance with a cutting point [ 'notify.email', 'In Email'] 
        Module1 = importlib.import_module (the module_path)   # from notity Import MSG, In Email, WeChat 
        CLS = getattr (Module1, class_name)   # using all reflection Thought the object are acquired from the property or method cls = a file name of a class of 
        obj = cls ()   # class instance of generating object 
        obj.send (content)  # Object transfer method
Copy the code

email.py

class In Email (Object):
     DEF  the __init__ (Self):
         Pass   # Send message codes required configuration 

    DEF Send (Self, Content):
         Print ( ' e-mail notification: S% ' % Content)

msg.py

class   Msg (Object):
     DEF  the __init__ (Self):
         Pass   # Send SMS configuration code required 

    DEF Send (Self, Content):
         Print ( ' SMS notification: S% ' % Content)

qq.py

class QQ (Object):
     DEF  the __init__ (Self):
         Pass   # transmitting the code required to prepare qq 

    DEF Send (Self, Content):
         Print ( ' qq notification: S% ' % Content)

wechat.py

class WeChat (Object):
     DEF  the __init__ (Self):
         Pass   # transmitting micro-channel configuration code required 

    DEF Send (Self, Content):
         Print ( ' micro-channel notification: S% ' % Content)

settings.py

NOTIFY_LIST = [
    'notify.email.Email',
    'notify.msg.Msg',
    # 'notify.wechat.WeChat',
    'notify.qq.QQ',
]

start.py

Import the Notify 

notify.send_all ( ' National Day holiday to remember to put eight days oh ' )

Create a folder notify

__init__.py

Copy the code
Import Settings
 Import the importlib 


DEF send_all (Content):
     for path_str in settings.NOTIFY_LIST:   # 1. one out of a string of 'notify.email.Email' 
        The module_path, path_str.rsplit class_name = ( ' . ' , maxsplit is =. 1)   # 2 from the right in accordance with a cutting point [ 'notify.email', 'In Email'] 
        Module1 = importlib.import_module (the module_path)   # from notity Import MSG, In Email, WeChat 
        CLS = getattr (Module1, class_name)   # using all reflection Thought the object are acquired from the property or method cls = a file name of a class of 
        obj = cls ()   # class instance of generating object 
        obj.send (content)  # Object transfer method
Copy the code

email.py

class In Email (Object):
     DEF  the __init__ (Self):
         Pass   # Send message codes required configuration 

    DEF Send (Self, Content):
         Print ( ' e-mail notification: S% ' % Content)

msg.py

class   Msg (Object):
     DEF  the __init__ (Self):
         Pass   # Send SMS configuration code required 

    DEF Send (Self, Content):
         Print ( ' SMS notification: S% ' % Content)

qq.py

class QQ (Object):
     DEF  the __init__ (Self):
         Pass   # transmitting the code required to prepare qq 

    DEF Send (Self, Content):
         Print ( ' qq notification: S% ' % Content)

wechat.py

class WeChat (Object):
     DEF  the __init__ (Self):
         Pass   # transmitting micro-channel configuration code required 

    DEF Send (Self, Content):
         Print ( ' micro-channel notification: S% ' % Content)

settings.py

NOTIFY_LIST = [
    'notify.email.Email',
    'notify.msg.Msg',
    # 'notify.wechat.WeChat',
    'notify.qq.QQ',
]

start.py

Import the Notify 

notify.send_all ( ' National Day holiday to remember to put eight days oh ' )

Guess you like

Origin www.cnblogs.com/asdaa/p/11621830.html