Beispiel #1
0
    def send_tweet(self, twitter_id, message):
        post_data = self.twitter.post_message(twitter_id, message)
        if post_data.status_code == 200:
            time.sleeps(61)

        else:
            raise RuntimeError("Error sending message: (%s)" % str(e))

        return post_data
Beispiel #2
0
def connect (host,user,password,release):
  global Found
  global Fails
  try:
    s = pxssh.pxssh()
    s.login(host,user,password)
    print '[+] Password Found: ' + password
  Found = True
  except Exception e:
    if 'read_nonblocking' in str(e):
      Fails += 1
      time.sleeps(5)
      connect(host,user,password,False)
    elif 'synchronize with original prompt' in str(e):
      time.sleep(1)
      connect(host,user,password,False)
    finally:
Beispiel #3
0
 def serialread(self, path):
     myline = ""
     try:
         if (self.ser.isOpen() == False):
             self.ser.open()
         if (self.ser.inWaiting() > 0):
             myline = self.ser.readline()
             self.ser.flushInput()
     except IOError as e:
         #Disconnect of USB->UART occured
         print(e)
         time.sleep(5)
         return -1
     except TypeError as e:
         print(e)
         self.ser.flushInput()
         self.ser.close()
         time.sleeps(5)
     except serial.SerialException as e:
         #There is no new data from serial port
         print(e)
         self.ser.flushInput()
         self.ser.close()
         time.sleep(5)
     else:
         #Some data was received
         p = re.compile('[^:\s]+:[\d|\.|-]+:[^\s]+')
         vals = p.findall(myline)
         ts = time.time()
         timestamp = datetime.datetime.fromtimestamp(ts).strftime(
             '%Y-%m-%d %H:%M:%S')
         print myline
         if (len(vals) > 0):
             for val in vals:
                 info = val.split(':')
                 if (len(info) == 3 and info[0] != 'MILLIS'):
                     print timestamp + " " + str(val)
                     self.log_measurement(timestamp, info[1], info[0],
                                          info[2])
     return 0
Beispiel #4
0
    def serialreadUSB(self, path):
        myline = ""
        try:
            if (self.serUSB.isOpen() == False):
                self.serUSB.open()
            if (self.serUSB.inWaiting() > 0):
                myline = self.serUSB.readline()
                self.serUSB.flushInput()
        except IOError as e:
            self.initserialUSB()
            '''
			#Disconnect of USB->UART occured
			print(e)
			if path == '/dev/ttyUSB1' :
				path = '/dev/ttyUSB0'
				print "Using "+path
			else :
				path = '/dev/ttyUSB1'
				print "Using "+path
			try :
				self.serUSB = serial.Serial(path,
							baudrate=9600,
							bytesize=serial.EIGHTBITS,
							parity=serial.PARITY_NONE,
							stopbits=serial.STOPBITS_ONE,
							timeout=1,
							xonxoff=0,
							rtscts=0
				)
				self.serUSB.setDTR(False)
				self.serUSB.flushInput()
				time.sleep(1)
				self.serUSB.setDTR(True)
			except IOError as e:
				print(e)
			'''
        except TypeError as e:
            print(e)
            self.serUSB.flushInput()
            self.serUSB.close()
            time.sleeps(5)
        except serial.SerialException as e:
            #There is no new data from serial port
            print(e)
            self.serUSB.flushInput()
            self.serUSB.close()
            time.sleep(5)
        else:
            self.parsereading(myline)
            '''
			#Some data was received
			p = re.compile('[^:\s]+:[^:\s]+:[\d|\.|-]+:[^\s]+')
			vals = p.findall(myline)
			ts = time.time()
			timestamp = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
			print myline
			if (len(vals) > 0):
				for val in vals:
					info = val.split(':')
					if (len(info) == 4 and info[0] != 'MILLIS'):
						if (info[0] in self.nodeids and info[1] in self.nodeids[info[0]]) :
							print timestamp+" "+str(val)
							self.log_emoncms(timestamp, info[0], info[1], info[2])
						else :
							print timestamp+" "+str(val)+" not ok !"
			'''
        return path