コード例 #1
0
ファイル: rss.py プロジェクト: kianby/stacosys
def generate_site(token):

    site = Site.select().where(Site.token == token).get()
    rss_title = get_template("rss_title_message").render(site=site.name)
    md = markdown.Markdown()

    items = []
    for row in (
        Comment.select()
        .join(Site)
        .where(Site.token == token, Comment.published)
        .order_by(-Comment.published)
        .limit(10)
    ):
        item_link = "%s://%s%s" % (config.get(config.RSS_PROTO), site.url, row.url)
        items.append(
            PyRSS2Gen.RSSItem(
                title="%s - %s://%s%s"
                % (config.get(config.RSS_PROTO), row.author_name, site.url, row.url),
                link=item_link,
                description=md.convert(row.content),
                guid=PyRSS2Gen.Guid("%s/%d" % (item_link, row.id)),
                pubDate=row.published,
            )
        )

    rss = PyRSS2Gen.RSS2(
        title=rss_title,
        link="%s://%s" % (config.get(config.RSS_PROTO), site.url),
        description="Commentaires du site '%s'" % site.name,
        lastBuildDate=datetime.now(),
        items=items,
    )
    rss.write_xml(open(config.get(config.RSS_FILE), "w"), encoding="utf-8")
コード例 #2
0
 def __init__(self, bot):
     BaseCog.__init__(self, bot)
     self.duels = {}
     self.duel_ctr = 0
     self.duel_delay = int(config.get('Duel', 'duel_delay', fallback=120))
     self.duel_battle_delay = int(
         config.get('Duel', 'duel_battle_delay', fallback=10))
コード例 #3
0
    def __init__(self, bot):
        BaseCog.__init__(self, bot)
        self.holiday_announcement_channel = None

        with open(config.cogs_data_path + '/holidays.json',
                  'r') as holidays_file:
            self.holidays = json.load(holidays_file)

        self.holiday_announcement_channel_id = int(
            config.get('Private',
                       'holiday_announcement_channel_id',
                       fallback=''))
        self.free_points_on_holiday = int(
            config.get('Holidays', 'free_points_on_holiday', fallback=5))
        self.holiday_points = int(
            config.get('Holidays', 'holiday_points', fallback=5))

        # We need to make sure that when the bot crashes, it keeps info
        # on which minigame was chosen at the beginning of the day for holiday points.
        self.holiday_minigame = self.bot.database.table('holiday_minigame')
        self.minigames = []

        timed_events_cog = BaseCog.load_dependency(self, 'TimedEvents')
        timed_events_cog.register_timed_event(self.print_holiday)

        self.bot.info_text += 'Holidays:' + linesep + '  The bot will post a description of holidays on appropriate days. We celebrate these holidays by gambling a random minigame for free and also by giving away more free points.' + linesep + linesep
コード例 #4
0
ファイル: jabberbot.py プロジェクト: davux/Tavu
 def acceptMessage(self, stanza):
     """Tell if the message is accepted or not."""
     section = 'Message filters'
     sender = stanza.get_from().bare()
     try:
         crit = config.get(section, 'accept')
     except (NoOptionError, NoSectionError):
         crit = 'roster+self'
     debug("Critere: %s" % crit, 8);
     if crit == 'all':
         return True
     if crit == 'none':
         return False
     if crit in ['self', 'roster+self']:
         if sender == self.jid.bare():
             return True
     if crit in ['list', 'roster+list']:
         try:
             list = config.get(section, 'list').split(', ')
         except (NoOptionError, NoSectionError):
             list = []
         if sender.as_utf8() in list:
             return True
     if crit in ['roster', 'roster+list', 'roster+self']:
         try:
             self.roster.get_item_by_jid(sender)
             return True
         except KeyError:
             return False
     return False
コード例 #5
0
ファイル: notifications.py プロジェクト: davux/Tavu
def message2text(body, fromName, resource, fromAddr, subject):
    """
    Return a triplet from the body + sender + subject
    - the first element is the text of the notification
    - the second element is the application name
    - the third element is the summary
    """
    if fromName == None:
        fromName = fromAddr
    if subject == None:
        subject = ''
    section = 'Event information'
    try: text_format = config.get(section, 'text')
    except: text_format = '$body'
    try: appName_format = config.get(section, 'app name')
    except: appName_format = '$senderresource'
    try: summary_format = config.get(section, 'summary')
    except: summary_format = '$subject'
    subst = {'body': body, 'senderjid': fromAddr, 'subject': subject,
             'sender': fromName, 'senderresource': resource}
    text_tmpl = Template(text_format)
    appName_tmpl = Template(appName_format)
    summary_tmpl = Template(summary_format)
    return (text_tmpl.safe_substitute(subst),
            appName_tmpl.safe_substitute(subst),
            summary_tmpl.safe_substitute(subst))
コード例 #6
0
def generate_site(token):

    site = Site.select().where(Site.token == token).get()
    rss_title = get_template('rss_title_message').render(site=site.name)
    md = markdown.Markdown()

    items = []
    for row in (Comment.select().join(Site).where(
            Site.token == token,
            Comment.published).order_by(-Comment.published).limit(10)):
        item_link = '%s://%s%s' % (config.get(
            config.RSS_PROTO), site.url, row.url)
        items.append(
            PyRSS2Gen.RSSItem(
                title='%s - %s://%s%s' % (config.get(
                    config.RSS_PROTO), row.author_name, site.url, row.url),
                link=item_link,
                description=md.convert(row.content),
                guid=PyRSS2Gen.Guid('%s/%d' % (item_link, row.id)),
                pubDate=row.published,
            ))

    rss = PyRSS2Gen.RSS2(
        title=rss_title,
        link='%s://%s' % (config.get(config.RSS_PROTO), site.url),
        description='Commentaires du site "%s"' % site.name,
        lastBuildDate=datetime.now(),
        items=items,
    )
    rss.write_xml(open(config.get(config.RSS_FILE), 'w'), encoding='utf-8')
