<commit_before># -*- coding: utf-8 -*-
# vim:ts=4:sw=4:noexpandtab
# c-basic-indent: 4; tab-width: 4; indent-tabs-mode: true;
from __future__ import absolute_import, print_function

import socket
import re
import datetime
import logging

import feedparser

import pmxbot
from . import core
from . import storage
from . import timing

log = logging.getLogger(__name__)

class RSSFeeds(object):
	"""
	Plugin for feedparser support.
	"""

	def __init__(self):
		self.feed_interval = pmxbot.config.feed_interval
		self.feeds = pmxbot.config.feeds
		self.store = FeedparserDB.from_URI(pmxbot.config.database)
		for feed in self.feeds:
			core.execdelay(
				name = 'feedparser',
				channel = feed['channel'],
				howlong = datetime.timedelta(minutes=self.feed_interval),
				args = [feed],
				repeat = True,
				)(self.parse_feed)
		timer = timing.Stopwatch()
		self.seen_feeds = set(self.store.get_seen_feeds())
		log.info("Loaded feed history in %s", timer.split())
		storage.SelectableStorage._finalizers.append(self.finalize)

	def finalize(self):
		del self.store

	def on_welcome(self, c, e):
		if self._feeds:
			# Feeds configured, check them periodically
			c.execute_delayed(30, self.feed_parse,
				arguments=(c, e, self._feed_interval, self._feeds))

	def parse_feed(self, client, event, feed):
		"""
		Parse RSS feeds and spit out new articles at
		regular intervals in the relevant channels.
		"""
		socket.setdefaulttimeout(20)
		outputs = []
		try:
			resp = feedparser.parse(feed['url'])
		except:<commit_msg>Remove on_welcome (legacy code no longer used)<commit_after># -*- coding: utf-8 -*-
# vim:ts=4:sw=4:noexpandtab
# c-basic-indent: 4; tab-width: 4; indent-tabs-mode: true;
from __future__ import absolute_import, print_function

import socket
import re
import datetime
import logging

import feedparser

import pmxbot
from . import core
from . import storage
from . import timing

log = logging.getLogger(__name__)

class RSSFeeds(object):
	"""
	Plugin for feedparser support.
	"""

	def __init__(self):
		self.feed_interval = pmxbot.config.feed_interval
		self.feeds = pmxbot.config.feeds
		self.store = FeedparserDB.from_URI(pmxbot.config.database)
		for feed in self.feeds:
			core.execdelay(
				name = 'feedparser',
				channel = feed['channel'],
				howlong = datetime.timedelta(minutes=self.feed_interval),
				args = [feed],
				repeat = True,
				)(self.parse_feed)
		timer = timing.Stopwatch()
		self.seen_feeds = set(self.store.get_seen_feeds())
		log.info("Loaded feed history in %s", timer.split())
		storage.SelectableStorage._finalizers.append(self.finalize)

	def finalize(self):
		del self.store

	def parse_feed(self, client, event, feed):
		"""
		Parse RSS feeds and spit out new articles at
		regular intervals in the relevant channels.
		"""
		socket.setdefaulttimeout(20)
		outputs = []
		try:
			resp = feedparser.parse(feed['url'])
		except:
{'fraction_non_alphanumeric': 0.11815661815661815, 'fraction_numerical': 0.005544005544005544, 'mean_word_length': 4.2111913357400725, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '174295', 'n_tokens_mistral': 1064, 'n_tokens_neox': 949, 'n_words': 240}