def test_log_file(self):

        if os.path.isfile(testing) :
            os.remove(testing)
        Log.create('FILE',testing,True)
        Log.info('wololo')
        eq_(True, os.path.isfile(testing))
Beispiel #2
0
def run(config):
    # Do 0)
    log = Log.create(level=config.log_level, verbose=Log.NOTICE)

    sql = MySQL()
    system = System()

    # Do 1)
    try:
        commands = Commands(file=config.commands, sql=sql, system=system)
    except IOError, e:
        log.error("Unable to read commands file (check config)")
        log.error(e)
        sys.exit(1)
Beispiel #3
0
 def init_logging(self, log):
     if log == 'db':
         Log.create()
     else:
         Log.create('FILE', log)
 def test_log_message(self):
     Log.create('DB','',True)
     logs = test_mongo.get_collection('logs')
     logs.remove()
     Log.info('MyTur')
     eq_('MyTur',logs.find()[0]["message"])
 def test_log_type(self):
     Log.create('DB','',True)
     logs = test_mongo.get_collection('logs')
     logs.remove()
     Log.error('Traktorz')
     eq_("error",logs.find()[0]["type"])
 def test_log_db(self):
     Log.create('DB','',True)
     logs = test_mongo.get_collection('logs')
     logs.remove()
     Log.info('wololoo')
     eq_(1, logs.count())
Beispiel #7
0
    def blockParse(self, block):
        log = Log()
        log.config()

        detail = None
        imgUrls = list()
        forwardNumber = commentsNumber = like = 0
        nickname = verify = avatar = video = id = userID = time = timestamp = deviceID = ''
        hrefLink = 'http://verified.weibo.com/verify'

        try:
            detail = block.find_element_by_css_selector('div.WB_feed_detail')
            nickInfo = detail.find_element_by_css_selector(
                'div.feed_content.wbcon>a.W_texta.W_fb')
            nickname = nickInfo.text
            userID = self.getUserID(nickInfo.get_attribute('href'))
            id = self.getUID(userID)
        except NoSuchElementException as e:
            print('Can not find block info, error: ' + str(e))

        # If does not match this tag, then verification is null
        try:
            approve = detail.find_element_by_class_name('W_icon')
            href = approve.get_attribute('href')
            if href == hrefLink:
                verify = approve.get_attribute('title')
        except (NoSuchElementException, NoSuchAttributeException):
            verify = ''

        try:
            avatarTag = detail.find_element_by_css_selector(
                'img.W_face_radius')
            avatarAlt = avatarTag.get_attribute('alt')
            if avatarAlt == nickname:
                avatar = avatarTag.get_attribute('src')

            try:
                text = detail.find_element_by_css_selector(
                    'div.feed_content.wbcon>p[node-type="feed_list_content_full"]'
                )
                content = self.contentFilter(text)
                contentLink = self.getContentLink(text)
            except NoSuchElementException:
                try:
                    text = detail.find_element_by_css_selector(
                        'div.feed_content>p.comment_txt')
                    content = self.contentFilter(text)
                    contentLink = self.getContentLink(text)
                except NoSuchElementException:
                    content = ''
                    contentLink = ''
            try:
                media = detail.find_element_by_css_selector(
                    'div.feed_content.wbcon>div.WB_media_wrap.clearfix')
                mediaBox = media.find_element_by_css_selector('div.media_box')
            except NoSuchElementException:
                pass
            else:
                try:
                    nodeType = mediaBox.get_attribute('node-type')
                    # Pictures list display, more than one picture
                    if nodeType == 'fl_pic_list':
                        li = mediaBox.find_elements_by_css_selector(
                            'li.WB_pic')  # Get a list of picture
                        for img in li:
                            src = img.find_element_by_tag_name(
                                'img').get_attribute('src')  # Obtain image url
                            url = self.replaceBigPic(src)
                            imgUrls.append(url)
                    else:
                        # It only has just one single media, one picture or a video frame
                        try:

                            img = mediaBox.find_element_by_css_selector(
                                'ul.WB_media_a>li>img')
                            src = img.get_attribute('src')
                            url = self.replaceBigPic(src)
                            imgUrls.append(url)
                            video = ''
                        except (NoSuchElementException,
                                NoSuchAttributeException):
                            # Obtain video url
                            try:
                                div = mediaBox.find_element_by_css_selector(
                                    'div.media_box_video_1>div.media_box_video_pic'
                                )
                                a = div.find_element_by_css_selector(
                                    'a.WB_video.S_bg1.WB_video_a')
                                src = a.get_attribute('action-data')
                                video = self.getVideoLink(src)
                                imgUrls = []
                            except (NoSuchElementException,
                                    NoSuchAttributeException) as e:
                                pass
                except NoSuchElementException as e:
                    log.create()
                    log.record('', nickname, str(e))
                    pass
            try:
                # Obtain time, timestamp and device id
                polymerization = detail.find_element_by_css_selector(
                    'div.feed_from.W_textb')
                timeInfo = polymerization.find_element_by_css_selector(
                    'a[node-type="feed_list_item_date"]')
                time = timeInfo.get_attribute('title')
                timestamp = timeInfo.get_attribute('date')
                try:
                    deviceID = polymerization.find_element_by_css_selector(
                        'a[rel="nofollow"]').text
                except NoSuchElementException:
                    pass
            except (NoSuchElementException, NoSuchAttributeException) as e:
                pass
            else:
                # Obtain forward number, comments number and like number
                try:
                    feedAction = block.find_element_by_css_selector(
                        'ul.feed_action_info.feed_action_row4')
                    li = feedAction.find_elements_by_tag_name('li>a')
                    # Forward number
                    try:
                        forward = li[1].find_element_by_tag_name('em').text
                        forwardNumber = 0 if forward == '' else int(forward)
                    except NoSuchElementException:
                        forwardNumber = 0

                    # Comments number
                    try:
                        comments = li[2].find_element_by_tag_name('em').text
                        commentsNumber = 0 if comments == '' else int(comments)
                    except NoSuchElementException:
                        commentsNumber = 0

                    # Like number
                    try:
                        likes = li[3].find_element_by_tag_name('em').text
                        like = 0 if likes == '' else int(likes)
                    except NoSuchElementException:
                        like = 0
                except NoSuchElementException:
                    pass

            data = dict(id=id,
                        userID=userID,
                        avatar=avatar,
                        nickname=nickname,
                        verification=verify,
                        text=content,
                        contentLink=contentLink,
                        time=time,
                        timestamp=timestamp,
                        deviceID=deviceID,
                        forwardNumber=forwardNumber,
                        commentsNumber=commentsNumber,
                        like=like,
                        video=video,
                        imgUrls=imgUrls)
            return data
        except (NoSuchElementException, NoSuchAttributeException) as e:
            print('All Information error: ' + nickname + ' | ' + str(e))