Exemple #1
0
 def __init__(self, acesRelease='', timeStamp=''):
     "%s - Initialize the standard class variables" % 'Config'
     self._children = []
     if acesRelease != '':
         self._children.append( Comment(acesRelease, 'ACESrelease_Version') )
     if timeStamp != '':
         self._children.append( Comment(timeStamp, 'Timestamp') )
Exemple #2
0
    def saveBlog(self):
        #获取html中所需的内容,可以通过Chrome开发者工具的element选项在人人网该页面查看
        self.content = self.spider.getContent(self.url)
        soup = BeautifulSoup(self.content)
        blogContent = soup.find('div',
                                id='blogContent',
                                class_='blogDetail-content')

        #将标签换位换行符,方便阅读
        pattern = r'<p>|<br>|</p>|<br/>'  #将<p>,<br>,</p>和<br/>四个标签换为换行符\n
        blogContent = re.sub(pattern, r'\n', blogContent.decode())

        with open(self.filename, 'wb+') as f:
            line = u'*** 日志标题: ***' + self.summary['title'] + '\n\n'
            line += u'*** 创建时间: ***' + self.summary['createTime'] + '\n\n'
            line += u'*** 所属分类: ***' + self.summary['category'] + '\n\n'
            line += Config.GAP
            f.write(line.encode('utf-8'))
            f.write(blogContent.encode('utf-8'))
            if int(self.summary['commentCount']):
                f.write(Config.GAP.encode('utf-8'))
                f.write((u'*** 评论: ***\n\n').encode('utf-8'))
                comments = Comment(self.spider, self.userID, self.blogID,
                                   'blog', self.ownerID)
                f.write(comments.work())
        print(self.filename + ' saves successfully')
Exemple #3
0
    def read(self, element):
        # Read child elements
        for child in element:
            elementType = child.tag

            if elementType == 'ACESrelease_Version':
                self._children.append( Comment(child.text, 'ACESrelease_Version') )
            elif elementType == 'Timestamp':
                self._children.append( Comment(child.text, 'Timestamp') )
            else:
                # Remove text used in xml names but not class names
                elementType = elementType.replace('-', '')
                elementType = elementType.replace('_', '')
                elementType = elementType.replace('aces:', '')
                elementType = normalize(elementType)

                elementClass = self.getClass(elementType)

                if elementClass != None:
                    #print( "element : %s, %s" % (elementType, elementClass) )
                    element = elementClass()
                    element.read(child)

                    self.addElement( element )
                else:
                    print( "Config::read - Ignoring unsupport element, %s" % child.tag)
Exemple #4
0
 def getAlbumComments(self):
     comment = Comment(self.userID,self.spider,self.albumID,'album',self.ownerID)
     content = comment.work()
     if content == '':
         with open(self.path + '/comments.markdown','w') as f:
             f.write((u'**评论: **\n\n').encode('utf-8'))
             f.write(content)
Exemple #5
0
    def addPosting(self, file='', REQUEST=None,RESPONSE=None):     
        """ add a Comment """
        index=1
        id=self.createId()
        msg=Comment(id, self.id)
        err, sage = msg.__of__(self)._validation(REQUEST,RESPONSE,'delete attachment',file)
        if err:
            return err
        # Set thread number. 
        msg.tnum = str(len(self.ids) + 2)

        if sage==0:
            self.modified=id     

        self.ids.insert(id)     
        self.data[id]=msg

        if index:
            msg.__of__(self).index()
          
        if RESPONSE:
            return self.showMessage(self, REQUEST=REQUEST, 
                                title='Comment Posted',
                                message  ='Your reply has been posted',
                                action=self.absolute_url()     
                                )

        return id
Exemple #6
0
 def __init__(self, appRelease='', copyright=''):
     "%s - Initialize the standard class variables" % 'Info'
     self._children = []
     if appRelease != '':
         self._children.append( Comment(appRelease, 'AppRelease') )
     if copyright != '':
         self._children.append( Comment(copyright, 'Copyright') )
Exemple #7
0
 def getAlbumComments(self):
     comment = Comment(self.userID, self.spider, self.albumID, 'album',
                       self.ownerID)
     content = comment.work()
     if content == '':
         with open(self.path + '/comments.markdown', 'w') as f:
             f.write((u'**评论: **\n\n').encode('utf-8'))
             f.write(content)
