def follow_hashtag_per_location_file(bot,
                                     hashtags_file,
                                     max_likes_amount,
                                     like_after_follow=False,
                                     follow_user_followers=None):
    if hashtags_file is None:
        return False
    try:
        hashtags = read_hashtags(hashtags_file)
        locations = read_locations(locations_file)
        if (len(hashtags) == 0):
            write_exception("no more hashtags , all were comsumed!")
            send_notification("HASHTAGS from {}".format(str(bot.username)),
                              "no more hashtags , all were comsumed!")
        for tag in hashtags:
            found = False
            for location in locations:
                if follow_hashtag_per_location(
                        bot,
                        hashtag=tag,
                        new_location=location,
                        amount=max_likes_amount,
                        like_after_follow=like_after_follow,
                        follow_followers=follow_followers):
                    found = True

            if not found:
                delete_hashtag(tag)
        return True
    except Exception as e:
        write_exception(str(e) + "from follow_hashtag_per_location")
        return False
Exemple #2
0
 def start(self,sens, method, mail, sound, notif):
     self.online = False
     print "staring..."
     iterator = 0
     count = 0
     while True:
         success, image = self.video.read()
         if not success:
             continue
         iterator += 1
         gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
         if method == 'face':
             faceCascade = cv2.CascadeClassifier("faceDetect.xml")
         elif method == 'ubody':
             faceCascade = cv2.CascadeClassifier("haarcascade_upperbody.xml")
         elif method == 'fbody':
             faceCascade = cv2.CascadeClassifier("haarcascade_fullbody.xml")
         faces = faceCascade.detectMultiScale(
             gray,
             scaleFactor=1.1,
             minNeighbors=5,
             flags=cv2.cv.CV_HAAR_SCALE_IMAGE
              )
         if type(faces) is not tuple:
             count+=1
         if self.online:
             print "Stopped by User"
             return
         if count == sens:
             print "Face Detected!"
             img = self.get_frame(False)
             if notif:
                 try:
                     print "sending Image to mail....."
                     mailer.send_notification(self.config)
                 except:
                     print "ERROR"
             if mail:
                 try:
                     print "sending Image to mail....."
                     mailer.sendMessege(img, self.config)
                     return
                 except:
                     print "ERROR"
             if sound:
                 winsound.PlaySound(self.config.get('Other')['alarm'], winsound.SND_FILENAME)
             return  
         if iterator==12:
             iterator=0
             count=0
Exemple #3
0
def like_file_hashtags(bot, hashtags_file=None, ):
    if hashtags_file is None:
        return False
    try:
        hashtags = read_hashtags(hashtags_file)
        if(len(hashtags) == 0):
            write_exception("no more hashtags , all were comsumed!")
            send_notification("HASHTAGS {}".format(str(bot.username)),"no more hashtags , all were comsumed!")
        for tag in hashtags:
            if not like_hashtag(bot, hashtag=tag):
                delete_hashtag(tag)
        return True
    except Exception as e:
        write_exception(str(e) + "from like_file_hashtags")
        return False
    def follow_file(self):
        if self.follow_file is None:
            return True
        try:
            follow_list = read_followers(follow_file)

            if len(follow_file) <= 1:
                send_notification("USERS from {}".format(srt(self.bot.username)),"no more user to follow!")

            for user in follow_list:
                if not self.follow_user_followers(username = user):
                    delete_follower(user, follow_file)
                    write_blacklist(user)
        except Exception as e:
            print(e)
            write_exception(e)
            return False
def follow_file(bot, follow_file):
    if follow_file is None:
        return False
    try:
        follow_list = read_followers(follow_file)
        if len(follow_list) < 1:
            send_notification("USERS from {}".format(str(bot.username)),
                              "no more user to follow!")

        for user in follow_list:
            if not follow_user_followers(bot, username=user):
                delete_follower(user, follow_file)
                write_blacklist(user, bot)
    except Exception as e:
        print(e)
        write_exception(str(e) + " from follow_file()")
        return False
    def follow_hashtag_per_location_file(self):
        if self.hashtags_file is None:
            return False
        try:
            hashtags = read_hashtags(hashtags_file)
            locations = read_locations(locations_file)
            if(len(hashtags) == 0):
                write_exception("no more hashtags , all were comsumed!")
                send_notification("HASHTAGS from {}".format(str(self.bot.username)),"no more hashtags , all were comsumed!")
            for tag in hashtags:
                found = False
                for location in locations:
                    if self.follow_hashtag_per_location(hashtag=tag,new_location=location,amount=self.max_likes_amount):
                        found = True

                if not found:
                    delete_hashtag(tag)
            return True
        except Exception as e:
            write_exception(str(e))
            return False
