summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@nomic.retiolum>2014-03-17 00:58:48 +0100
committertv <tv@nomic.retiolum>2014-03-17 00:58:48 +0100
commitdba1f1d1be5d4e0a91b0b575d35e04e4722e21df (patch)
treee2ae6786e2b937e5ac6836f7f7e20bf2796c7780
parente13c7bcd25311ce7b446074343bf733322edc992 (diff)
parent0e6a8d12f55f5e8c1c5afb8f91ebcb5564590830 (diff)
Merge branch 'master' of lassulus:painload
-rw-r--r--news/new_feeds12
-rw-r--r--news/newsbot.js104
-rw-r--r--news/newsbot.py14
3 files changed, 103 insertions, 27 deletions
diff --git a/news/new_feeds b/news/new_feeds
index f6025f7e..61e6330e 100644
--- a/news/new_feeds
+++ b/news/new_feeds
@@ -18,7 +18,6 @@ bdt_pressemitteilungen|http://bundestag.de/service/rss/Bundestag_Presse.rss|#new
bdt_wd|http://bundestag.de/service/rss/Bundestag_WD.rss|#news #bundestag
bitcoinboard|http://bitcoinboard.net/feed/|#news #financial
bitcoinpakistan|https://bitcoinspakistan.com/feed/|#news #financial
-bmj|http://www.bmj.com/rss|#news
businessweek|http://www.businessweek.com/feeds/homepage.rss|#news
cancer|http://feeds.feedburner.com/ncinewsreleases?format=xml|#news
carta|http://feeds2.feedburner.com/carta-standard-rss|#news
@@ -44,7 +43,6 @@ csm|http://rss.csmonitor.com/feeds/csm|#news
csm_world|http://rss.csmonitor.com/feeds/world|#news
cyberguerrilla|https://www.cyberguerrilla.org/a/2012/?feed=rss2|#news
danisch|http://www.danisch.de/blog/feed/|#news
-dod|http://www.defense.gov/news/rss/|#news
dwn|http://deutsche-wirtschafts-nachrichten.de/feed/customfeed/|#news
ecat|http://ecat.com/feed|#news
eia_press|http://www.eia.gov/rss/press_rss.xml|#news
@@ -60,7 +58,6 @@ faz_feui|http://www.faz.net/rss/aktuell/feuilleton/|#news
faz_politik|http://www.faz.net/rss/aktuell/politik/|#news
faz_wirtschaft|http://www.faz.net/rss/aktuell/wirtschaft/|#news #financial
fbi|http://www.fbi.gov/homepage/RSS|#news #bullerei
-fbi_nat_press|http://www.fbi.gov/news/rss|#news #bullerei
fbi_news|http://www.fbi.gov/news/news_blog/rss.xml|#news
fbi_press|http://www.fbi.gov/news/current/rss.xml|#news #bullerei
fbi_stories|http://www.fbi.gov/news/stories/all-stories/rss.xml|#news #bullerei
@@ -75,7 +72,6 @@ GerForPol|http://www.german-foreign-policy.com/de/news/rss-2.0|#news
gmanet|http://www.gmanetwork.com/news/rss/news|#news
golem|http://www.golem.de/rss.php?feed=RSS1.0|#news
google|http://news.google.com/?output=rss|#news
-greenpeace|http://www.greenpeace.de/nachrichten/feed/rss2/|#news
guardian_uk|http://feeds.theguardian.com/theguardian/uk-news/rss|#news
gulli|http://ticker.gulli.com/rss/|#news
handelsblatt|http://www.handelsblatt.com/contentexport/feed/schlagzeilen|#news #financial
@@ -98,8 +94,6 @@ LtU|http://lambda-the-ultimate.org/rss.xml|#news
lukepalmer|http://lukepalmer.wordpress.com/feed/|#news
mit|http://web.mit.edu/newsoffice/rss-feeds.feed?type=rss|#news
mongrel2_master|https://github.com/zedshaw/mongrel2/commits/master.atom|#news
-nasa_iotd|http://www.nasa-usa.de/rss/dyn/lg_image_of_the_day.rss|#news
-nasa_news|http://www.nasa-usa.de/rss/dyn/breaking_news.rss|#news
nds|http://www.nachdenkseiten.de/?feed=atom|#news
netzpolitik|https://netzpolitik.org/feed/|#news
newsbtc|http://newsbtc.com/feed/|#news #financial
@@ -122,7 +116,6 @@ reddit_4chan|http://www.reddit.com/r/4chan/new/.rss|#news #brainfuck
reddit_anticonsum|http://www.reddit.com/r/Anticonsumption/new/.rss|#news
reddit_btc|http://www.reddit.com/r/Bitcoin/new/.rss|#news #financial
reddit_consp|http://reddit.com/r/conspiracy/.rss|#news
-reddit_prog|http://reddit.com/r/programming/|#news
reddit_sci|http://www.reddit.com/r/science/.rss|#news
reddit_tech|http://www.reddit.com/r/technology/.rss|#news
reddit_tpp|http://www.reddit.com/r/twitchplayspokemon/.rss|#news #tpp
@@ -182,5 +175,8 @@ weechat|http://dev.weechat.org/feed/atom|#news
wp_world|http://feeds.washingtonpost.com/rss/rss_blogpost|#news
xkcd|https://xkcd.com/rss.xml|#news
yahoo|http://news.yahoo.com/rss/|#news
-z0r|https://www.facebook.com/feeds/page.php?format=atom10&id=278857186139|#news
zdnet|http://www.zdnet.com/news/rss.xml|#news
+reddit_prog|http://www.reddit.com/r/programming/new/.rss|#news
+bmj|[object Object]|#news
+dod|http://www.defense.gov/news/afps2.xml|#news
+greenpeace|http://feeds.feedburner.com/GreenpeaceNews|#news
diff --git a/news/newsbot.js b/news/newsbot.js
index 4171e968..683bf39a 100644
--- a/news/newsbot.js
+++ b/news/newsbot.js
@@ -1,31 +1,40 @@
var IRC = require('irc')
var FeedParser = require('feedparser')
var Request = require('request')
+var Parse = require('shell-quote').parse
+var FS = require('fs')
var irc_server = 'ire.retiolum'
var master_nick = 'knews'
-var news_channel = '&testing'
+var news_channel = '#news'
var feeds_file = 'new_feeds'
var feedbot_loop_delay = 60 * 1000 // [ms]
+var slaves = {}
+
function main () {
- // XXX mangle nick to not clash with newsbot.py
- var master = new IRC.Client(irc_server, master_nick + '_2', {
+ var master = new IRC.Client(irc_server, master_nick, {
channels: [ news_channel ],
})
master.on('message' + news_channel, function (nick, text, message) {
if (is_talking_to(master_nick, text)) {
- var parse = /^[^:]*:\s*(\S*\S)\s*$/.exec(text)
- if (parse) {
- client.say(to, nick + ': ' + parse[1] + '?')
+ var request = parse_request(text)
+ if (request) {
+ return run_command(request.method, request.params, function (error, result) {
+ if (error) {
+ return master.say(news_channel, '4' + error)
+ } else {
+ return master.say(news_channel, result)
+ }
+ })
}
}
})
master.once('registered', function () {
// read feeds file and create a feedbot for each entry
- require('fs')
+ FS
.readFileSync(feeds_file)
.toString()
.split('\n')
@@ -45,16 +54,10 @@ function main () {
return
}
- // XXX mangle nick to not clash with newsbot.py
- var nick = parts[0] + '_2'
+ var nick = parts[0]
var uri = parts[1]
var channels = parts[2].split(' ')
- // XXX mangle channel to not clash with newsbot.py
- channels = channels.map(function (channel) {
- return channel === '#news' ? news_channel : channel
- })
-
return create_feedbot(nick, uri, channels)
})
})
@@ -65,6 +68,13 @@ function create_feedbot (nick, uri, channels) {
channels: channels,
})
+ slaves[nick] = {
+ client: client,
+ nick: nick,
+ uri: uri,
+ channels: channels,
+ }
+
// say text in every joined channel
function broadcast (text) {
Object.keys(client.chans).forEach(function (channel) {
@@ -141,7 +151,9 @@ function create_feedbot (nick, uri, channels) {
// (i.e. we already have a lastTitle)
if (client.lastTitle) {
newitems.forEach(function (item) {
- broadcast(item.title + ' ' + item.link)
+ return getShortLink(item.link, function (error, shortlink) {
+ return broadcast(item.title + ' ' + shortlink)
+ })
})
}
@@ -162,6 +174,68 @@ function is_talking_to (my_nick, text) {
&& text[my_nick.length] === ':'
}
+function parse_request (text) {
+ var parse = Parse(text)
+ return {
+ method: parse[1],
+ params: parse.slice(2),
+ }
+}
+
+function run_command (methodname, params, callback) {
+ var method = methods[methodname]
+ if (method) {
+ return method(params, callback)
+ } else {
+ return callback(new Error('dunno what ' + methodname + ' is'));
+ }
+}
+
+function getShortLink (link, callback) {
+ return callback(null, link)
+}
+
+var methods = {}
+methods.add = function (params, callback) {
+ if (slaves.hasOwnProperty(params[0])) {
+ return callback(new Error('name already taken'))
+ } else {
+ create_feedbot(params[0], params[1], [news_channel])
+ return callback(null)
+ }
+}
+methods.del = function (params, callback) {
+ var slave = slaves[params[0]]
+ if (slave) {
+ slave.client.disconnect()
+ delete slaves[params[0]]
+ return callback(null)
+ } else {
+ return callback(new Error('botname not found'))
+ }
+}
+methods.save = function (params, callback) {
+ var feeds = Object.keys(slaves)
+ .map(function (nick) {
+ return slaves[nick]
+ })
+ .map(function (slave) {
+ return [
+ slave.nick,
+ slave.uri,
+ slave.channels.join(' '),
+ ].join('|')
+ }).join('\n') + '\n'
+ return FS.writeFile(feeds_file, feeds, function (error) {
+ if (error) {
+ return callback(error)
+ } else {
+ return callback(null, 'Feeds saved')
+ }
+ })
+}
+
+
if (require.main === module) {
main()
}
diff --git a/news/newsbot.py b/news/newsbot.py
index 19ca3647..2f8bf635 100644
--- a/news/newsbot.py
+++ b/news/newsbot.py
@@ -17,7 +17,7 @@ from time import sleep
## Newsbot Controller Class
class NewsBot(asybot):
- def __init__(self, name, channels=['#test'], server='ire', port=6667, timeout=60, loglevel=logging.ERROR, url_shortener='http://wall'):
+ def __init__(self, name, channels=['#test'], server='ire', port=6667, timeout=60, loglevel=logging.ERROR, url_shortener='http://localhost'):
asybot.__init__(self, server, port, name, channels, loglevel=loglevel)
self.to = timeout
self.url_shortener = url_shortener
@@ -140,7 +140,9 @@ class RssBot(asybot):
self.lastnew = datetime.now()
self.url_shortener = url_shortener
self.retry = True
- self.on_nickinuse = lambda: None
+
+ def on_nickinuse(*bla):
+ pass
def start_rss(self):
self.upd_loop = threading.Thread(target=self.updateloop)
@@ -223,12 +225,16 @@ class RssBot(asybot):
self.push('JOIN ' + chan)
self.channels.append(chan)
+ def on_welcome(self, prefix, command, params, rest):
+ asybot.on_welcome(self, prefix, command, params, rest)
+ self.push('MODE ' + self.nickname + ' +D')
+
feedfile = 'new_feeds'
-url_shortener = 'http://wall'
+url_shortener = 'http://go'
init_channels = ['#news']
bots = {}
-knews = NewsBot('knews', init_channels)
+knews = NewsBot('knews', init_channels, url_shortener=url_shortener)
#config file reading
F = open(feedfile, "r")