コード例 #7
0
ファイル: timed_task.py プロジェクト: Lustidrike/Economy-Bot
    def __init__(self, bot):
        BaseCog.__init__(self, bot)

        self.hour = int(
            config.get('TimedTasks', 'timed_task_hour', fallback='5'))
        self.minute = int(
            config.get('TimedTasks', 'timed_task_minute', fallback='0'))
        self.second = int(
            config.get('TimedTasks', 'timed_task_second', fallback='0'))

        # If the bot dies during the day and is restarted, self.time_until_execute will be set correctly
        # HOWEVER, if the bot is dead in that moment when it should execute its tasks and is restarted subsequently it will not execute the timed tasks.
        # This is a known issue but 'fixed' e.g. by running a cronjob to restart the bot 5 minutes before the timed events should be executed.

        self.timed_task = bot.loop.create_task(self.timed_task())
        self.timed_events = [
        ]  # Cogs register their tasks here that should be executed

        # Figure out number of seconds until next time we need to execute our events
        tomorrow = datetime.datetime.now() + datetime.timedelta(1)

        execute_time = datetime.datetime(year=tomorrow.year,
                                         month=tomorrow.month,
                                         day=tomorrow.day,
                                         hour=self.hour,
                                         minute=self.minute,
                                         second=self.second)

        self.time_until_execute = (execute_time -
                                   datetime.datetime.now()).seconds
        print(self.time_until_execute)
コード例 #8
0
ファイル: __init__.py プロジェクト: batulu12/notebook
 def __init__(self):
     session_server = config.get('SESSION','server')
     cache_server = config.get('CACHE','server')
     behaviors = {'tcp_nodelay':True,'ketama':True}
     self.session = pylibmc.Client(eval(session_server),binary=True,behaviors=behaviors)
     self.cache = pylibmc.Client(eval(cache_server),binary=True,behaviors=behaviors)
     self.user = UserCtrl()
     self.note = NoteCtrl()
コード例 #9
0
ファイル: main.py プロジェクト: cuzn/finalProj
 def __init__(self):
     self.host = config.get('server','ip')
     self.port = string.atoi(config.get('server' , 'port'))
     self.server = socket.socket()
     self.server.bind((self.host , self.port))
     self.server.listen(5)
     self.inputs = [self.server]
     self.clientList = {}
コード例 #10
0
ファイル: base.py プロジェクト: batulu12/notebook
 def get_session_id(self, expires=0):
     cookie_name = config.get('SESSION', 'cookie_name')
     secret = config.get('SESSION', 'secret')
     if expires:
         expires = datetime.datetime.utcnow() + datetime.timedelta(seconds=expires)
     session_id = self.gen_session_id(secret)
     self.set_cookie(cookie_name, session_id, expires=expires)
     return session_id
コード例 #11
0
ファイル: mailer.py プロジェクト: bigbeer/stacosys
def _open_mailbox():
    return imap.Mailbox(
        config.get(config.IMAP_HOST),
        config.get_int(config.IMAP_PORT),
        config.get_bool(config.IMAP_SSL),
        config.get(config.IMAP_LOGIN),
        config.get(config.IMAP_PASSWORD),
    )
コード例 #12
0
    def test_get_default(self):
        """Tests that the default config is loaded with default values"""

        os.environ['CONFIG_FILE'] = '/fake/path'

        from conf import config

        self.assertEqual('127.0.0.1', config.get('app', 'address'))
        self.assertEqual('8080', config.get('app', 'port'))
コード例 #13
0
def mail(message):
    s = smtplib.SMTP(config.get(config.SMTP_HOST),
                     config.getInt(config.SMTP_PORT))
    if config.getBool(config.SMTP_STARTTLS):
        s.starttls()
    s.login(config.get(config.SMTP_LOGIN), config.get(config.SMTP_PASSWORD))
    s.sendmail(config.get(config.SMTP_LOGIN), config.get(config.SMTP_TO),
               message)
    s.quit()
コード例 #14
0
ファイル: gambling.py プロジェクト: Lustidrike/Economy-Bot
    def __init__(self, bot):
        BaseCog.__init__(self, bot)
        self.lock = True
        bot.info_text += 'Gambling: ' + linesep + '  ' + config.currency_name + 's can be gambled with in various minigames. Participation is optional.' + linesep + linesep

        with open(config.cogs_data_path + '/gambling.json', 'r') as gambling_config:
            self.weapon_emotes = json.load(gambling_config)['weapon_emotes']

        self.lock_max_bet = int(config.get('Gambling', 'lock_max_bet', fallback=15))
        self.unlock_max_points_to_give_per_day = int(config.get('Gambling', 'unlock_max_points_to_give_per_day', fallback=10000))
        self.subscriber_role = config.get('Gambling', 'subscriber_role', fallback='')
コード例 #15
0
def fetchforward():
    M = poplib.POP3(config.get(config.POP3_HOST))
    M.user(config.get(config.POP3_LOGIN))
    M.pass_(config.get(config.POP3_PASSWORD))
    numMessages = len(M.list()[1])
    for i in range(numMessages):
        (_, body, _) = M.retr(i + 1)
        message = b"\n".join(body)
        mail(message)
        r = M.dele(i + 1)
        logger.info(r)
    M.quit()
