user@linuxtrack:~ $ python -c 'print("Soyez les bienvenus !")'

Vous n'êtes pas identifié(e).

#1 24-07-2013 19:36:46

IceF0x
#! Gourou Linux

RSS bot IRC

Voici le bot IRC utilisé pour le chan IRC #cybernux

== Code ==

#!/usr/bin/python
#
# IRC b0t that keeps track of RSS feeds
#
# Licensed under the GNU General Public License v3
#
# Copyright (2009) by Akarsh Simha modify by IceF0x

import irclib
import feedparser
import os
import threading
import time

channel_list = [ "#cyber-nux" ] # Put in a list of channels
feed_list = [ "http://www.linuxtrack.com/rss.php"]
old_entries_file = os.environ.get("HOME") + "/.b0t/old-feed.entry"

irc = irclib.IRC()
server = irc.server()

server.connect( "irc.ubuntu.com", 6667, "RSS-track" ) # TODO: Make this general
# server.privmsg( "NickServ", "identify " )

msgqueue = []

def feed_refresh():
 #print "Test"
 FILE = open( old_entries_file, "r" )
 filetext = FILE.read()
 FILE.close()
 for feed in feed_list:
  NextFeed = False
  d = feedparser.parse( feed )
  for entry in d.entries:
   id = entry.link.encode('utf-8')+entry.title.encode('utf-8')
   if id in filetext:
    NextFeed = True
   else:
    FILE = open( old_entries_file, "a" )
    #print entry.title + "\n"
    FILE.write( id + "\n" )
    FILE.close()
    msgqueue.append( entry.title.encode('utf-8') + " : " + entry.link.encode('utf-8') )
   if NextFeed:
    break;

 t = threading.Timer( 500.0, feed_refresh ) # TODO: make this static
 t.start()

for channel in channel_list:
  server.join( channel )

feed_refresh()

while 1:
 while len(msgqueue) > 0:
  msg = msgqueue.pop()
  for channel in channel_list:
   server.privmsg( channel, msg )
 time.sleep(1) # TODO: Fix bad code
 irc.process_once()
 time.sleep(1) # So that we don't hog the CPU!

== Installation ==

mkdir ~/.b0t/
touch ~/.b0t/old-feed.entry

== Usage ==

./rss.py

Utiliser des logiciels propriétaires, c'est comme les plats préparés, on est incapable de dire les conservateurs qu'ils contiennent, on dira toujours que c'est bon, mais ça ne remplacera jamais le repas fait maison par sa maman.
]:D #! Crunchbang & Archlinux GNU/Linux User ]:D

Hors ligne

Pied de page des forums