Exemple #8
0
    def get_comments_from_maoyan(self, offset):
        comments = []

        json_str = self.get_one_page_comment_json_from_maoyan(offset)
        if json_str is None:
            return None

        try:
            data1 = json_str['cmts']  # 获取评论内容
            data2 = json_str['hcmts']  # 获取评论内容
            data = data1 + data2
        except KeyError:
            return None
        for item in data:
            comment = Comment(self.movie)
            # 使用get方法获取值,避免出现KeyError
            comment.user_loc = item.get('cityName')
            comment.user_avatar = item.get('avatarurl')
            comment.user_name = item.get('nickName')
            comment.user_id = item.get('userId')
            comment.comment = item.get('content')
            comment.create_time = item.get('time')
            comment.vote_count = item.get('approve')
            comments.append(comment)
        return comments
Exemple #9
0
 def __init__(self, clipName='', sourceMediaID='', clipDate='', note=''):
     "%s - Initialize the standard class variables" % 'ClipID'
     self._children = []
     if clipName != '':
         self._children.append(Comment(clipName, 'ClipName'))
     if clipDate != '':
         self._children.append(Comment(clipDate, 'ClipDate'))
     if sourceMediaID != '':
         self._children.append(Comment(sourceMediaID, 'Source_MediaID'))
     if note != '':
         self._children.append(Comment(note, 'Note'))
Exemple #10
0
    def read(self, element):
        # Read child elements
        for child in element:
            elementType = child.tag
            #print( "Info child element type: %s" % elementType )

            if elementType == 'Application':
                self._children.append(
                    Comment(child.text, 'Application', child.attrib))
            if elementType == 'Comment':
                self._children.append(Comment(child.text, 'Comment'))
Exemple #11
0
 def __init__(self, application='', appVersion='', comment=''):
     "%s - Initialize the standard class variables" % 'Info'
     self._children = []
     if appVersion != '':
         attributes = {}
         if appVersion != '':
             attributes['version'] = appVersion
         self._children.append(
             Comment(application, 'Application', attributes=attributes))
     if comment != '':
         self._children.append(Comment(comment, 'Comment'))
Exemple #12
0
    def read(self, element):
        # Read child elements
        for child in element:
            elementType = self.getElementType(child.tag)

            if elementType == 'AppRelease':
                self._children.append( Comment(child.text, 'AppRelease') )
            if elementType == 'Copyright':
                self._children.append( Comment(child.text, 'Copyright') )

            # Autodesk-specific attribute
            if elementType == 'Release':
                self._children.append( Comment(child.text, 'Release') )
Exemple #13
0
def Comentarios():
    if 'User' in session:
        CommentComment = Comment()
        UsuarioComentario = Usuario()
        UsuarioComentario.TraerObjeto(session['User'])
        idPosta = request.args.get("IdPost")
        Userinho = UsuarioComentario
        ComentariosDesc = request.form.get("Comentario")
        CommentComment.AllSetsComments(ComentariosDesc, idPosta, Userinho)
        CommentComment.Insert()
        return redirect("/Inicio#p" + idPosta)
    else:
        return redirect("/")
Exemple #14
0
    def setUp(self):
        self.student = User("user", "password", 1)
        self.lecture = LectureTopic(1, "L1", "author", "Lecture", "info")
        self.comment = Comment(1, "author", "info", 2, self.lecture.getLTid())
        self.subscribe = Subscription(1, self.lecture.getLTid(),
                                      self.student.getUid())
        self.notify = Notification(1, self.subscribe.getSid())

        self.db_fd, app.app.config['DATABASE'] = tempfile.mkstemp()
        app.app.testing = True
        self.app = app.app.test_client()
        with app.app.app_context():
            app.init_db()
Exemple #15
0
    def read(self, element):
        # Read child elements
        for child in element:
            elementType = child.tag

            if elementType == 'ClipName':
                self._children.append(Comment(child.text, 'ClipName'))
            if elementType == 'ClipDate':
                self._children.append(Comment(child.text, 'ClipDate'))
            if elementType == 'Source_MediaID':
                self._children.append(Comment(child.text, 'Source_MediaID'))
            if elementType == 'Note':
                self._children.append(Comment(child.text, 'Note'))