コード例 #16
0
ファイル: __init__.py プロジェクト: batulu12/notebook
    def __init__(self):
        host = config.get('DB_NOTE', 'host')
        port = config.get('DB_NOTE', 'port')
        user = config.get('DB_NOTE', 'user')
        db = config.get('DB_NOTE', 'db')
        passwd = config.get('DB_NOTE', 'passwd')

        mysql = 'mysql://%s:%s@%s:%s/%s?charset=utf8'%(user,passwd,host,port,db)
        self.engine = create_engine(mysql)
        print '--->init db:%s' % mysql
        Session = scoped_session(sessionmaker(bind=self.engine))
        self.session = Session()
        self.ping()
        PeriodicCallback(self.ping, 3600*1000).start()
def create():
	# Load the class that will handle API requests
	cfsb_handler = config.get('Service Broker', 'handler')

	print("Attempting to start with {} handler".format(cfsb_handler))

	cfsb_module_default = importlib.import_module("cf_service_broker.handlers.{handler}".format(handler="default_service_broker"))
	cfsb_module = importlib.import_module("cf_service_broker.handlers.{handler}".format(handler=cfsb_handler))

	for name, obj in inspect.getmembers(cfsb_module_default):
		if inspect.isclass(obj) and obj.__name__[-13:] == "ServiceBroker":
			cfsb_class_default = obj

	for name, obj in inspect.getmembers(cfsb_module):
		if inspect.isclass(obj) and obj.__name__[-13:] == "ServiceBroker":
			cfsb_class = obj
	try:
		if cfsb_class.__name__ == "DefaultServiceBroker":
			print "Warning: Your running DefaultServiceBroker, which probably isn't what you want"
		elif not issubclass(cfsb_class,cfsb_class_default):
			raise exceptions.InvalidServiceBroker("{classname} is not a subclass of {classname_default}".format(classname=cfsb_class.__name__,classname_default=cfsb_class_default.__name__))
	except:
		raise
	
	cfsb_object = cfsb_class()

	return cfsb_class, cfsb_object
コード例 #18
0
ファイル: run.py プロジェクト: kianby/mail2diaspora
def mail2diaspora(config_pathname):

    # configure logging
    logger = logging.getLogger(__name__)
    configure_logging(logging.INFO)

    logger.info("Start mail2diaspora application")
    config.initialize(config_pathname)

    os.chdir(config.get(config.TEMP))

    # cron email fetcher
    scheduler = BackgroundScheduler()
    scheduler.add_job(
        diaspora.mail_poll, "interval", seconds=config.getInt(config.MAIL_POLLING)
    )
    scheduler.start()

    print("Press Ctrl+{0} to exit".format("Break" if os.name == "nt" else "C"))
    try:
        # This is here to simulate application activity (which keeps the main thread alive).
        while True:
            time.sleep(2)
    except (KeyboardInterrupt, SystemExit):
        # Not strictly necessary if daemonic mode is enabled but should be done if possible
        scheduler.shutdown()

    logger.info("Stop mail2diaspora application")
コード例 #19
0
ファイル: run.py プロジェクト: bigbeer/stacosys
def stacosys_server(config_pathname):

    app = Flask(__name__)
    config.initialize(config_pathname, app)

    # configure logging
    logger = logging.getLogger(__name__)
    configure_logging(logging.INFO)
    logging.getLogger('werkzeug').level = logging.WARNING
    logging.getLogger('apscheduler.executors').level = logging.WARNING

    # initialize database
    from core import database

    database.setup()

    # cron email fetcher
    app.config.from_object(
        JobConfig(config.get_int(config.IMAP_POLLING),
                  config.get_int(config.COMMENT_POLLING)))
    scheduler = APScheduler()
    scheduler.init_app(app)
    scheduler.start()

    logger.info('Start Stacosys application')

    # generate RSS for all sites
    from core import rss

    rss.generate_all()

    # start Flask
    from interface import api

    logger.info('Load interface %s' % api)

    from interface import form

    logger.info('Load interface %s' % form)

    app.run(
        host=config.get(config.HTTP_HOST),
        port=config.get(config.HTTP_PORT),
        debug=False,
        use_reloader=False,
    )
コード例 #20
0
ファイル: run.py プロジェクト: kianby/stacosys
def stacosys_server(config_pathname):

    app = Flask(__name__)
    config.initialize(config_pathname, app)

    # configure logging
    logger = logging.getLogger(__name__)
    configure_logging(logging.INFO)
    logging.getLogger("werkzeug").level = logging.WARNING
    logging.getLogger("apscheduler.executors").level = logging.WARNING

    # initialize database
    from core import database

    database.setup()

    # cron email fetcher
    app.config.from_object(
        JobConfig(
            config.getInt(config.MAIL_POLLING), config.getInt(config.COMMENT_POLLING)
        )
    )
    scheduler = APScheduler()
    scheduler.init_app(app)
    scheduler.start()

    logger.info("Start Stacosys application")

    # generate RSS for all sites
    from core import rss

    rss.generate_all()

    # start Flask
    from interface import api
    from interface import form

    logger.debug("Load interface %s" % api)
    logger.debug("Load interface %s" % form)

    app.run(
        host=config.get(config.HTTP_HOST),
        port=config.get(config.HTTP_PORT),
        debug=False,
        use_reloader=False,
    )
