コード例 #1
0
 def subscriber(self):
     if self._subscriber is None:
         self._subscriber = pubsub_v1.SubscriberClient()
         self._subscription_path = self._subscriber.subscription_path(
             cfg.get('pub-sub', 'PROJECT_ID'),
             cfg.get('pub-sub', 'SUBSCRIPTION_NAME'))
     return self._subscriber
コード例 #2
0
ファイル: publisher.py プロジェクト: reenal/mailing-services
 def publisher(self):
     if self._publisher is None:
         self._publisher = pubsub_v1.PublisherClient()
         self._topic_path = self._publisher.topic_path(
             cfg.get('pub-sub', 'PROJECT_ID'),
             cfg.get('pub-sub', 'TOPIC_NAME'))
     return self._publisher
コード例 #3
0
def get_user_subscriptions():
    try:

        final_result = []
        response = requests.get(cfg.get('api', 'GET_USER'), verify=False)
        response.raise_for_status()
        response_json = response.json()
        response_list = response_json['users']
        user_list = cfg.get('user', 'USER').split(',')
        for user_data in response_list:
            if user_data['username'] in user_list:
                result = [
                    user_data['username'], user_data['email'],
                    user_data['subscriptions']
                ]
                final_result.append(result)
        return final_result

    except requests.exceptions.HTTPError as httpErr:
        print("Http Error:", httpErr)
    except requests.exceptions.ConnectionError as connErr:
        print("Error Connecting:", connErr)
    except requests.exceptions.Timeout as timeOutErr:
        print("Timeout Error:", timeOutErr)
    except requests.exceptions.RequestException as reqErr:
        print("Something Else:", reqErr)
コード例 #4
0
def start():
    c = config.get()
    print('Waiting', c.startup_delay, 'seconds ...')
    time.sleep(c.startup_delay)
    print('Starting heartbeat ...')
    consecutive_failures = 0

    while consecutive_failures < c.failures:
        print('Checking ...')
        try:
            response = requests.get(url=c.endpoint, timeout=c.timeout)

            if response.status_code == 200:
                consecutive_failures = 0
                print('Success')
            else:
                consecutive_failures += 1
                print('Fail')

        except Exception as e:
            consecutive_failures += 1
            print('Fail')

        if consecutive_failures < c.failures:
            time.sleep(c.interval)

    notifs_sent = 0
    # send at most 50 notifications
    while notifs_sent < min(c.max_notifications, 50):
        # send a notification at most every 5 minutes
        send_notifications()
        notifs_sent += 1
        time.sleep(max(c.notification_interval, 300))
コード例 #5
0
def send_notifications():
    c = config.get()
    for destination in [slack, email, sms]:
        module_name = destination.__name__.split('.')[-1]
        if c.notifications[module_name]['enabled']:
            dest_config = c.notifications[module_name]
            kwargs = {k: dest_config[k] for k in dest_config if k != 'enabled'}
            destination.send(**kwargs)
コード例 #6
0
ファイル: sms.py プロジェクト: batwood001/whatsupdoc
def send(numbers, message):
    twilio = config.get().auth['twilio']
    client = Client(twilio['account_sid'], twilio['auth_token'])

    print('Sending SMS notifications ...')
    for number in numbers:
        message = client.messages.create(to="+1" + str(number),
                                         from_=twilio['from'],
                                         body=message)

        print(message.sid)
コード例 #7
0
ファイル: test_plugins.py プロジェクト: oskarsh/Yin-Yang
    def test_set_empty_theme(self):
        for pl in plugins:
            with self.subTest(plugin=pl):
                try:
                    pl.set_theme('')
                except ValueError as e:
                    self.assertEqual(
                        'Theme \"\" is invalid', str(e),
                        'set_theme() should throw an exception if the theme is empty'
                    )
                    return

                self.assertTrue(
                    False,
                    'set_theme() should throw an exception if the theme is empty!'
                )
                # try to return to previous theme
                pl.set_theme(
                    config.get(pl.name + config.get('theme').title() +
                               'Theme'))