Exemple #7
0
    def start(self, sens, method, mail, sound, notif):
        self.online = False
        logging.info('Active security started at ' +
                     str(datetime.datetime.now()))
        iterator = 0
        repeated = 0
        sequence_capture = False
        self.first_captured = None
        while True:
            success, image = self.video.read()
            if not success:
                continue
            iterator += 1
            gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

            if method == 'face':
                faceCascade = cv2.CascadeClassifier(
                    "haarcascade/faceDetect.xml")
            elif method == 'ubody':
                faceCascade = cv2.CascadeClassifier(
                    "haarcascade/haarcascade_upperbody.xml")
            elif method == 'fbody':
                faceCascade = cv2.CascadeClassifier(
                    "haarcascade/haarcascade_fullbody.xml")
            elif method == 'move':
                if self.first_captured is None:
                    self.first_captured = gray
                frameDelta = cv2.absdiff(self.first_captured, gray)
                self.first_captured = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
                thresh = cv2.threshold(frameDelta, 25, 255,
                                       cv2.THRESH_BINARY)[1]
                thresh = cv2.dilate(thresh, None, iterations=2)
                (cnts, _) = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
                                             cv2.CHAIN_APPROX_SIMPLE)
                for c in cnts:
                    if cv2.contourArea(c) < int(
                            self.config.get('Video')['min_movement_object']):
                        continue
                    repeated += 1
                    break
            if method == 'ubody' or method == 'fbody' or method == 'face':
                #TODO export arguments to config file
                faces = faceCascade.detectMultiScale(gray,
                                                     scaleFactor=1.1,
                                                     minNeighbors=5,
                                                     flags=0)
                if type(faces) is not tuple:
                    if sequence_capture:
                        repeated += 1
                    sequence_capture = True
                else:
                    sequence_capture = False
                    repeated = 0
            if self.online:
                logging.info('Active security Stopped by user at ' +
                             str(datetime.datetime.now()))
                self.first_captured = None
                return
            if repeated == (6 - sens):
                logging.info('Figure has been Detected at ' +
                             str(datetime.datetime.now()))
                ret, jpeg = cv2.imencode('.jpg', image)
                img = jpeg.tostring()
                if notif:
                    try:
                        logging.info('Sending notification  ' +
                                     str(datetime.datetime.now()))
                        if 'bxc' in self.config.get("Notifications"):
                            mailer.send_notification(self.config)
                        if self.notification.user:
                            self.notification.send_notification()
                    except:
                        logging.warn('Error sending notification  ' +
                                     str(datetime.datetime.now()))
                if sound:
                    pygame.mixer.music.load(self.config.get('Sound')['alarm'])
                    pygame.mixer.music.play()
                    while pygame.mixer.music.get_busy() == True:
                        continue

                if mail:
                    try:
                        logging.info('Sending email ' +
                                     str(datetime.datetime.now()))
                        mailer.sendMessege(img, self.config)
                    except:
                        logging.info('Error Sending Mail ' +
                                     str(datetime.datetime.now()))
                self.first_captured = None
                return
            if iterator == 10:
                iterator = 0
                repeated = 0
Exemple #8
0
    def start(self,sens, method, mail, sound, notif):
        self.online = False
        logging.info('Active security started at ' + str(datetime.datetime.now()))
        iterator = 0
        repeated = 0
        sequence_capture = False
        self.first_captured = None
        while True:
            success, image = self.video.read()
            if not success:
                continue
            iterator += 1
            gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

            if method == 'face':
                faceCascade = cv2.CascadeClassifier("haarcascade/faceDetect.xml")
            elif method == 'ubody':
                faceCascade = cv2.CascadeClassifier("haarcascade/haarcascade_upperbody.xml")
            elif method == 'fbody':
                faceCascade = cv2.CascadeClassifier("haarcascade/haarcascade_fullbody.xml")
            elif method == 'move':
                if self.first_captured is None:
                    self.first_captured = gray
                frameDelta = cv2.absdiff(self.first_captured, gray)
                self.first_captured = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
                thresh = cv2.threshold(frameDelta, 25, 255, cv2.THRESH_BINARY)[1]
                thresh = cv2.dilate(thresh, None, iterations=2)
                (cnts, _) = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
                for c in cnts:
                    if cv2.contourArea(c) < int(self.config.get('Video')['min_movement_object']):
                        continue
                    repeated += 1
                    break
            if method == 'ubody' or method == 'fbody' or method == 'face':
                #TODO export arguments to config file
                faces = faceCascade.detectMultiScale(
                    gray,
                    scaleFactor=1.1,
                    minNeighbors=5,
                    flags=0)
                if type(faces) is not tuple:
                    if sequence_capture:
                        repeated += 1
                    sequence_capture = True
                else:
                    sequence_capture = False
                    repeated = 0
            if self.online:
                logging.info('Active security Stopped by user at ' + str(datetime.datetime.now()))
                self.first_captured = None
                return
            if repeated == (6 - sens):
                logging.info('Figure has been Detected at ' + str(datetime.datetime.now()))
                ret, jpeg = cv2.imencode('.jpg', image)
                img = jpeg.tostring()
                if notif:
                    try:
                        logging.info('Sending notification  ' + str(datetime.datetime.now()))
                        mailer.send_notification(self.config)
                    except:
                        logging.warn('Error sending notification  ' + str(datetime.datetime.now()))
                if sound: 
                    pygame.mixer.music.load(self.config.get('Sound')['alarm'])
                    pygame.mixer.music.play()
                    while pygame.mixer.music.get_busy() == True:
                        continue

                if mail:
                    try:
                        logging.info('Sending email ' + str(datetime.datetime.now()))
                        mailer.sendMessege(img, self.config)
                    except:
                        logging.info('Error Sending Mail ' + str(datetime.datetime.now()))
                self.first_captured = None
                return
            if iterator == 10:
                iterator = 0
                repeated = 0