コード例 #21
0
ファイル: cron.py プロジェクト: kianby/alerte-enlevement
def findArticles(numero_rubrique, numero_articles):
    articles = []
    for numero_article in numero_articles:
        article_url = config.get(config.SITE_ARTICLE_URL).format(
            numero_rubrique, numero_article)
        date, titre, contenu = getArticle(article_url)
        articles.append({"date": date, "titre": titre, "contenu": contenu})
    return articles
コード例 #22
0
ファイル: emailer.py プロジェクト: kianby/srmail
def fetch_email():
    try:
        with imap.Mailbox(
            config.get(config.IMAP_HOST),
            config.getInt(config.IMAP_PORT),
            config.getBool(config.IMAP_SSL),
            config.get(config.IMAP_LOGIN),
            config.get(config.IMAP_PASSWORD),
        ) as mbox:
            count = mbox.get_count()
            for num in range(count):
                msg = mbox.fetch_message(num + 1)
                if persist(msg):
                    mbox.delete_message(msg["index"])
                    time.sleep(10)
    except:
        logger.exception("fetch mail exception")
コード例 #23
0
ファイル: base.py プロジェクト: batulu12/notebook
 def get_session(self):
     '''
     get session
     '''
     cookie_name = config.get('SESSION', 'cookie_name')
     session_id = self.get_cookie(cookie_name)
     session = ctrl.session.get(str(session_id))
     return session
コード例 #24
0
ファイル: mailer.py プロジェクト: kianby/mail2diaspora
def fetch():
    mails = []
    r = requests.get(config.get(config.MAILER_URL) + "/mbox")
    if r.status_code == 200:
        payload = r.json()
        if payload["count"] > 0:
            mails = payload["emails"]
    return mails
コード例 #25
0
    def __init__(self, bot):
        BaseCog.__init__(self, bot)
        self.br_participants = []
        self.br_holiday_points_used = []
        self.br_last_ann = ''
        self.br_pool = 0
        self.br_bet = 0
        self.br_closed = True

        with open(config.cogs_data_path + '/gambling.json', 'r') as gambling_config:
            data = json.load(gambling_config)
            self.arena_init_texts = data['arena_init_texts']
            self.custom_weapons = data['custom_weapons']
            self.custom_suicides = data['custom_suicides']
            self.suicide_emotes = data['suicide_emotes']
            self.exotic_weapons = data['exotic_weapons']

        self.br_delay = int(config.get('BattleRoyale', 'br_delay', fallback=180))
        self.br_min_bet = int(config.get('BattleRoyale', 'br_min_bet', fallback=5))
        self.br_min_users = int(config.get('BattleRoyale', 'br_min_users', fallback=3))
        self.p_suicide = float(config.get('BattleRoyale', 'p_suicide', fallback=1))
        self.p_block = float(config.get('BattleRoyale', 'p_block', fallback=0.3))
        self.p_bomb_or_melee = float(config.get('BattleRoyale', 'p_bomb_or_melee', fallback=0.15))
        self.p_exotic = float(config.get('BattleRoyale', 'p_exotic', fallback=0.05))

        if (self.br_min_users < 3):
            raise RuntimeError('Minimum number of BR participants is 3!')

        # Register battle royale to be a possible minigame for holiday points
        holidays = self.bot.get_cog('Holidays')

        if holidays is not None:
            holidays.minigames.append('Battle Royale')
コード例 #26
0
ファイル: base.py プロジェクト: batulu12/notebook
 def delete_session(self):
     '''
     delete session
     '''
     cookie_name = config.get('SESSION', 'cookie_name')
     session_id = self.get_cookie(cookie_name)
     if session_id:
         ctrl.session.delete(session_id)
     self.clear_cookie(cookie_name)
コード例 #27
0
ファイル: emailer.py プロジェクト: kianby/srmail
def mail(m):

    from_email = config.get(config.SMTP_LOGIN)
    if "from" in m:
        from_email = m["from"]

    # Create the container (outer) email message.
    msg = MIMEText(m["content"])
    msg["Subject"] = m["subject"]
    msg["To"] = m["to"]
    msg["From"] = from_email

    s = smtplib.SMTP(config.get(config.SMTP_HOST), config.getInt(config.SMTP_PORT))
    if config.getBool(config.SMTP_STARTTLS):
        s.starttls()
    s.login(config.get(config.SMTP_LOGIN), config.get(config.SMTP_PASSWORD))
    s.send_message(msg)
    s.quit()
コード例 #28
0
	def load_configuration(self):
		config_dir = config.get('Service Broker', 'config_dir')
		config_file = os.path.join(config_dir, '{service_name}_service_broker.conf'.format(service_name=self.service_name))

		self.config = ConfigParser.RawConfigParser()
		if os.path.isfile(config_file):
			self.config.read(config_file)
		else:
			raise Exception("Settings file missing from {location}".format(location=config_file))
コード例 #29
0
ファイル: mailer.py プロジェクト: kianby/mail2diaspora
def send(to_email, subject, message):
    headers = {"Content-Type": "application/json; charset=utf-8"}
    msg = {"to": to_email, "subject": subject, "content": message}
    r = requests.post(
        config.get(config.MAILER_URL) + "/mbox", data=json.dumps(msg), headers=headers
    )
    if r.status_code in (200, 201):
        logger.debug("Email for %s posted" % to_email)
    else:
        logger.warn("Cannot post email for %s" % to_email)