Exemple #16
0
 def savePhotoComment(self):
     with open(self.path + "/photo details.markdown", "w") as f:
         for item in self.photos:
             line = u"**ID: " + str(item["id"]) + "**\n\n"
             line += u"**名称: " + item["title"].replace("\n", " ") + "**\n\n"
             line += u"**时间: " + item["date"] + "**\n\n"
             f.write(line.encode("utf-8"))
             filename = str(item["id"])
             f.write(("![" + filename + "](" + filename + ".jpg)\n\n").encode("utf-8"))
             if int(item["commentCount"]):
                 comment = Comment(self.userID, self.spider, item["id"], "photo", item["owner"])
                 f.write((u"**评论: **\n\n").encode("utf-8"))
                 f.write(comment.work())
             f.write(config.gap)
Exemple #17
0
	def put(self):
		JSON = json.loads(json.dumps(request.get_json(force = True)))
		url = JSON['url']
		userID = current_user.email
		name = current_user.name
		content = JSON['content']
		time = str(datetime.datetime.now())
		comment = Comment(ID = userID, name = name, content = content, time = time)
		check = mongo.db.comments.find({'_id': url})
		if check.count() > 0:
			mongo.db.comments.update({'_id': url}, {'$push': {'comments': comment.toDict()}})
		else:
			mongo.db.comments.insert({'_id': url, 'comments': [comment.toDict()]})
		return {'SUCCESS': 'New Comment Updated'}
Exemple #18
0
 def saveBlog(self):
     soup = BeautifulSoup(self.content)
     blogContent = soup.find('div',id='blogContent',class_='blogDetail-content')
     with open(self.filename, 'w+') as f:
         line = u'###日志标题: ' + self.summary['title'] + '\n\n'
         line += u'#####创建时间: ' + self.summary['createTime'] + '\n\n'
         line += u'#####所属分类: ' + self.summary['category'] + '\n\n'
         line += config.gap
         f.write(line.encode('utf-8'))
         f.write(blogContent.encode('utf-8'))
         if int(self.summary['commentCount']):
             f.write(config.gap)
             f.write((u'#####评论:\n\n').encode('utf-8'))
             comments = Comment(self.userID,self.spider,self.blogID,'blog',self.ownerID)
             f.write(comments.work())
     print self.filename + ' save success'
Exemple #19
0
 def get_number_comments(self):
     number_comments = Comment.all().filter('post_id = ',
                                            self.key().id()).count()
     if number_comments:
         return number_comments
     else:
         return '0'
Exemple #20
0
    def __find_obj_by_id(self, obj_id, table_id):
        # Connect to db
        db = sqlite3.connect(self.DB_PATH)
        cur = db.cursor()
        print("Connected to db to read!")

        statement = ''

        # Prepare SQL statement
        if table_id == self.TABLE_ID_COMMENTS:
            statement = 'SELECT id, media_id, text, post_url FROM Comments WHERE id={}'.format(
                obj_id)
        elif table_id == self.TABLE_ID_RESPONSES:
            statement = 'SELECT text, id FROM Responses WHERE id={}'.format(
                obj_id)

        # Execute SQL statement
        cur.execute(statement)
        result = cur.fetchone()

        # Fill up
        if table_id == self.TABLE_ID_COMMENTS:
            return Comment(result[1], result[0], result[2], result[3])
        elif table_id == self.TABLE_ID_RESPONSES:
            return Response(result[0], result[1])
Exemple #21
0
    def process_comment(self, comment):
        result = Comment()

        # Get content
        result.content = comment.find("div", attrs={"class": "comment_content"}).text.strip()

        # Get rating
        result.rating = int(comment.find("ins").text.replace("+", ""))

        # Get author
        result.author = comment.find("a", attrs={"href": re.compile("profile")}).text.strip()

        # Get date
        result.date = comment.find("span", attrs={"class": "gray1"}).text.split("wrote on ")[-1].strip()

        return result
