Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- from ConfigParser import RawConfigParser as ConfParser
- from BeautifulSoup import BeautifulSoup
- from optparse import OptionParser
- from collections import deque
- from time import sleep, time, gmtime, strftime
- import ConfigParser
- import os
- import sys
- import socket
- import codecs
- from irc import *
- from select import select
- import urllib
- import imp
- import modules.fml
- import modules.meme
- import modules.bitly
- my = IRCbot()
- start = time()
- try:
- config = ConfigParser.RawConfigParser()
- config.readfp(codecs.open("config.ini", "r", "utf8"))
- except IOError as config:
- sys.exit()
- def main():
- """ A demo daemon main routine, write a datestamp to
- /tmp/daemon-log every 10 seconds.
- """
- import time
- f = open("/tmp/daemon-log", "w")
- while 1:
- f.write('%s\n' % time.ctime(time.time()))
- f.flush()
- time.sleep(10)
- if __name__ == "__main__":
- # do the UNIX double-fork magic, see Stevens' "Advanced
- # Programming in the UNIX Environment" for details (ISBN 0201563177)
- try:
- pid = os.fork()
- if pid > 0:
- # exit first parent
- sys.exit(0)
- except OSError, e:
- print >>sys.stderr, "fork #1 failed: %d (%s)" % (e.errno, e.strerror)
- sys.exit(1)
- # decouple from parent environment
- os.chdir("/")
- os.setsid()
- os.umask(0)
- # do second fork
- try:
- pid = os.fork()
- if pid > 0:
- # exit from second parent, print eventual PID before
- print "Daemon PID %d" % pid
- sys.exit(0)
- except OSError, e:
- print >>sys.stderr, "fork #2 failed: %d (%s)" % (e.errno, e.strerror)
- sys.exit(1)
- irc = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
- irc.connect ((config.get('connection', 'server'),config.getint('connection', 'port')))
- irc.send ('NICK %s\r\n' % config.get('irc-bot', 'nickname'))
- irc.send ('USER %s %s Internets :%s\r\n' % (config.get('irc-bot', 'ident'), config.get('irc-bot', 'nickname'), config.get('irc-bot', 'realname')))
- while 1:
- (rl, wl, xl) = select([irc], [], [])
- for sock in rl:
- data = readline(sock)
- raw = parse(data)
- if sock == irc:
- print raw
- if raw[0] == "PING":
- sock.send("PONG %s\r\n" % raw[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement