Erste Release von Balu
authorMoritz Rosenthal <moritz@major-tom.(none)>
Sun, 4 Dec 2011 17:53:18 +0000 (18:53 +0100)
committerMoritz Rosenthal <moritz@major-tom.(none)>
Sun, 4 Dec 2011 17:53:18 +0000 (18:53 +0100)
two.py [new file with mode: 0644]
users.csv [new file with mode: 0644]

diff --git a/two.py b/two.py
new file mode 100644 (file)
index 0000000..82b5e75
--- /dev/null
+++ b/two.py
@@ -0,0 +1,133 @@
+#!/usr/bin/env python
+
+
+import sys
+import socket
+import string
+import ow
+import time
+import os
+
+import ssl
+import pprint
+
+HOST="irc.hackint.eu"
+PORT=9999
+NICK="lisaBOT"
+IDENT="Lisa"
+PW="hackquarter4ever"
+REALNAME="Bot"
+CHAN="#lisaBOTChan"
+readbuffer=""
+
+
+#read config
+if len(sys.argv) != 2:
+  print "Usage:" + sys.argv[0] +  " Filename"
+
+
+ow.init('u')
+
+userHash = {}
+try:
+  with open( sys.argv[1] , "r" ) as fd :
+    for i in fd.readlines():
+      try:
+        userHash[int(i.split(';')[0].strip())] = [i.split(';')[1].strip(),False]
+      except:
+        print "Could not parse file"
+        print sys.exc_info()[0]
+        sys.exit(-1)
+except:
+  print "FATAL ERROR"
+  print sys.exc_info()[0]
+  sys.exit(-1)
+
+alteListe = set()
+
+#end setup 
+
+#function 
+def process(diff):
+  global s 
+  for i in diff:
+    userHash[i][1] = not userHash[i][1]
+    if userHash[i][1]:
+      s.send("PRIVMSG %s :%s\r\n" % (CHAN, "!join " + userHash[i][0]))
+    else:
+      s.send("PRIVMSG %s :%s\r\n" % (CHAN, "!part " + userHash[i][0]))
+
+def process1wire():
+  global alteListe
+  global tempListe 
+  try:
+    try:
+      tempListe = ow.Sensor('/uncached/').sensorList()
+    except ow.exUnknownSensor:
+      print "fehler"
+    neueListe = set()
+    for i in tempListe:
+      if i.type == 'DS2401':
+        neueListe.add(int(i.r_id,16))
+      #else:
+      #  print i.type
+    diff = neueListe - alteListe
+    alteListe = neueListe
+    process(diff)
+  except KeyboardInterrupt:
+    ow.finish()
+    sys.exit(0) 
+
+
+s = ssl.wrap_socket(socket.socket(socket.AF_INET))
+#context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
+#context.verify_mode = ssl.CERT_NONE
+#s = context.wrap_socket(socket.socket(socket.AF_INET))
+s.connect((HOST, PORT))
+s.send("NICK %s\r\n" % NICK)
+s.send("USER %s 8 * : %s \r\n" % (IDENT, REALNAME))
+
+
+line = False
+
+while not line or not line[0]=="PING":
+  readbuffer=readbuffer+s.recv(1024)
+  temp=string.split(readbuffer, "\n")
+  readbuffer=temp.pop( )
+
+  for line in temp:
+    print line
+    line=string.rstrip(line)
+    line=string.split(line)
+    if(line[0]=="PING"):
+      s.send("PONG %s\r\n" % line[1])
+      print "Pong send"
+
+
+s.send("PRIVMSG Nickserv : identify %s\r\n" % (PW))
+s.send("JOIN :%s\r\n" % CHAN)
+
+
+#s.send("PRIVMSG %s :%s\r\n" % (CHAN, "Hello There!"))
+#s.send("PRIVMSG %s :%s\r\n" % (CHAN, "I am a bot"))
+
+s.settimeout(1)
+
+while 1:
+  try:
+    readbuffer=readbuffer+s.recv(1024)
+    temp=string.split(readbuffer, "\n")
+    readbuffer=temp.pop( )
+
+    for line in temp:
+      print line
+      line=string.rstrip(line)
+      line=string.split(line)
+
+      if(line[0]=="PING"):
+        s.send("PONG %s\r\n" % line[1])
+        print "Pong send"
+  except socket.timeout:
+    process1wire()
+  except ssl.SSLError:
+    process1wire()
diff --git a/users.csv b/users.csv
new file mode 100644 (file)
index 0000000..5c5149a
--- /dev/null
+++ b/users.csv
@@ -0,0 +1,8 @@
+347171366;mrm2m
+347176892;bongo
+347138440;dd2
+347135743;sommteck
+347185958;schma
+347146067;evilyves
+347183851;bdu
+347134686;balu