Exemple #22
0
    def __read_from_db(self, table_id):
        # Connect to db
        db = sqlite3.connect(self.DB_PATH)
        cur = db.cursor()
        print("Connected to db to read!")

        statement = ''

        # Prepare SQL statement
        if table_id == self.TABLE_ID_COMMENTS:
            statement = 'SELECT media_id, id, text, post_url FROM Comments'
        elif table_id == self.TABLE_ID_RESPONSES:
            statement = 'SELECT text, id FROM Responses'

        # Execute SQL statement
        cur.execute(statement)
        result = cur.fetchall()

        # Fill up
        if table_id == self.TABLE_ID_COMMENTS:
            for comment in result:
                self.comments.append(
                    Comment(comment[0], comment[1], comment[2], comment[3]))
        elif table_id == self.TABLE_ID_RESPONSES:
            for response in result:
                self.responses.append(Response(response[0], response[1]))

        print('Success!')

        db.commit()
        db.close()
Exemple #23
0
 def savePhotoComment(self):
     with open(self.path + '/photo details.markdown', 'w') as f:
         for item in self.photos:
             line = u'**ID: ' + str(item['id']) + '**\n\n'
             line += u'**名称: ' + item['title'].replace('\n', ' ') + '**\n\n'
             line += u'**时间: ' + item['date'] + '**\n\n'
             f.write(line.encode('utf-8'))
             filename = str(item['id'])
             f.write(('![' + filename + '](' + filename +
                      '.jpg)\n\n').encode('utf-8'))
             if int(item['commentCount']):
                 comment = Comment(self.userID, self.spider, item['id'],
                                   'photo', item['owner'])
                 f.write((u'**评论: **\n\n').encode('utf-8'))
                 f.write(comment.work())
             f.write(config.gap)
Exemple #24
0
 def saveBlog(self):
     soup = BeautifulSoup(self.content)
     blogContent = soup.find('div',
                             id='blogContent',
                             class_='blogDetail-content')
     with open(self.filename, 'w+') as f:
         line = u'###日志标题: ' + self.summary['title'] + '\n\n'
         line += u'#####创建时间: ' + self.summary['createTime'] + '\n\n'
         line += u'#####所属分类: ' + self.summary['category'] + '\n\n'
         line += config.gap
         f.write(line.encode('utf-8'))
         f.write(blogContent.encode('utf-8'))
         if int(self.summary['commentCount']):
             f.write(config.gap)
             f.write((u'#####评论:\n\n').encode('utf-8'))
             comments = Comment(self.userID, self.spider, self.blogID,
                                'blog', self.ownerID)
             f.write(comments.work())
     print self.filename + ' save success'
Exemple #25
0
    def post(self, id, lineno):
        paster = users.get_current_user()
        comment = self.request.get('comment').strip()

        if paster == None or comment == '':
            self.error("203")
        elif not paster:
            self.error("403")
        else:
            u = Comment(User=paster, Content=comment, PostId=id, LineNo=lineno)
            u.put()
            m = memcache.get("comments:"+id)
            if m is None:
                logging.debug("Adding new memcache entry for comments:"+id)
                memcache.add("comments:"+id, [u])
            else:
                m.append(u)
                memcache.set("comments:"+id, m)
            self.redirect('/pasty/' + id)
Exemple #26
0
    def saveContent(self):
        self.statusCount = len(self.status)
        with open(config.PATH + '/' + self.ownerID + '/status.markdown','w') as f:
            f.write('quantity of status:' + str(self.statusCount) + '\n')
            f.write(config.gap)
            for item in self.status:
                line = u'**ID号:** ' + str(item['id']) + '\n'
                line += u'**发表时间:** ' + item['dtime'] + '\n'
                line += u'**评论数:** ' + str(item['comment_count']) + '\n\n'
#                 line += 'content: ' + BeautifulSoup(item['content']).getText() + '\t\t'
                line += u'**内容:** ' + item['content'] + '\n\n'
                line += u'**原作者:** ' + item['rootDoingUserName'] + '\n\n'
                line += u'**原内容:** ' + item['rootContent'] + '\n\n'
                f.write(line.encode('utf-8'))
                if int(item['comment_count']):
                    f.write((u'**评论:**\n\n').encode('utf-8'))
                    comments = Comment(self.userID,self.spider,item['id'],'status',self.ownerID)
                    f.write(comments.work())
                f.write(config.gap)
        print datetime.datetime.now(), ': status save successfully'
Exemple #27
0
    def decode_json(self, json_str):
        # 创建评论变量
        comments = []

        # 解析关键的根节点
        count = json_str['count']
        start = json_str['start']
        interests = json_str['interests']
        total = json_str['total']

        # print('本次获取的个数为:', count)
        # print('评论为:', interests)
        # print('起始评论数为:', start)
        # print('总评论数为:', total)

        # 解析所需要的评论内容
        for interest in interests:
            comment = Comment(self.movie)

            user = interest['user']
            rating = interest['rating']

            loc = user['loc']
            if loc is not None:
                loc_name = loc['name']
                comment.user_loc = loc_name

            comment.user_avatar = user['avatar']
            comment.user_name = user['name']
            comment.user_id = user['id']
            if rating is not None:
                comment.rate = rating['value']
            comment.comment = interest['comment']
            comment.create_time = interest['create_time']
            comment.vote_count = interest['vote_count']

            comments.append(comment)

        # 保存评论内容到文件中
        self.save_comments(comments, 0)
        return start, len(interests), total
Exemple #28
0
    def savePhotoComment(self):
        with open(self.path + '/photo_detail.markdown', 'wb') as f:
            for item in self.photos:
                f.write(Config.GAP.encode('utf-8'))

                line = '***Photo ID: ' + str(item['id']) + '***\n\n'
                line += '***Photo Name: ' + item['title'].replace(
                    '\n', ' ') + '***\n\n'
                line += '*** Photo Time: ' + item['date'] + '***\n\n'
                f.write(line.encode('utf-8'))  #转为utf-8编码格式
                filename = str(item['id'])
                f.write(('Photo File Name: ' + filename +
                         '.jpg\n\n').encode('utf-8'))
                if int(item['commentCount']):
                    comment = Comment(self.spider, self.userID, item['id'],
                                      'photo', item['owner'])
                    f.write((u'***评论: ***\n\n').encode(
                        'utf-8'))  #字符串前面加u也是将编码变为utf-8,但是后面已经转码了,所以没有必要其实
                    f.write(comment.work())

                f.write(Config.GAP.encode('utf-8'))
Exemple #29
0
def recognizeSourceLineAndUpdateTree(subParts, line):
    """Updates the program call tree. List subParts IS MUTATED"""
    if isNewline(line):
        subParts.append(Newline())
    elif isComment(line):
        subParts.append(Comment(line))
    elif isImplicitNone(line):
        pass # Ignore "implicit none"
    elif isInteger(line):
        subParts.append(Integer(line))
    else:
        raise RuntimeError("Unknown statement: " + line + "Please first use a Fortran compiler")
Exemple #30
0
def collect_comments(driver, comments_dictionary):
    page_source_element = driver.find_element_by_xpath("//div[@id='root']")
    campaign_comments = page_source_element.find_element_by_class_name(
        'p-campaign-comments')
    comments = campaign_comments.find_elements_by_class_name(
        "o-comments-list-item")
    print(len(comments))
    for comment_id in range(0, len(comments)):
        if comment_id in comments_dictionary:
            continue
        comment_text = comments[comment_id].text
        comment_object = Comment(comment_text)
        comments_dictionary[comment_id] = comment_object
Exemple #31
0
 def get(self, post_hash):
     print("PostApi.get(): %s", post_hash)
     originalPost = postTable.find({Post.HASH: post_hash})[0]
     post = Post(originalPost).as_dict()
     original_comments = commentTable.find(
         {Comment.POST_HASH: post[Post.HASH]})
     commend_list = [
         Comment(originalComment).as_dict()
         for originalComment in original_comments
     ]
     post[Comment.COMMENTS] = commend_list
     print(post)
     return post
Exemple #32
0
 def post(self, path):
     try:
         print('AddCommentHandler')
         print(self.request.uri)
         content = self.get_body_argument('content')
         userid = self.get_body_argument('userid')
         poi = self.get_body_argument('poi')
         ath = self.get_body_argument('ath')
         atv = self.get_body_argument('atv')
         scene = self.get_body_argument('scene')
         comment = Comment(content, userid, poi, ath, atv, scene)
         comment.add()
         print(self.request.cookies)
         print(self.get_secure_cookie("user"))
         print(
             '===========================================================')
     except Exception as e:
         print('EXCEPTION FROM AddCommentHandler post:')
         print(e)
         self.write('1')
     else:
         self.write('0')
 def get(self, path):
     try:
         print('GetCommentHandler')
         print(self.request.uri)
         self.write(
             Comment.get(self.get_argument('poi'),
                         self.get_argument('scene')))
         print(
             '===========================================================')
     except Exception as e:
         print('EXCEPTION FROM GetCommentHandler get:')
         print(e)
         self.write('1')