コード例 #30
0
    def __init__(self, bot):
        BaseCog.__init__(self, bot)
        self.main_db = bot.database.table('main_db')
        self.give_table = bot.database.table('give_table')

        bot.info_text += 'Registered users may reward others by giving away a fictional currency called ' + config.currency_name + 's.' + linesep + 'Type !add to initialize your account.' + linesep + linesep
        bot.info_text += 'Free ' + config.currency_name + 's:' + linesep + '  There is a free amount of points you may give away each day without draining your personal balance.' + linesep + '  Free points are reset every day and do not stack. If the amount you wish to transfer exceeds your remaining free points, your personal balance is used as supplement. Additionally, you can use !loan to take out a loan in free points (repaid automatically the next day)' + linesep + '  Free points cannot be used for gambling.' + linesep + linesep

        self.max_points_to_give_per_day = int(
            config.get('Economy', 'max_points_to_give_per_day', fallback='30'))
        self.initial_balance = int(
            config.get('Economy', 'initial_balance', fallback='15'))
        self.free_points_per_day = int(
            config.get('Economy', 'free_points_per_day', fallback='15'))
        self.max_loan = int(config.get('Economy', 'max_loan', fallback='14'))

        timed_events_cog = BaseCog.load_dependency(self, 'TimedEvents')
        timed_events_cog.register_timed_event(self.refill_free_points)
        timed_events_cog.register_timed_event(self.pay_back_loans)
コード例 #31
0
ファイル: mailer.py プロジェクト: bigbeer/stacosys
def send(to_email, subject, message):

    # Create the container (outer) email message.
    msg = MIMEText(message)
    msg["Subject"] = subject
    msg["To"] = to_email
    msg["From"] = config.get(config.SMTP_LOGIN)

    success = True
    try:
        s = smtplib.SMTP(config.get(config.SMTP_HOST), config.get_int(config.SMTP_PORT))
        if config.get_bool(config.SMTP_STARTTLS):
            s.starttls()
        s.login(config.get(config.SMTP_LOGIN), config.get(config.SMTP_PASSWORD))
        s.send_message(msg)
        s.quit()
    except:
        logger.exception("send mail exception")
        success = False
    return success
コード例 #32
0
ファイル: gambling.py プロジェクト: Lustidrike/Economy-Bot
    async def lock(self, context):
        """[ADMINS ONLY] Locks high-stake gambling."""

        BaseCog.check_main_server(self, context)
        BaseCog.check_bot_channel(self, context)
        BaseCog.check_admin(self, context)
        BaseCog.check_forbidden_characters(self, context)

        economy = BaseCog.load_dependency(self, 'Economy')

        self.lock = True
        economy.max_points_to_give_per_day = int(config.get('Economy', 'max_points_to_give_per_day', fallback=30))
        await self.bot.post_message(self.bot.bot_channel, '**[INFO]** High-stakes gambling is now locked.')
コード例 #33
0
def mail_error(ex):
    msg = MIMEText(ex)
    msg["Subject"] = "POP FORWARD EXCEPTION"
    msg["To"] = config.get(config.SMTP_TO)
    msg["From"] = config.get(config.SMTP_LOGIN)

    s = smtplib.SMTP(config.get(config.SMTP_HOST),
                     config.getInt(config.SMTP_PORT))
    if config.getBool(config.SMTP_STARTTLS):
        s.starttls()
    s.login(config.get(config.SMTP_LOGIN), config.get(config.SMTP_PASSWORD))
    s.sendmail(config.get(config.SMTP_LOGIN), config.get(config.SMTP_TO), msg)
    s.quit()
コード例 #34
0
ファイル: run.py プロジェクト: kianby/srmail
def srmail_server(config_pathname):

    app = Flask(__name__)
    config.initialize(config_pathname, app)

    # configure logging
    logger = logging.getLogger(__name__)
    configure_logging(logging.INFO)

    # initialize database
    from core import database

    database.setup()

    # cron email fetcher
    app.config.from_object(JobConfig(config.getInt(config.IMAP_POLLING)))
    scheduler = APScheduler()
    scheduler.init_app(app)
    scheduler.start()

    logger.info("Starting SRMAIL application")

    # start Flask
    from interface import api

    logger.debug("Load interface %s" % api)

    app.run(
        host=config.get(config.HTTP_HOST),
        port=config.get(config.HTTP_PORT),
        debug=False,
        use_reloader=False,
    )

    # Exit application
    logger.info("Stopping SRMAIL application")
コード例 #35
0
ファイル: cron.py プロジェクト: kianby/alerte-enlevement
def findReferenceArticles():
    data = requests.get(config.get(config.SITE_URL))
    html = BeautifulSoup(data.text, "html.parser")
    metas = html.head.select("meta")
    numero_rubrique = None
    numero_articles = []
    for meta in metas:
        if not meta.get("name"):
            continue
        if meta["name"] == "rubrique":
            numero_rubrique = meta["content"]
        elif meta["name"] == "article":
            numero_articles = meta["content"]
    if numero_rubrique and numero_articles:
        numero_articles = numero_articles.split(",")
    # saute le dernier article qui est une presentation de l'objet du site de 2016
    return numero_rubrique, numero_articles[:-1]
