Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Python Executescript processor

Python Executescript processor

New Contributor

I am working on a python script to post messages to a irc chat. From what I understand I need to use session.get() in order to retrieve flowfiles from a queue. 

I have tried several things but have not been able to retrieve any files from the queue to successfully post. 

 

 

 

import socket
from org.apache.nifi.processor.io import StreamCallback, InputStreamCallback

class PyStreamCallback(InputStreamCallback):
    def __init__(self):
       pass
       self.ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
       self.server = "irc.freenode.net"
       self.channel = ""
       self.botnick = ""
       self.ircsock.connect((self.server, 6667))
       self.ircsock.send(bytes("USER "+ botnick +" "+ botnick +" "+ botnick + " " + botnick + "\n"))
       self.ircsock.send(bytes("NICK "+ botnick +"\n"))

    def joinchan(self, chan):
      self.ircsock.send(bytes("JOIN "+ chan +"\n"))
      ircmsg = ""
      while ircmsg.find("End of /NAMES list.") == -1:
        self.ircmsg = ircsock.recv(2048)
        self.ircmsg = ircmsg.strip('\n\r')
        print(ircmsg)

    def sendmsg(self, msg, target=self.channel):
      self.ircsock.send(bytes("PRIVMSG "+ target +" :"+ msg +"\n"))



flowFile = session.get()
if (flowFile != None):
  flowFile = session.read(flowFile,PyStreamCallback())
session.commit()

 

Don't have an account?
Coming from Hortonworks? Activate your account here