Exemple #34
0
def Inicio():
    if 'User' in session:
        UsuarioInicio = Usuario()
        UsuarioInicio.TraerObjeto(session['User'])
        cursorsito = DB().run("SELECT * FROM Usuario")
        for itemsito in cursorsito:
            if itemsito["Nombre_Usuario"] == None:
                UsuarioInicio.TraerObjeto(itemsito["idUsuario"])
                UsuarioInicio.DeleteManual()
        Usuariohtml = UsuarioInicio.TraerObjeto(session['User'])
        PostSeleccionado = []
        CommentSeleccionado = []
        cursor = DB().run("SELECT * FROM Post ORDER BY(idPost)DESC")
        for item in cursor:
            PostInicio = Post()
            PostInicio.TraerObjeto(item["idPost"])
            PostInicio.Contador()
            PostSeleccionado.append(PostInicio)
        cursor2 = DB().run("SELECT * FROM `Like`")
        LikesExistentes = []
        for item2 in cursor2:
            LikeInicio = Like()
            LikeInicio.TraerObjeto(item2["Post_idPost"],
                                   item2["Usuario_idUsuario"])
            LikesExistentes.append(LikeInicio)
        cursor3 = DB().run("SELECT * FROM Comment ORDER BY(idComment)ASC")
        for item3 in cursor3:
            CommentInicio = Comment()
            CommentInicio.TraerObjeto(item3["idComment"])
            CommentSeleccionado.append(CommentInicio)
        return render_template("VerPost.html",
                               PostSeleccionado=PostSeleccionado,
                               LikesExistentes=LikesExistentes,
                               Usuariohtml=Usuariohtml,
                               UserIniciado=UsuarioInicio,
                               CommentSeleccionado=CommentSeleccionado)
    elif 'User' not in session:
        return redirect("/")
Exemple #35
0
 def __register_comment(self,
                        media_id,
                        comment_id,
                        post_code,
                        comment_text=''):
     comment = Comment(media_id, comment_id, comment_text, post_code)
     self.comments.append(comment)
     if self.__write_to_db(comment):
         print("Succesfully added comment (id: {0} , url: {2} )\r\n\t{1}".
               format(comment.get_id(), comment.get_text(),
                      comment.get_post_url()))
     else:
         print(
             "Failed to add comment (id: {0} , url: {2} )\r\n\t{1}".format(
                 comment.get_id(), comment.get_text(),
                 comment.get_post_url()))
Exemple #36
0
def download_chat_to_file(vodID : str):
    comments = []
    fragment = { '_next' : '' }

    while '_next' in fragment:
        fragment = get_chat_fragment(vodID,fragment['_next'])
        for comment in fragment['comments']:
            comments.append(Comment(comment))
        print("downloaded up to " + str(fragment['comments'][0]['content_offset_seconds']) + " seconds")

    with open('VOD#' + str(vodID), 'w') as outfile:
        json.dump(comments, outfile,default=Comment.toJSON,indent=4)
    
    perform_analytics(comments, vodID)
Exemple #37
0
    def delete(self):
        authenticated, this_user = utils.process_cookie(self.request)
        if not authenticated:
            self.response.status = 401
            return

        url_obj = urlparse.urlparse(str(self.request.url))
        subdirs = str(url_obj.path).split('/')
        num_layers = len(subdirs)
        last_dir_string = str(subdirs[len(subdirs)-1])

        if num_layers == 3:
            try:
                target_dish = int(last_dir_string)
                dishHandler.delete_dish(self, this_user, target_dish)
            except ValueError:
                self.response.status = 405
        elif num_layers == 4:
            try:
                target_dish = int(subdirs[2])
                subdir_string = str(last_dir_string)
                handling_function = delete_sub_routes["DELETE_" + subdir_string]
                getattr(globals()[subdir_string + "Handler"], handling_function)(self, this_user, target_dish)
            except ValueError:
                self.response.status = 405
            except KeyError:
                self.response.status = 405
        elif num_layers == 5 and subdirs[3] == 'comment':
            try:
                target_dish = int(subdirs[2])
                target_comment = int(last_dir_string)
                commentHandler.delete_comment(self, this_user, target_dish, target_comment)
            except ValueError:
                self.response.status = 405
        else:
            self.response.status = 405
