Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,12 @@ python2 feedupdater.py
```

To start the bot, run:

```
python2 main.py
```
or
```
python2 main.py 2>&1 > newsbot.log &
```

If you want to run this as a systemd service, you can use the `rss2irc.service` file after adjusting the paths in there.
Expand Down
21 changes: 15 additions & 6 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import irc.bot
import irc.client
import irc.connection
import tinyurl
import time
import re
import sys
import feedparser
import datetime
import dateutil.parser
import requests
from colour import Colours
from db import FeedDB
from config import Config
Expand Down Expand Up @@ -67,7 +67,7 @@ def on_join(self, connection, event):
self.__first_start = True

def welcome_msg(self):
msg = u"Hi, I'm the channel's " + self.get_bolded_text(self.__get_colored_text(self.color_feedname,"RSS")) + u" news publishing bot v2.0. Send " + self.__get_colored_text(self.color_num,"!help") + u" to receive a list of commands in private message (PM). If you find me annoying, you can to use " + self.__get_colored_text(self.color_num,"/IGNORE " + self.connection.get_nickname()) + u" to stop reading me."
msg = u"Hi, I'm the channel " + self.get_bolded_text(self.__get_colored_text(self.color_feedname,"RSS")) + u" news publishing bot v2.1. Send " + self.__get_colored_text(self.color_num,"!help") + u" to receive a command list in private message (PM). If you find me annoying, you can to use " + self.__get_colored_text(self.color_num,"/IGNORE " + self.connection.get_nickname()) + u" to stop reading me."
time.sleep(1)
return msg

Expand Down Expand Up @@ -187,7 +187,7 @@ def post_news(self, feed_name, title, url, date):
"""Try shortening url"""
if self.__config.shorturls:
try:
post_url = tinyurl.create_one(url)
post_url = self.shorten(url)
if ("error" in post_url.lower()):
post_url = url
except Exception as e:
Expand All @@ -204,6 +204,15 @@ def post_news(self, feed_name, title, url, date):
print datetime.datetime.now(), e
sys.stdout.flush()

def shorten(self, url):
try: # Trying to shorten URL
sresponse = requests.get('https://v.gd/create.php?format=json&url=' + url)
surl = sresponse.json()['shorturl']
except Exception as err:
print('A shortening error occurred.')
surl = url
return surl

def __get_colored_text(self, color, text):
if not self.__config.use_colors:
return text
Expand Down Expand Up @@ -241,9 +250,9 @@ def __init__(self):
self.__connected = False

def __check_config(self):
necessary_options = ["HOST", "PORT", "PASSWORD", "SSL", "CHANNEL", "NICK", "admin_nicks", "use_colors",
"num_col", "date", "feedname", "shorturls", "dateformat", "feedlimit", "update_before_connecting",
"url", "feedorderdesc"]
necessary_options = ["HOST", "PORT", "PASSWORD", "SSL", "CHANNEL",
"use_colors", "num_col", "feedname", "newstitle", "url", "date", "shorturls", "dateformat", "feedlimit",
"postdelay", "feedorderdesc", "update_before_connecting", "filterkeywords"]
missing_options = []
for key in necessary_options:
if not hasattr(self.__config, key):
Expand Down
18 changes: 9 additions & 9 deletions config.py.sample
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@ class Config(object):
lastpubmsg = 0

def __init__(self):
self.HOST = "irc.rizon.net"
self.HOST = 'irc.rizon.net'
self.PORT = 9999
self.PASSWORD = None
self.SSL = True
self.NICK = "rss2irc"
self.NICKPASS = ""
self.CHANNEL = "#tests"
self.admin_nicks= ['']
self.NICK = 'rss2irc'
self.NICKPASS = ''
self.CHANNEL = '#tests'

"""
'''
00 - white 01 - black 02 - blue (navy) 03 - green
04 - red 05 - brown 06 - purple 07 - orange
08 - yellow 09 - light green 10 - teal 11 - cyan
12 - light blue 13 - pink 14 - grey 15 - light grey
"""
'''

self.use_colors = True
self.num_col = 'red' # Empty for dafault color
Expand All @@ -33,5 +32,6 @@ class Config(object):
self.postdelay = 180 # Post delay during conversation in seconds. 0 for off.
self.feedorderdesc = False
self.update_before_connecting = True # Update all feeds before connecting to the IRC server
self.filterkeywords = {} # Lower-case keywords list to filter in title news. Use
# {"one","two","three"} to activate or {} for deactivate.
self.filterkeywords = () # Lower-case keywords list to filter in title news. Use
# ('one','two','three') to activate or () for deactivate.

2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ pytz==2016.4
six==1.10.0
git+https://github.com/palantir/sqlite3worker#egg=sqlite3worker
tempora==1.4
TinyUrl==0.1.0
requests==2.25.1