コード例 #36
0
	def load_catalog(self):
		config_dir = config.get('Service Broker', 'config_dir')
		catalog_file = os.path.join(config_dir, '{service_name}_catalog.yml'.format(service_name=self.service_name))

		if not os.path.isfile(catalog_file):
			raise exceptions.ServiceBrokerConfiguration("Missing catalog file {file}".format(file=catalog_file))		

		stream = open(catalog_file, 'r')

		try:
			service_data = yaml.load(stream)
		except yaml.scanner.ScannerError as e:
			raise exceptions.ServiceBrokerConfiguration("Error parsing catalog file {}: {}".format(catalog_file, e))
		finally:
			stream.close()

		service_required_fields = ['id', 'name', 'description', 'bindable', 'plans']
		plan_required_fields = ['id', 'name', 'description']

		for index, service_object in enumerate(service_data["services"]):
			for _, field in enumerate(service_required_fields):
				try:
					service_object[field]
				except KeyError as e:
					raise exceptions.ServiceBrokerConfiguration("Missing catalog setting \"{}[{}][{}]\"".format("services", index, field))
			try:
				if type(service_object["plans"]) is not list or not len(service_object["plans"]) > 0:
					raise exceptions.ServiceBrokerConfiguration("There are no catalog plans defined \"{}[{}][{}]\"".format("services", index, "plans"))
			except KeyError as e:
				raise exceptions.ServiceBrokerConfiguration("Missing catalog setting \"{}[{}][{}]\"".format("services", index, "plans"))			

			for plan_index, plan_object in enumerate(service_object["plans"]):
				for _, plan_field in enumerate(plan_required_fields):
					try:
						plan_object[plan_field]
					except KeyError as e:
						raise exceptions.ServiceBrokerConfiguration("Missing catalog setting \"{}[{}][{}][{}][{}]\"".format("services", index, "plans", plan_index, plan_field))

		self.service_catalog = service_data
コード例 #37
0
    def __init__(self, bot):
        BaseCog.__init__(self, bot)
        self.trivia_table = bot.database.table('trivia_table')
        self.seasons_path = config.get('Private',
                                       'seasons_path',
                                       fallback='seasons')

        # Past seasons, if available
        self.season_tables = []

        try:
            if len(self.trivia_table) < 1:
                self.reset_trivia()
        except Exception as e:
            print('Stats::__init__: Error while resetting trivia table!')
            log.exception(e)

        for filename in sorted(listdir(self.seasons_path)):
            if filename.endswith('.json'):
                season_db = TinyDB(self.seasons_path + '/' + filename)
                self.season_tables.append((season_db.table('main_db'),
                                           season_db.table('trivia_table')))

        log.info('Loaded ' + str(len(self.season_tables)) + ' season tables')
コード例 #38
0
ファイル: templater.py プロジェクト: bigbeer/stacosys
def get_template(name):
    return env.get_template(config.get(config.LANG) + '/' + name + '.tpl')
コード例 #39
0
ファイル: run.py プロジェクト: webdrivenz/cf-service-broker
	config_dir = os.path.join(os.getcwd(), args.configuration)
	if not os.path.isdir(config_dir):
		raise Exception('Configuration directory not found in the following locations:\n     {}\n    {}'.format(args.configuration, setting_file))
else:
	config_dir = args.configuration

config_file = os.path.join(config_dir, "settings.conf")

if not os.path.isfile(config_file):
	raise Exception('Configuration file not found in the following locations:\n	{}\n	{}'.format(args.configuration, setting_file))
else:
	config.read(config_file)

config.set('Service Broker', 'config_dir', config_dir)

debug = config.get('Service Broker', 'debug')
debug = debug == "True" or debug == "true"

from cf_service_broker import api as cfsb_api

app = cfsb_api.create()

if __name__ == '__main__':
        pidfile = open(config.get('Service Broker','pidfile'), 'w')
        pidfile.write(str(os.getpid()))
        pidfile.close()

	if debug:
		print "Running in debug mode"
	app.run('0.0.0.0', debug=debug)
コード例 #40
0
	def __init__(self):
		super(FilesystemServiceBroker,self).__init__()
		self._database_connection_str = config.get('Service Broker', 'database_connection_str')
		self.db_connect()
		self.db_create()
