<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""pyfibot BETA module_rss.py
@author Henri 'fgeek' Salo <<EMAIL>>, Tomi 'dmc' Nykänen
@copyright Copyright (c) 2010 <NAME>
@licence BSD
"""

try:
    import feedparser
    import os
    import sqlite3
    import logging
    import logging.handlers
    import sys
    import hashlib
    from twisted.internet import reactor
    from threading import Thread
    import re
    import yaml
    import urllib
except ImportError, error:
    print error
    sys.exit(2)

# Initialize logger
log = logging.getLogger('rss')

t = None
t2 = None

# Read configuration
configfile = os.path.join(sys.path[0], 'modules', 'module_rss.conf')
rssconfig = yaml.load(file(configfile))
# Config format:
# database: rss.db
# delays:
#   rss_sync: 300 #How often we synchronize rss-feeds (in seconds)
#   output: 7 #How often to output new elements to channels
# output_syntax: 0 #0 == feed_title: title - url, 1 == feed_title: title - shorturl, 2 == feed_title: title (id)

# With output_syntax #2 you could get url via .url <id>

def event_signedon(bot):
    """Starts rotators"""
    global delay
    global output_dealy
    rotator_indexfeeds(bot, rssconfig["delays"]["rss_sync"])
    rotator_output(bot, rssconfig["delays"]["output"])

def init(botconfig):
    """Creates database if it doesn't exist"""<commit_msg>Don't include core libs in try/except block Smarter handling for required libraries<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""pyfibot BETA module_rss.py
@author Henri 'fgeek' Salo <<EMAIL>>, Tomi 'dmc' Nykänen
@copyright Copyright (c) 2010 <NAME>
@licence BSD
"""

import sys
import os
import re
import urllib
import logging
import logging.handlers
import hashlib
from threading import Thread

try:
    import feedparser
    import sqlite3
    from twisted.internet import reactor
    import yaml
    init_ok = True
except ImportError, error:
    print 'Error starting rss module: ',error
    init_ok = False

# Initialize logger
log = logging.getLogger('rss')

t = None
t2 = None

# Config format:
# database: rss.db
# delays:
#   rss_sync: 300 #How often we synchronize rss-feeds (in seconds)
#   output: 7 #How often to output new elements to channels
# output_syntax: 0 #0 == feed_title: title - url, 1 == feed_title: title - shorturl, 2 == feed_title: title (id)

# With output_syntax #2 you could get url via .url <id>

def event_signedon(bot):
    """Starts rotators"""
    if not init_ok: 
        log.error("Config not ok, not starting rotators")
        return False

    global delay
    global output_dealy

    rotator_indexfeeds(bot, rssconfig["delays"]["rss_sync"])
    rotator_output(bot, rssconfig["delays"]["output"])

def init(botconfig):
    """Creates database if it doesn't exist"""
    if not init_ok: 
        log.error("Config not ok, skipping init")
        return False

    global rssconfig
    # Read configuration
    configfile = os.path.join(sys.path[0], 'modules', 'module_rss.conf')
    rssconfig = yaml.load(file(configfile))

{'fraction_non_alphanumeric': 0.1107459743674006, 'fraction_numerical': 0.011501807426881366, 'mean_word_length': 3.7786499215070646, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5286061', 'n_tokens_mistral': 1021, 'n_tokens_neox': 973, 'n_words': 322}