Exemple #38
0
def execute_scrape(url, days_ago, debug=False):
    """ If debug is True - Soup constant HTML from consts.py.
        Else - Use selenium to extract HTML from URL. """
    if debug:
        comments_html = comments_txt
    else:
        comments_html = scrape_li_comments(url)
    """ All post's comments generator """
    all_comments = (Comment(*souped_cmt)
                    for souped_cmt in soup_comments(comments_html))
    """ Only post's new comments generator """
    new_comments = (c for c in all_comments
                    if c.is_newer_from_days_ago(days_ago) and c.has_mail)
    """ Print new comments """
    print_comments(new_comments)
Exemple #39
0
def parseComments(data):
    """
    Parse comments from site
    """
    global comments
    reviewBegins = '<div style="margin-left:0.5em;">'
    reviewEnds = '<div style="padding-top: 10px; clear: both; width: 100%;">'
    stars_line = 'margin-right:5px;'
    stars = re.compile('\d+.\d+ out of 5 stars')
    header_line = '<span style="vertical-align:middle;"'
    helpful_line ='people found the following review helpful'
    helpful = re.compile('\d+ of \d+ people found the following review helpful')
    reviewText = '<span class="h3color tiny">' # Actual review

    boundaries = commentsStartStopLineNmbr(data)
    for i in range(boundaries[0], boundaries[1] + 1):
        if reviewBegins in data[i]:
            curcomment = Comment()
            while reviewEnds not in data[i]:
                # Parse stars
                if stars_line in data[i]:
                    stars_found = re.search(stars, data[i])
                    if stars_found != None:
                        curcomment.stars = stars_found.group()
                # Parse header
                elif header_line in data[i]:
                    line = data[i]
                    begin = line.find('<b>') + 3
                    end = line.find('</b>')
                    curcomment.header = line[begin : end]
                # Parse helpfulness
                elif helpful_line in data[i]:
                    helpful_found = data[i].replace(",", "")
                    helpful_found = re.search(helpful, helpful_found)
                    if helpful_found != None:
                        curcomment.helpful = helpful_found.group()
                # Parse body text
                elif reviewText in data[i]:
                    i += 3
                    if '<span class="small"' in data[i]: # Yep, dirty trick :(
                        i += 3
                    data[i] = stripHtmlTags(data[i])
                    curcomment.comment = re.sub("\s+", " ", data[i])
                i += 1
            #comments.append(curcomment.getonelinecomment())
            comments.append(curcomment.__repr__())