コード例 #41
0
ファイル: wsgi.py プロジェクト: ShafiurShamim/django-project
"""
WSGI config for project project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application
from conf import config

os.environ.setdefault('DJANGO_SETTINGS_MODULE',
                      str(config.get('project_settings', 'project.settings')))

application = get_wsgi_application()
コード例 #42
0
def downloadRecursive(ruta):
    """
    Download files recursive
    """
    global numErrors, numFolders, numFiles
    global log
    # Nos movemos a la ruta en el servidor
    ftp.cwd(ruta)
    print 'Actual route:', ruta
    initialList = []
    ftp.dir(initialList.append)
    # print "Lista inicial:", initialList
    '''
    con dir() obtenemos un string que lista todos los elementos contenido en la ruta
    la estructura obtenida en mi caso fue
     
        drwxr-xr-x    2 362309906  usuario1       4096 Nov  2 15:09 .
        drwxr-x--x    4 362309906  usuario1       4096 Jun  9 08:26 ..
        -rw-r--r--    1 362309906  usuario1        563 Nov  1 17:10 index.html
         
    donde las carpetas comienzan con d y el nombre del archivo/carpeta se ubica al fin
    el string anterior se trata de la siguiente manera:
        -se divide el string en una lista de strings donde cada posicion representa una linea
        -cada posicion de la lista se subdivide tomando como referencia los espacios formando un 
        array bidimensional donde tenemos la informacion separada y podemos consultarla con mas facilidad
    En este caso el array bidimensional tiene en las posiciones:
        -nx0: la informacion relativa a si es un directorio (d) o un archivo (-) y sus pemisos
        -nx8: el nombre de fichero
    '''
    listaIntermedia = []
    for elemento in initialList:
        listaIntermedia.append(str(elemento).split())

    # print "Lista intermedia:", listaIntermedia
    '''
    Tras obtener en listaIntermedia el array bidimensional, generamos dos listas:
        -Una lista de pos[8] (nombres de ficheros) que cumplen que pos[0] no comienza con d
        -Una lista de pos[8] (carpetas) que cumplen que pos[0] comienza con d
    '''
    listFiles = []
    listFolders = []
    for elemento in listaIntermedia:
        name = b""
        for a in elemento[8:]:
            name += a + " "
        name = name.strip()
        if elemento[0].startswith('d'):
            # print "Folder: ", name
            listFolders.append(name)
        else:
            # print "File:", name.decode('utf-8')
            listFiles.append(name)

    # Fill num files and folders
    numFiles += len(listFiles)
    numFolders += len(listFolders)
    '''
    Eliminamos de la lista de carpetas . y .. para evitar bucles por el servidor
    '''
    try:
        listFolders.remove('.')
        listFolders.remove('..')
    except:
        pass
    '''
    Listamos los elementos a trabajar de la ruta actual
    '''
    # print('\tLista de Archivos: ' + str(listFiles))
    # print('\tLista de Carpetas: ' + str(listFolders))
    '''
    Si la ruta actual no tiene su equivalente local, creamos la carpeta a nivel local
    '''
    if not os.path.exists(config.get("dest") + ruta):
        os.makedirs(config.get("dest") + ruta)
    '''
    Los elementos de la lista de archivo se proceden a descargar de forma secuencial en la ruta
    '''
    for elemento in listFiles:
        print('\tDescargando ' + elemento + ' en ' + config.get("dest") + ruta)
        try:
            ftp.retrbinary(
                "RETR " + elemento,
                open(
                    os.path.join(
                        config.get("dest") + ruta, elemento.decode('utf-8')),
                    "wb").write)
            # listFiles.remove(elemento)
        except:
            ex = 'Error al descargar ' + elemento + \
                ' ubicado en ' + config.get("dest") + ruta
            print ex
            listErrors.append('Archivo ' + elemento + ' ubicado en ' +
                              config.get("dest") + ruta)
            numErrors += 1
    '''
    Una vez se termina de descargar los archivos invocamos el metodo actual provocando una solucion
    recursiva, para ello concatenamos la ruta actual con el nombre de la carpeta, realizando tantas
    llamadas al metodo actual como elementos tengamos listados en listFolders
    '''
    for elemento in listFolders:
        # elemento = elemento[2:len(elemento) - 2]
        downloadRecursive(ruta + elemento + "\\")

    return
コード例 #43
0
ファイル: mailer.py プロジェクト: kianby/mail2diaspora
def delete(id):
    requests.delete(config.get(config.MAILER_URL) + "/mbox/" + str(id))
コード例 #44
0
ファイル: mailer.py プロジェクト: kianby/mail2diaspora
def get(id):
    payload = None
    r = requests.get(config.get(config.MAILER_URL) + "/mbox/" + str(id))
    if r.status_code == 200:
        payload = r.json()
    return payload
コード例 #45
0
ファイル: database.py プロジェクト: bigbeer/stacosys
def get_db():
    return connect(config.get(config.DB_URL))
コード例 #46
0
def connect():
    ftp.connect(config.get("host"), config.get("port"))
    ftp.login(config.get("user"), config.get("pass"))
    print('Connected to server')
    print(str(ftp.welcome))
    return
コード例 #47
0
ファイル: templater.py プロジェクト: kianby/stacosys
def get_template(name):
    return env.get_template(config.get(config.LANG) + "/" + name + ".tpl")
コード例 #48
0
ファイル: database.py プロジェクト: kianby/srmail
def get_db():
    return connect(config.get(config.DB_URL))
コード例 #49
0
ファイル: app.py プロジェクト: justiniso/justiniso.com
#!/usr/bin/env python
from conf import config
from flask import Flask
from flask.ext.assets import Environment, Bundle
import home

blueprints = (home.bp,)

app = Flask(__name__)
[app.register_blueprint(bp) for bp in blueprints]

assets = Environment(app)
assets.register('js', Bundle(
    'js/vendor/jquery-1.7.1.js',
    'js/vendor/jquery.proximity.js',
    'js/animations.js',
    'js/canvas.js',
    'js/frost.js',
    output='gen/common.js'))

assets.register('css', Bundle(
    'css/objects.css',
    'css/frost.css',
    output='gen/common.css'))


if __name__ == '__main__':
    app.run(
        host=config.get('app', 'address'),
        port=config.getint('app', 'port'),
        debug=config.getboolean('app', 'debug'))
コード例 #50
0
ファイル: tests.py プロジェクト: Vaishaal/blackout
 def test_config(self):
     from conf import config
     self.assert_(config.forwardingNumber)
     self.assert_(str(config.phoneType) in '1237')
     self.assertEqual(config.get('wtf'), None)
コード例 #51
0
 def test_config(self):
     from conf import config
     self.assert_(config.forwardingNumber)
     self.assert_(str(config.phoneType) in '1237')
     self.assertEqual(config.get('wtf'), None)
コード例 #52
0
ファイル: base.py プロジェクト: batulu12/notebook
 def send_json(self, result, code):
     err_desc = eval(config.get('DESC', 'err_desc'))
     code_desc = eval(config.get('DESC', 'code_desc'))
     r = {"status": {"code": code_desc[code], "msg": err_desc[code]}, "result": result}
     self.jsondump(r)
コード例 #53
0
 def __init__(self, key):
     resource.Resource.__init__(self)
     self.key = key
     self.value = config.get(key, None)
     self.putChild('', self)
     self.putChild('config', ConfigConfig(self.key))
コード例 #54
0
ファイル: hashing.py プロジェクト: kianby/stacosys
def salt(value):
    string = "%s%s" % (value, config.get(config.SECURITY_SALT))
    dk = hashlib.sha256(string.encode())
    return dk.hexdigest()
コード例 #55
0
For more information on this file, see
https://docs.djangoproject.com/en/2.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.1/ref/settings/
"""

