def _merge_file(self, mfilter, filename): contents = self._read_merge_file(mfilter, filename) categories = self._split_categories(filename, contents) for (category, docstr) in categories: parts = category.split('/') qid = self._normalized_qid(parts[0]) key = 'doc' if len(parts) > 1: key = parts[1] if not self.qid_to_node[qid]: self.add_categories([qid]) node = self.category_to_node[qid] else: node = self.qid_to_node[qid] if key == 'doc': node.merge_comment(comment.Comment(docstr, None), override=True) else: sys.stderr.write('Unknown type `{0}\' for id `{1}\'\n'.format( key, parts[0])) sys.exit(1)
def query_gerrit(name, count, project, quiet=False): """Query gerrit and fetch the comments.""" # Include review messages in query search = "reviewer:\"%s\"" % name if project: search = search + (" AND project:\"%s\"" % project) query = ("https://review.openstack.org/changes/?q=%s&" "o=MESSAGES&o=DETAILED_ACCOUNTS" % search) r = requests.get(query) try: changes = json.loads(r.text[4:]) except ValueError: if not quiet: print("query: '%s' failed with:\n%s" % (query, r.text)) return [] comments = [] for change in changes: for date, message in comment.get_comments(change, name): if date is None: # no comments from reviewer yet. This can happen since # 'Uploaded patch set X.' is considered a comment. continue comments.append( comment.Comment(date, change['_number'], change['subject'], message)) return sorted(comments, key=lambda comment: comment.date, reverse=True)[0:count]
def getComments(self): """returns the jobs comments""" response = self.stub.GetComments( job_pb2.JobGetCommentsRequest(job=self.data), timeout=Cuebot.Timeout) commentSeq = response.comments return [comment.Comment(cmt) for cmt in commentSeq.comments]
def getComments(self): """returns the hosts comments""" response = self.stub.GetComments( host_pb2.HostGetCommentsRequest(host=self.data), timeout=Cuebot.Timeout) commentSeq = response.comments return [comment.Comment(c) for c in commentSeq.comments]
def post(self, link): if self.request.get( "action" ) == "newcomment": #para saber si la accion post o el metodo post es para nuevo comentario submitter = self.get_data( 'user_' + self.request.cookies.get('user_id').split('|')[0], self.get_cookie_user(self.request.cookies.get('user_id'))[1] ) #si todo esta bien asigna el valor del objeto logueado como user content = self.request.get("content") comments = self.get_data( link + '_comments', db.GqlQuery("select * from Comment where post='" + link + "' order by created desc") ) #enlista los comentarios que tiene comments = self.display_names( submitter, list(comments)) #camufla los usuarios de los comentarios post = self.get_data("post_" + link, Post.get_by_id(int(link))) #obtiene el post if len(content) < 1: self.redirect('/' + link) else: com = comment.Comment(submitter=submitter.user_id, content=content, post=link, reported=False, title="Comentario #" + str(len(list(comments)) + 1) + " en " + post.title) com.created_str = str(com.created) com.created_str = com.created_str[0:16] com.put() self.delete_data(link + '_comments') post.comments += 1 post.put() self.redirect("/" + link) elif self.request.get( 'action' ) == 'editcomment': #para saber si la accion post o el metodo post es para editar un comentario content = self.request.get("content") if len(content) < 1: self.redirect("/" + link) else: com = comment.Comment.get_by_id(int(self.request.get("c"))) com.content = content com.created_str = str(com.created) com.created_str = com.created_str[0:16] com.put() self.redirect("/" + link) elif self.request.get('action') == 'reportcomment': razon = self.request.get("razon") if len(razon) < 1: self.redirect("/" + link) else: com = comment.Comment.get_by_id(int(self.request.get("c"))) com.razon = com.razon + [razon] com.reported = True com.put() self.redirect("/" + link)
def comments(self): """Gets Comments for a given Issue""" comments = [] json_raw = self._account.request(self.api_url) raw_issue = json_raw['issue'] raw_comments = raw_issue['comments'] for raw_comment in raw_comments: c = comment.Comment(raw_comment) comments.append(c) return comments
def on_notification_changed(self, sel): rect = self.treeview.get_allocation() (origin_x, origin_y) = self.treeview.window.get_origin() candidate_x = int(origin_x + rect.width - 10) candidate_y = int(self.cursor_y - 50) comment_width = comment.STATUS_WIDTH + comment.MAIN_ICON_SIZE if candidate_x > gtk.gdk.screen_width() - comment_width - 100: candidate_x = origin_x - comment_width - 20 tlist, it = sel.get_selected() if it == None: return nid = tlist.get(it, 3)[0] entry = self.office.get_notification_entry(nid) logging.info("herf: " + entry['href']) has_detail = tlist.get(it, 2)[0] logging.debug("nid: %s" % nid) logging.debug("has_detail: %s" % has_detail) if self.comment_handler_id != None: gobject.source_remove(self.comment_handler_id) self.comment_handler_id = None for k in self.comments: if self.comments[k].window.get_property("visible") == True: self.comments[k].window.hide() if has_detail: status = self.office.get_status_with_nid(nid) if status != {}: logging.debug("status: %s" % status['message']) if not self.comments.has_key(status['post_id']): self.comments[status['post_id']] = comment.Comment( status['post_id']) self.comments[status['post_id']].window.set_transient_for( self.window) rect = self.comments[status['post_id']].window.get_allocation() if candidate_y + rect.height > utils.get_min_monitor_height( ) - 30: logging.debug("orig candidate_y: %d" % candidate_y) candidate_y = utils.get_min_monitor_height( ) - rect.height - 30 logging.debug("modify candidate_y: %d" % candidate_y) logging.debug("x, y: (%d, %d)" % (candidate_x, candidate_y)) self.comments[status['post_id']].window.move( candidate_x, candidate_y) self.comment_handler_id = \ gobject.timeout_add (300, self.delay_show_comment, status['post_id'])
def worksight(): if qsight.empty() == True: time.sleep(5) while qsight.empty() != True: url = tools.work(qsight,setsight,mutexOfsight) if url : if url.startswith("http://you.ctrip.com"): pass else: url = 'http://you.ctrip.com' + url html_code = spider.request_html(url) time.sleep(1) if html_code : print(url) hp = htmlparser.MyParser3(url) hp.feed(html_code) print(hp.title, hp.poiID, hp.page) if len(hp.poiID) == 0 or hp.poiID.strip().isnumeric() != True: print("failed") continue comm = comment.Comment(hp) hp.close() hp2 = htmlparser.MyParser2() id=1 try: while comm.data['pagenow']<comm.page: comm.data['pagenow']+=1 if comm.data['pagenow']%100 == 0: time.sleep(2) response=spider.request_ajax_url(resource,body=comm.data,referer=url) hp2.feed(response) for item in hp2.item: comm.text += '<p id='+str(id)+'>'+str(item)+'</p>\n\n' id+=1 hp2.text = '' hp2.item = [] except Exception as e: print(e) comm.text = "<div>\n"+comm.text+"</div>" comm.save() hp2.close()
def post(self): print "Comment API" args = self.reqparse.parse_args() email = args["Email"] content = args["Content"] docid = args["PostID"] try: comObj = comment.Comment(docid) msg = comObj.commentPost(content, email) if (msg == "Comment successfully!"): comList = comObj.commentGet() return {'Comment': comList}, 201 return 450 except: raise sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2] return 450
def read_doc(doc): result = [] # 普通读取 data = open(doc) for d in data: # 读取json文件 s = json.loads(d) id = s[unicode("用户ID")] content = s[unicode("评论内容")] reply = s[unicode("被回复的人")] title = s[unicode("评论标题")] time = s[unicode("评论时间")] stock = s[unicode("股票代码")] com = comment.Comment(id, content, reply, title, time, stock) result.append(com) data.close() return result
def process_moves(self, start=0, parent=None, white_move=True): # Find next string of form : NB. move_to = re.search(r'[0-9]{1,}\.', self.current_text[start:]) black_processed = False # re.search returns None is there are no match if move_to is not None: # Get start of move offset current_id = start + move_to.start() # Start by grabing id and move name current_id, move_id, move_name = self.get_move_id_and_name( current_id) # Check if the currently processed move is not at the end of a variant if self.check_end_of_variant(current_id): nag = [] comment = "" else: # If not check if there is a comment and/or nag current_id, nag, comment = self.get_nag_and_comment(current_id) # Once id name nags and comment is retrieved create move move = hm.HalfMove(move_id, move_name, white_move, parent, [], cmt.Comment(nag, comment), None) # to avoid segfaults children list of parent is updated by children themselves if parent is not None: parent.children.append(move) # Append generated move to global move list self.move_list.append(move) # Keep the color of last proceeded move to know the color of the next one last_process_color = white_move # Check again if after the comment there is the end of a variant if self.check_end_of_variant(current_id): return move_to # Need to declare it here to be used after b_move = None # Recursively process next moves and variants while True: current_id = self.skip_char(current_id) # ( mark the sart of a new variant if self.current_text[current_id] == "(": # Depending on last processed move to compute next move color and parent if black_processed: self.process_moves(current_id, move, last_process_color) else: self.process_moves(current_id, parent, last_process_color) # The variant is processed recursively therefore jump to the next regular half move current_id = self.skip_variant(current_id) # If next move is a digit use last processed color to compute color and parent elif self.current_text[current_id].isdigit(): # New move inverse from the last one # We get here if we have white move, comment, black move # Recursively process next moves if black_processed: self.process_moves(current_id, b_move, not last_process_color) else: self.process_moves(current_id, move, not last_process_color) # If we are here we have finish to process the full move moving to the next one break # Detect if we are at the end of the file elif self.current_text[current_id] == "*" or ( self.current_text[current_id] == "1" and (self.current_text[current_id + 1] == "/" or self.current_text[current_id + 1] == "-")): return move_to # Else the structure is white_move black move with no comment in between else: # Parse regular black move current_id, b_move_name = self.get_move_name(current_id) if self.check_end_of_variant(current_id): b_nag = [] b_comment = "" else: current_id, b_nag, b_comment = self.get_nag_and_comment( current_id) b_move = hm.HalfMove(move_id, b_move_name, False, move, [], cmt.Comment(b_nag, b_comment)) move.children.append(b_move) self.move_list.append(b_move) last_process_color = False black_processed = True if self.check_end_of_variant(current_id): return move_to return move_to
def collect_comments(video_id, user_api_key): c = comment.Comment(video_id, user_api_key) c.build_comment_list() # Strips comments of html tags, tabs, excessive spacing ect. return c.strip_comments()
def get(self, postid): comObj = comment.Comment(postid) comList = comObj.commentGet() return {'Comment': comList}