Exemple #40
0
def runtests():
    r = str(randrange(1,999999))
    #r = str(123)
    username = "******" + r
    email = "t2fhvhd" + r + "@penstro.com"
    target = "Target" + r
    targetEmail = "t2fhvh" + r + "@penstro.com"
    secondary = "Sec" + r
    secondaryEmail = "t2fhvhc" + r + "@penstro.com"
    secondaryTarget = "sT" + r
    secondaryTargetEmail = "t2fhvcc" + r + "@penstro.com"
    lockedTarget1 = "l1t" + r
    lockedTarget1Email = "lt1c" + r + "@penstro.com"
    lockedTarget2 = "l2t" + r
    lockedTarget2Email = "lt2c" + r + "@penstro.com"
    paymentId1="*****@*****.**"
    paymentId2="*****@*****.**"
    paymentId3="*****@*****.**"
    
    notifications = {'backing':{},
                     'posting':{},
                     'comment':{}}
    
    print("Running all tests")
    print("Username: "******"Target: " + target)
    targetToken, token = Authentication(None, username, email, None, target, targetEmail).runTests()
    secondaryTargetToken, secondaryToken = Authentication(None, secondary, secondaryEmail, 
                                                          None, secondaryTarget, 
                                                          secondaryTargetEmail).runTests()
    lockedTargetToken2, lockedTargetToken1 = Authentication(None, lockedTarget1, lockedTarget1Email, 
                                                          None, lockedTarget2, 
                                                          lockedTarget2Email).runTests()
    
    Role(token, username, email, targetToken, target, targetEmail).runTests(secondaryToken, lockedTargetToken1, lockedTargetToken2, paymentId1, paymentId2, paymentId3)
    
    General(token, username, email, targetToken, target, targetEmail).runTests()
    User(token, username, email, targetToken, target, targetEmail).runTests()
    
    Finance(token, username, email, targetToken, target, targetEmail).runTests()
    Notification(token, username, email, targetToken, target, targetEmail).runTests()
    Message(token, username, email, targetToken, target, targetEmail).runTests()
    
    #backing = Backing(token, username, email, targetToken, target, targetEmail)
    #backing.runTests(notifications)
    posting = Posting(token, username, email, targetToken, target, targetEmail)
    createdPostings = posting.runTests(notifications, secondaryToken, secondary, lockedTargetToken1)
    comment = Comment(token, username, email, targetToken, target, targetEmail)
    comment.runTests(notifications, secondaryToken, secondary, createdPostings, lockedTargetToken2)
    Follow(token, username, email, targetToken, target, targetEmail).runTests(secondaryToken, secondary)
    Settings(token, username, email, targetToken, target, targetEmail).runTests()
    
    time.sleep(CacheTimes.PAGED)
    
    print('Testing notifications')
    #backing.testNotifications()
    posting.testNotifications()
    comment.testNotifications()
    
    print('Testing posting and comment pageables')
    #it now takes so long to get to the pageables, due to individual tests requiring wait time for caching, this test is no longer valid
    #posting.testPostingsPaged()
    #comment.testCommentsPaged()
    Admin(token, username, email, targetToken, target, targetEmail).runTests(secondaryToken, secondary, secondaryTargetToken, secondaryTarget)
    
    #Delete(token, username, email, targetToken, target, targetEmail).runTests(secondaryToken, secondaryTargetToken)
    
    print("Finished running all tests")
    if hasattr(PyRequest, "ERROR_COUNT"):
        if PyRequest.ERROR_COUNT > 0:
            print("Error count: " + str(PyRequest.ERROR_COUNT))
        else: 
            print("No errors!")
    else:
        print("No errors!")
Exemple #41
0
def request_comments():
	#request comments
	fp = open("res.txt", "a")
	xw = ExcelWriter("res.xls")
	xw.add_sheet("test")
	# write head
	write_head(xw)

	polled_num = 0
	current_page = 1
	comment_count = 1
	while(True):
		print "get %s" % current_page
		content =  client.comments.timeline.get(page=current_page)
		total_number = content.total_number
		recv_num = len(content.comments)
		if recv_num == 0:
			print "recv_num = 0"
			break
		
		for comment in content.comments:
			commentRecord = Comment()
			if(comment.has_key("reply_comment")):
				commentRecord.is_reply = True
				commentRecord.reply_comment_id = comment.reply_comment.id
				commentRecord.reply_comment_text = comment.reply_comment.text
				commentRecord.reply_comment_created_time = comment.reply_comment.created_at
				commentRecord.reply_comment_user_id = comment.reply_comment.user.id
				commentRecord.reply_comment_user_name = comment.reply_comment.user.name
			commentRecord.comment_id = comment.id
			commentRecord.comment_text = comment.text
			commentRecord.comment_created_time = comment.created_at
			commentRecord.comment_user_id = comment.user.id
			commentRecord.comment_user_name = comment.user.name

			commentRecord.weibo_id = comment.status.id
			commentRecord.weibo_text = comment.status.text
			commentRecord.weibo_user_id = comment.status.user.id
			commentRecord.weibo_user_name = comment.status.user.name

			fp.writelines(commentRecord.vars_to_str()+'\n')
			# print commentRecord.is_reply, comment_count
			if commentRecord.is_reply == True:
				write_comment_xls(commentRecord, raw=comment_count, xw=xw)
				comment_count += 1

		polled_num += recv_num
		print total_number, polled_num, current_page
		if(polled_num < total_number):
			current_page += 1
		else:
			break
	xw.save()
	fp.close()