import os
import json
from conf import config

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

PROJECT_PACKAGE = str(
    os.path.join(BASE_DIR, config.get('project_name', 'project')))

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = str(config.get('secret_key', 'your-secret-key'))

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

# ALLOWED_HOSTS = ['127.0.0.1', 'django-project.test']
ALLOWED_HOSTS = []

# Application definition

INSTALLED_APPS = [
    'accounts.apps.AccountsConfig',
    'blog.apps.BlogConfig',
コード例 #56
0
		def decorator(*args, **kwargs):
			api_username = config.get('Service Broker', 'api_username')
			api_password_hash = config.get('Service Broker', 'api_password_hash')

			auth = request.authorization

			if not auth or api_username != auth.username or not sha256_crypt.verify(auth.password, api_password_hash):
				return Response(
				'Could not verify your access level for that URL.\n'
				'You have to login with proper credentials', 401,
				{'WWW-Authenticate': 'Basic realm="Login Required"'})

			try:
				request.headers['X-Broker-Api-Version']
			except (KeyError, NameError) as e:
				return "Request header not set: X-Broker-Api-Version", 400

			try:
				api_version = request.headers['X-Broker-Api-Version']
				api_version_split = map(int, api_version.split("."))
				if len(api_version_split) != 2:
					raise ValueError("API version format error")
			except ValueError as e:
				return "Invalid request header value \"%s\" for X-Broker-Api-Version" % api_version, 500

			api_version_min = config.get('Service Broker', 'api_version_min')
			api_version_max = config.get('Service Broker', 'api_version_max')

			try:
				api_version_min
				if api_version_min == "None":
					pass
				else:
					try:
						api_version_min = str( api_version_min )
						api_version_min_split = map(int, api_version_min.split("."))
						if len(api_version_min_split) != 2:
							raise ValueError("API version min format error")
					except ValueError as e:
						return "Invalid api_version_min \"%s\"" % api_version_min, 500
					else:
						if ( api_version_split[0] < api_version_min_split[0] ) or \
						   ( api_version_split[0] == api_version_min_split[0] and api_version_split[1] < api_version_min_split[1] ):
							return "Broker API Version request %s is less than the %s minimum" % ( api_version, api_version_min), 500
			except:
				pass

			try:
				api_version_max
				if api_version_max == "None":
					pass
				else:
					try:
						api_version_max = str( api_version_max )
						api_version_max_split = map(int, api_version_max.split("."))
						if len(api_version_max_split) != 2:
							raise ValueError("API version max format error")
					except ValueError as e:
						return "Invalid api_version_max \"%s\"" % api_version_max, 500
					else:
						if ( api_version_split[0] > api_version_max_split[0] ) or \
						   ( api_version_split[0] == api_version_max_split[0] and api_version_split[1] > api_version_max_split[1] ):
							return "Broker API Version request %s is greater than the %s maximum" % ( api_version, api_version_max), 500
			except:
				pass

			ret = func(*args, **kwargs)
			return ret
コード例 #57
0
    for elemento in listFolders:
        # elemento = elemento[2:len(elemento) - 2]
        downloadRecursive(ruta + elemento + "\\")

    return


def prepareLog():
    global numErrors, log, listErrors
    print 'Errors detected = ', str(numErrors)
    log.write('Errors detected = ' + str(numErrors))
    for el in listErrors:
        log.write(str(el))


# Main
print 'Run backup FTP', config.get("host")
connect()
downloadRecursive(config.get("route"))
prepareLog()

# Create commit & push
msgcommit = ", ".join([
    str(int(time.time())),
    str(numErrors) + " Errors",
    str(numFiles) + " Files",
    str(numFolders) + " Folders"
])
print "[GIT]\tPrepare commit", msgcommit
git.commit(config.get("folderdest"), msgcommit)
コード例 #58
0
from googlevoice import Voice, utilfrom os import path, removefrom unittest import TestCase, main
class VoiceTest(TestCase):    voice = Voice()    voice.login()    outgoing = util.input('Outgoing number (blank to ignore call tests): ')    forwarding = None if outgoing:        forwarding = util.input('Forwarding number [optional]: ') or None  if outgoing: def test_1call(self): self.voice.call(self.outgoing, self.forwarding)
 def test_sms(self): self.voice.send_sms(self.outgoing, 'i sms u')
 def test_2cancel(self): self.voice.cancel(self.outgoing, self.forwarding)  def test_special(self): self.assert_(self.voice.special)  def test_inbox(self): self.assert_(self.voice.inbox)  def test_balance(self): self.assert_(self.voice.settings['credits'])  def test_search(self): self.assert_(len(self.voice.search('joe')))  def test_disable_enable(self): self.voice.phones[0].disable() self.voice.phones[0].enable()  def test_download(self):        msg = list(self.voice.voicemail.messages)[0]        fn = '%s.mp3' % msg.id if path.isfile(fn): remove(fn) self.voice.download(msg) self.assert_(path.isfile(fn))  def test_zlogout(self): self.voice.logout() self.assert_(self.voice.special is None)  def test_config(self): from conf import config self.assert_(config.forwardingNumber) self.assert_(str(config.phoneType) in '1237') self.assertEqual(config.get('wtf'), None) if __name__ == '__main__': main()