コード例 #8
0
 def __init__(self):
     self.server = cfg.get('email', 'MAIL_SERVER')
     self.port = cfg.get('email', 'MAIL_PORT')
     self.username = cfg.get('email', 'MAIL_USERNAME')
     self.password = cfg.get('email', 'MAIL_PASSWORD')
     self.sender = cfg.get('email', 'MAIL_SENDER')
     self.env = Environment(
         loader=FileSystemLoader(cfg.get('email', 'TEMPlATE_PATH')))
     self._mail = None
コード例 #9
0
ファイル: logger.py プロジェクト: vitus133/rwar_vpn
    def logger(self):
        name = '.'.join([config.get('name').split('.')[0]])
        lg = logging.getLogger(name)
        lg.setLevel(10)
        formatter = logging.Formatter(
            '%(name)s %(asctime)s %(levelname)s [%(module)s:%(lineno)s]: %(message)s',
            datefmt='%Y-%m-%d %H:%M:%S')
        if not lg.hasHandlers():
            # logging to file
            path = PurePath(config.get('log_path'), config.get('name'))
            handler = RotatingFileHandler(
                str(path),
                maxBytes=config.get('rotate_bytes'),
                backupCount=config.get('rotate_count'))
            handler.setLevel(config['file_level'])
            handler.setFormatter(formatter)
            lg.addHandler(handler)

            # logging to console
            handler = logging.StreamHandler()
            handler.setLevel(config['console_level'])
            handler.setFormatter(formatter)
            lg.addHandler(handler)
        return lg
コード例 #10
0
def get_content(scription_data):
    try:
        if scription_data:
            data = {"subscriptions": scription_data}
            data_json = json.dumps(data)
            headers = {'Content-type': 'application/json'}
            resp = req.post(cfg.get('api', 'GET_CONTENT'),
                            verify=False,
                            data=data_json,
                            headers=headers)
            resp_dict = resp.json()
            return resp_dict
        else:
            return None

    except req.exceptions.HTTPError as httpErr:
        print("Http Error:", httpErr)
    except req.exceptions.ConnectionError as connErr:
        print("Error Connecting:", connErr)
    except req.exceptions.Timeout as timeOutErr:
        print("Timeout Error:", timeOutErr)
    except req.exceptions.RequestException as reqErr:
        print("Something Else:", reqErr)
コード例 #11
0
ファイル: web_app.py プロジェクト: BALEHOK/lead-zeppelin
from flask import Flask, send_from_directory, request
from flask_cors import CORS
from flask_graphql import GraphQLView
# from mongoengine import connect

from src.config import config
from src.leads.lead_interactor import LeadInteractor
from src.leads.models import db

from src.web.schema import schema
from src.leads.payment_interactor import PaymentInteractor
# from src.processes.process_interactor import ProcessInteractor

web_app = Flask(__name__)
CORS(web_app)
web_app.debug = config.get('debug')
web_app.config['SQLALCHEMY_DATABASE_URI'] = config.get('sql_db_url')
web_app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

with web_app.app_context():
    db.init_app(web_app)

# connect(host=config.get('mongo_web_uri'))

# Routes
web_app.add_url_rule(
    '/graphql',
    view_func=GraphQLView.as_view(
        'graphql',
        schema=schema,
        graphiql=True
コード例 #12
0
ファイル: celery_app.py プロジェクト: BALEHOK/lead-zeppelin
from celery import Celery
from mongoengine import connect

from src.config import config

connect(host=config.get('mongo_web_uri'))
celery_app = Celery('lead_zeppelin', broker=config.get('redis_uri'))
celery_app.autodiscover_tasks(packages=['src.processes'])
コード例 #13
0
 def __init__(self, config):
     config = config  # use config.py as this instance's config
     irc = irc_.irc(config)  # use irc.py for socket connections
     incoming_data.initialize(irc, config.get('channels', {}))
     self.runs = scrape()