示例#1
0
def book_page(book_id):
    searchform = SearchForm()
    db = current_app.config["db"]
    book, author_id = db.get_book(book_id)
    reviews, users = db.get_reviews(book_id)
    if book is None:
        abort(404)
    form = ReviewForm()
    if form.validate_on_submit():
        score = form.data["score"]
        comment = form.data["comment"]
        author = db.get_user_id(current_user.username)
        review = Review(author=author,
                        book=book_id,
                        score=score,
                        comment=comment)
        review_id = db.add_review(review)
        review.id = review_id
        return redirect(url_for("book_page", book_id=book_id))
    return render_template("book.html",
                           book=book,
                           author_id=author_id,
                           form=form,
                           reviews=reviews,
                           users=users,
                           searchform=searchform)
示例#2
0
def test_review():
    txt = "I don't love her any more"
    r = Review('abc',txt)
    d = r.to_dict()

    cpyr = Review.from_dict(d)
    print cpyr.to_dict()
示例#3
0
    def get_data_from_file(self):
        ngram_count = {}
        ngrams_list = []
        reviews = []
        x_train_dataset = []
        y_train_dataset = []
        threshold = 128

        train = random.sample(self.files, 10000)
        #train = self.files

        for path in train:
            if ('train' not in path[0]):
                continue

            with open(path[0] + '/' + path[1]) as reader:
                review = reader.read()
                review = Review(review, path)
                if (self.n > 1):
                    ngrams = review.generate_ngrams(n=2)
                else:
                    ngrams = review.review

                reviews.append(review)

                for elem in ngrams:
                    if (elem not in ngram_count):
                        ngram_count[elem] = 0
                    ngram_count[elem] += 1

        x_train_dataset, y_train_dataset, input_size = self.make_bag_of_words(
            ngram_count, reviews, threshold)

        return x_train_dataset, y_train_dataset, reviews, input_size
示例#4
0
def review(user_msg):
    """
	This function analyzes the users review of a cafe and returns a response
	about the sentiment of the review.

	:param user_msg: string
	:return: str
	"""

    # initiate review object
    rvw = Review(user_msg)

    # determine if review is positive or negative
    predicted_sentiment = rvw.predict_sentiment()

    # store review
    rvw.store_review()

    # if positive, respond to positive experience
    if predicted_sentiment == 1:
        response_msg = "Based on your review, it seems that you had a good time. Great! For another recommendation, please write: recommend me"

    # otherwise it was negative, respond to negative experience
    else:
        response_msg = "Based on your review, it seems that you did not have a good time. I'm sorry! For another recommendation, please write: recommend me"
    return response_msg
示例#5
0
def test_review():
    txt = "I don't love her any more"
    r = Review('abc', txt)
    d = r.to_dict()

    cpyr = Review.from_dict(d)
    print cpyr.to_dict()
    def get_book_reviews(book_link):
        """Given a url representing a book, return the reviews for that book.
		The reviews are stored in a dictionary. Each review has an id as the key,
		and a dictionary as the value. The value stores the date and the contents
		of the review, as strings.
		"""
        page = requests.get(book_link)
        soup = BeautifulSoup(page.content, 'html.parser')

        reviews = {}

        dates = soup.find_all("a", {"class": "reviewDate createdAt right"},
                              href=True)
        contents = soup.find_all("div", {"class": "reviewText stacked"})

        analyser = SentimentIntensityAnalyzer()

        for id in range(len(contents)):

            score = analyser.polarity_scores(contents[id].get_text().strip())
            key = str(id)
            review = Review(date=dates[id].get_text().strip(),
                            content=contents[id].get_text().strip(),
                            score=score)
            reviews[key] = review.create_dictionary()
            print(contents[id].get_text().strip())

        return reviews
示例#7
0
文件: recipepage.py 项目: gench/rec2
    def getReviews(self):
        reviews_array = []
        i = 1

        hdr = {'User-Agent': 'super happy flair bot by /u/spladug'}
        url = self.REVIEWS_ENDPOINT + self.id + '&pagenumber=' + str(
            i) + '&pagesize=50&recipeType=Recipe&sortBy=MostHelpful'
        req = urllib2.Request(url, headers=hdr)
        data = urllib2.urlopen(req).read()

        lxml_data = lxml.html.fromstring(data)
        reviews = lxml_data.xpath(self.REVIEWS_TAG)
        while len(reviews) != 0:
            for review in reviews:
                r = Review()
                r.parseReview(review, self.id)
                reviews_array.append(r)
            i += 1
            try:
                time.sleep(random.random() + 1)
                data = urllib2.urlopen(
                    self.REVIEWS_ENDPOINT + self.id + '&pagenumber=' + str(i) +
                    '&pagesize=50&recipeType=Recipe&sortBy=MostHelpful').read(
                    )
                lxml_data = lxml.html.fromstring(data)
                reviews = lxml_data.xpath(self.REVIEWS_TAG)
            except:
                # Assume if we cannot get the next page of the reviews, then there are no more reviews
                reviews = {}
        return reviews_array
示例#8
0
    def post(self, product_id, member_id):
        json_string = self.request.body
        review_props = review_properties(json_string)
        new_review = Review(product_id=product_id,
                            member_id=member_id,
                            time=review_props["time"],
                            rating=review_props["rating"],
                            summary=review_props["summary"],
                            text=review_props["text"])

        new_review.put()

        json_response_dict = new_review.to_dict()

        # This dictionary is not quite ready to serialize into JSON because JSON has no native datetime type.
        # It is common in JSON to use an ISO 8601 datetime string with Z (representing GMT/UT) as the timezone.
        # Such a datetime looks like: "2016-10-04T18:55:11Z". Therefore we make that substitution (including the
        # trailing "Z" which is not optional, but the library leaves it off because conventionally python does
        # not distinguish between offsetless datetimes and UTC datetimes (a datetime with an offset that is 0).
        json_response_dict["time"] = json_response_dict["time"].isoformat(
        ) + "Z"
        # Now we can dump into valid json.
        json_response_string = json.dumps(json_response_dict)
        # Set the response type and write the json.
        self.response.headers["Content-Type"] = "application/json"
        self.response.write(json_response_string)
示例#9
0
    def callback(ch, method, properties, body):
        """
        This function will be triggered when an element enter the  
        pastebin_parser queue. Review object will be create in
        order to parse the content of a text file stored
        at "tmp/pastebin/<filename>".
        """

        body = body.decode('utf-8')
        msg = f"Data {body} received from queue {lc.PARSER_QUEUE}"
        if gc.DEBUG:
            log_info('pastebin', msg)
        path = f"{lc.TEMP_STORAGE}/{body}"

        try:
            with open(path, 'r') as f:
                data = f.read()
        except Exception as e:
            msg = f"callback() failed, for file {body}: {e}"
            log_info('pastebin', msg)
            return

        delimiter = data.find('\n')
        metadata = data[0:delimiter]
        data = data[delimiter + 1::]

        review = Review(metadata, data)
        review.search(path, body)
        ch.basic_ack(delivery_tag=method.delivery_tag)
示例#10
0
def get_reviews(hotel_file):
    hotel = TaHotel(hotel_file)

    for index,tareview in enumerate( hotel.reviews):
        review = Review()
        review.business_id = hotel.id
        review.ratings = tareview.ratings
        review.assign_content(tareview.entire_content(),StopWords)
        yield review
示例#11
0
def read_review_data(filename):
    review_list = []
    with open(filename) as json_file:
        data = json.load(json_file)
        for obj in data['reviews']:
            review = Review()
            review.rating = obj['rating']
            review.date = obj['date']
            review.text = obj['review_text']
            review_list.append(review)
    return review_list
def new_review():
    if request.method == 'GET':
        return render_template('new_review.html')
    elif request.method == 'POST':
        form = request.form
        au = form['author']
        s = form['song']
        ar = form['artist']
        c = form['content']
        print(au, s, ar, c)

        new_review = Review(author=au, song=s, artist=ar, content=c)
        new_review.save()

        return redirect(url_for('reviews'))
示例#13
0
    def run(self):
        for index,fname in enumerate(self.allfiles):
            hotel = TaHotel(fname)

            reviews = []
            for tareview in hotel.reviews:
                review = Review()
                review.business_id = hotel.id
                review.ratings = tareview.ratings
                review.assign_comment(tareview.entire_content(),self.stopwords)
                reviews.append(review)

            if len(reviews)>0:
                self.queue.put(reviews)
                print "[PARSER]: {}-th file<{}> parsed, {} reviews enqueued".format(index+1,fname,len(reviews))
示例#14
0
def test_user():
    user1 = User('Martin', 'pw12345')
    user4 = User('Martin', 'pw12345')
    user2 = User('Ian', 'pw67890')
    user3 = User('Daniel', 'pw87465')

    movie = Movie("Moana", 2009)
    review_text = "It was so average"
    rating = 10
    review = Review(movie, review_text, rating)
    print(movie)
    movie.runtime_minutes = 107

    movie3 = Movie("", 4545)
    print(movie3)

    movie2 = Movie("Inception", 2010)
    movie2.runtime_minutes = 133
    user1.watch_movie(movie)
    user1.watch_movie(movie2)
    user1.watch_movie(movie)
    user2.add_review(review)
    print(user1)
    print(user4)
    print(user2)
    print(user3)
    print(user1 == user4)
    print(user1 > user2)
    print(user1.time_spent_watching_movies_minutes)
    print(user2.reviews)
    print(user1.watched_movies)
    def get(self, id=None):
        self.response.headers["Content-Type"] = "text/html"
        url = ""
        user = users.get_current_user()
        review_form_url = '/electric_vehicles/review/'
        if user:
            url = users.create_logout_url(self.request.uri)
            url_string = "logout"
        else:
            url = users.create_login_url(self.request.uri)
            url_string = "login"

        if id:
            electric_vehicle = ElectricVehicle.get_by_id(int(id))
            reviews = Review.query(Review.electric_vehicle == electric_vehicle.
                                   key).order(-Review.date).fetch()
            for_score = [rev.score for rev in reviews]
            avg_review = 0
            if len(for_score):
                avg_review = sum(for_score) / len(for_score)

        template_values = {
            "avg_review": avg_review,
            "reviews": reviews,
            "review_form_url": review_form_url,
            "electric_vehicle": electric_vehicle,
            "url": url,
            "url_string": url_string,
            "user": user
        }
        template = JINJA_ENVIRONMENT.get_template(
            "electric_vehicles/show.html")
        self.response.write(template.render(template_values))
示例#16
0
def readReviews(reviewIDs, folder, ironic):
    """Returns a dictionary containing reviews to the given IDs."""
    return {
        reviewID: Review(filename="{0}{1}.txt".format(folder, reviewID),
                         ironic=ironic)
        for reviewID in reviewIDs
    }
示例#17
0
 def getReviews(self):
     reviews_array = []
     i = 1
     data = urllib2.urlopen(self.REVIEWS_ENDPOINT + self.id + '&pagenumber=' + str(i) + '&pagesize=50&recipeType=Recipe').read()
     lxml_data = lxml.html.fromstring(data)
     reviews = lxml_data.xpath(self.REVIEWS_TAG)
     while len(reviews) != 0:
         for review in reviews:
             r = Review()
             r.parseReview(review, self.id)
             reviews_array.append(r)
         i += 1
         data = urllib2.urlopen(self.REVIEWS_ENDPOINT + self.id + '&pagenumber=' + str(i) + '&pagesize=50&recipeType=Recipe').read()
         lxml_data = lxml.html.fromstring(data)
         reviews = lxml_data.xpath(self.REVIEWS_TAG)
     return reviews_array
示例#18
0
def crawl(url):
    data = urllib.request.urlopen(url).read()
    review_list = []
    soup = bs(data, 'html.parser')

    soup.select('h3>a')[0].text
    title = soup.find('h3', class_='h_movie').find('a').text
    div = soup.find('div', class_='score_result')
    data_list = div.select('ul > li')

    for review in data_list:
        star = review.find('div', class_='star_score').text.strip()
        reply = review.find('div', class_='score_reple')
        comment = reply.find('p').text

        date = reply.select('dt>em')[1].text.strip()

        button = review.find('div', class_='btn_area')

        sympathy = button.select('strong')

        good = sympathy[0].text
        bad = sympathy[1].text
        review_list.append(Review(comment, date, star, good, bad))

    return title, review_list
示例#19
0
def review_edit_page(review_id):
    searchform = SearchForm()
    db = current_app.config["db"]
    review = db.get_review(review_id)
    if review is None:
        abort(404)
    if not current_user.id == review.author:
        abort(401)
    form = ReviewForm()
    if form.validate_on_submit():
        score = form.data["score"]
        comment = form.data["comment"]
        author = review.author
        book_id = review.book
        review_id = review.id
        review_ = Review(score=score,
                         comment=comment,
                         author=author,
                         book=book_id,
                         id=review_id)
        db.update_review(review_)
        flash("Review updated successfully.")
        return redirect(url_for("book_page", book_id=book_id))
    form.score.data = str(review.score)
    form.comment.data = review.comment
    return render_template("review_edit.html",
                           form=form,
                           searchform=searchform)
示例#20
0
 def add_review(self, item, text, rating):
     new_review = Review(self, item, text, rating)
     self.reviews.append(new_review)
     logger.info(
         f"{self.first_name} {self.last_name}'s review for '{item.title}' was added."
     )
     return new_review
示例#21
0
 def create_review(self, item, rate):
     new_review = Review(self, item, rate)
     self.reviews.append(new_review)
     logger.info(
         f"New review by {new_review}, is created by the customer: {self.id}"
     )
     return new_review
示例#22
0
def read_data(path):
    reviews_list = [];
    f1 = open(path, 'r');
    lines1 = f1.readlines();
    for i in range(len(lines1)):
        reviews_list += [Review(lines1[i].strip(),"")]
    return reviews_list;
示例#23
0
    async def handle_dm(self, message):
        # Translate unicode
        message.content = uni2ascii(message.content)

        # Handle a help message
        if message.content == Report.HELP_KEYWORD:
            reply =  "Use the `report` command to begin the reporting process.\n"
            reply += "Use the `cancel` command to cancel the report process.\n"
            await message.channel.send(reply)
            return

        author_id = message.author.id
        responses = []

        # Let the report class handle this message; forward all the messages it returns to us
        if author_id not in globals.CURRENT_REVIEWERS_DB:
        # Only respond to messages if they're part of a reporting flow
            if author_id not in self.reports and not message.content.startswith(Report.START_KEYWORD):
                return

            # If we don't currently have an active report for this user, add one
            if author_id not in self.reports:
                self.reports[author_id] = Report(self)
        
            responses, report = await self.reports[author_id].handle_message(message)
            for r in responses:
                await message.channel.send(r)

            # If the report is complete or cancelled, remove it from our map
            if self.reports[author_id].report_complete():
                if report is not None and report.reporting_user not in globals.BAD_REPORT_TRACKER:
                    globals.BAD_REPORT_TRACKER[report.reporting_user] = 1
                self.reports.pop(author_id)
                if report is not None and globals.BAD_REPORT_TRACKER[report.reporting_user] <= globals.BAD_REPORT_THRESHOLD:
                    globals.TICKET_NUM += 1
                    globals.REPORTS_DATABASE[globals.TICKET_NUM] = report
                    await self.handle_report(globals.TICKET_NUM)
        else: # This is a review from a moderator
            # If we don't currently have an active report for this user, add one
            if author_id not in self.reviews and message.content != "s":
                return

            if author_id not in self.reviews:
                self.reviews[author_id] = Review(self)
            
            case_id = globals.CURRENT_REVIEWERS_DB[author_id]
            report = globals.REPORTS_DATABASE[(int)(case_id)]

            responses = await self.reviews[author_id].review_report(message, report, case_id, author_id)
            for r in responses:
                await message.channel.send(r) 

            # If the review is complete or cancelled, remove it from our map
            if self.reviews[author_id].review_complete():
                self.reviews.pop(author_id)
                del globals.CURRENT_REVIEWERS_DB[author_id]
                # Set number of reviewers in globals file
                if (len(globals.REVIEWS_DATABASE[case_id]) >= globals.NUM_REVIEWERS):
                    await self.handle_review(case_id)
示例#24
0
 def reviews(self):
     recipes = self.recipes()
     reviews = []
     for recipe in recipes:
         for review in Review.all():
             if recipe == review.recipe:
                 reviews.append(review)
     return reviews
 def reviews(self):
     recipe_list = self.recipes()
     review_list = []
     for item in recipe_list:
         review_list += [
             review for review in Review.all() if review.recipe == item
         ]
     return review_list
 def test_review_class_methods(self):
     self.assertItemsEqual(Review._all, [
         review_1, review_2, review_3, review_4, review_5, review_6,
         review_7, review_8, review_9, review_10
     ])
     self.assertItemsEqual(Review.all(), [
         review_1, review_2, review_3, review_4, review_5, review_6,
         review_7, review_8, review_9, review_10
     ])
示例#27
0
def sentence_stream(colname):
    client = pymongo.MongoClient()
    collection = client.popcorn[colname]

    cursor = collection.find({}, {'words':0 })
    for d in cursor:
        yield Review.from_dict(d)

    client.close()
示例#28
0
 def insert_review(self, rating, product_id, customer_email):
     try:
         review = Review(rating, product_id, customer_email)
         self.session.add(review)
         self.session.commit()
         if id is not None or id != 0:
             return [True, review]
     except SQLAlchemyError as e:
         return [False, e]
示例#29
0
    def LogisticTest(self, words, parser):

        x_test = []
        for word in words:
            review = Review(word)
            x_test.append(parser.bag_of_one_word(review, self.n))

        print(self.nb.predict(x_test))
        print(self.nb.predict_proba(x_test))
示例#30
0
def sentence_stream(colname):
    client = pymongo.MongoClient()
    collection = client.popcorn[colname]

    cursor = collection.find({}, {'words': 0})
    for d in cursor:
        yield Review.from_dict(d)

    client.close()
示例#31
0
 def load(self, directory, label):
     reviews = []
     for root, subFolders, files in os.walk(directory):
         for file in files:
             with open(os.path.join(root, file), 'r') as fin:
                 for lines in fin:
                     reviews.append(
                         Review(lines, label, os.path.join(root, file)))
     return reviews
示例#32
0
 def get(self, member_id):
     q = Review.query().filter(Review.member_id == member_id)
     count = q.count()
     to_fetch = count if count < 10 else 10
     reviews = q.fetch(to_fetch)
     print("Found " + str(count) + " reviews for member " + member_id +
           ", returning " + str(to_fetch))
     self.response.headers["Content-Type"] = "application/json"
     write_reviews(reviews, self.response)
示例#33
0
def init_data(textfile, lablesfile):
    reviews_list = []
    f1 = open(textfile, 'r')
    f2 = open(lablesfile, 'r')
    lines1 = f1.readlines()
    lines2 = f2.readlines()
    for i in range(len(lines1)):
        reviews_list += [Review(lines1[i].strip(), lines2[i].strip())]
    return reviews_list
示例#34
0
 def bottom_three(cls):
     recipe_dict = {}
     for item in Review.all():
         recipe_dict[item.recipe] = item.recipe.avg_rating()
     sorted_recipe_dict = dict(
         sorted(recipe_dict.items(), key=lambda item: item[1]))
     final_list = []
     for i in range(0, 3):
         final_list.append(list(sorted_recipe_dict.keys())[i])
     return final_list
 def favorite_recipe(self):
     recipe_list = {
         review.recipe: review.rating
         for review in Review.all() if review.reviewer == self
     }
     favorite = max(recipe_list.values())
     return [
         review for review, rating in recipe_list.items()
         if rating == favorite
     ][0]
示例#36
0
 def getReviews(self):
     reviews_array = []
     i = 1
     data = urllib2.urlopen(self.REVIEWS_ENDPOINT + self.id + '&pagenumber=' + str(i) + '&pagesize=50&recipeType=Recipe&sortBy=MostHelpful').read()
     lxml_data = lxml.html.fromstring(data)
     reviews = lxml_data.xpath(self.REVIEWS_TAG)
     while len(reviews) != 0:
         for review in reviews:
             r = Review()
             r.parseReview(review, self.id)
             reviews_array.append(r)
         i += 1
         try:
             data = urllib2.urlopen(self.REVIEWS_ENDPOINT + self.id + '&pagenumber=' + str(i) + '&pagesize=50&recipeType=Recipe&sortBy=MostHelpful').read()
             lxml_data = lxml.html.fromstring(data)
             reviews = lxml_data.xpath(self.REVIEWS_TAG)
         except:
             # Assume if we cannot get the next page of the reviews, then there are no more reviews
             reviews = {}
     return reviews_array
示例#37
0
def get_all_known_aspect_sentences(dbname):
    client = MongoClient()
    review_collection = client[dbname]["reviews"]

    query_condition = {"sentences": {'$elemMatch': {'aspect': {'$ne':'Unknown'}}   }   }
    cursor = review_collection.find(query_condition,{"sentences":1})
    for d in cursor:
        review = Review.from_dict(d)
        for sentence in review.sentences:
            if sentence.aspect != "Unknown":
                yield sentence

    client.close()
示例#38
0
def test_load_review_words():
    client = MongoClient()
    collection = client['airbnb']['reviews']
    cursor = collection.find({})

    for index in xrange(10):
        d = next(cursor)
        review = Review.from_dict(d)
        print "*************** {} ***************".format(index+1)
        print "raw: {}".format(review.sent.raw)
        print "words: {}".format(review.sent.words)

    client.close()
def load_reviews_save_sentiment_sentences(dbname,classifier):
    client = MongoClient()
    db = client[dbname]
    reviews_collection = db["reviews"]
    sentisent_collection = db["sentiment_sentences"]

    review_cursor = reviews_collection.find({})
    for index,rd in enumerate(review_cursor):
        review = Review.from_dict(rd)

        sentence_dicts  = [ s.to_dict() for s in review_to_sentences(review,classifier) ]
        if len(sentence_dicts)>0:
            sentisent_collection.insert_many(sentence_dicts)

        print "{}-th review extract {} sentences and saved".format(index+1,len(sentence_dicts))

    client.close()
示例#40
0
def update_add_neg_suffix(dbname,query_condition):
    stop_words = common.make_stop_words()
    client = MongoClient()
    review_collection = client[dbname]['reviews']

    cursor = review_collection.find(query_condition,{"sentences.raw":1,"sentences.words":1})
    for rindex,rd in enumerate(cursor):
        review = Review.from_dict(rd)

        update_content = {}
        for sindex,sent in enumerate(review.sentences):
            new_sent = Sentence.from_raw(sent.raw,stop_words)
            if set(new_sent.words) != set(sent.words):
                update_content["sentences.{}.words".format(sindex)] = new_sent.words

        if len(update_content)>0:
            result = review_collection.update_one({"_id":review.id},{"$set":update_content})
            if result.modified_count != 1:
                raise Exception("failed to update review<{}>".format(review.id))

        print "{}-th review updated {} sentences".format(rindex+1,len(update_content))

    client.close()
class QAReviewer(gnomeglade.GnomeApp):
    #
    # Program Initialization
    # 
    def __init__(self, arguments):
        """Creates a new QA reviewer window.
           
        Keyword -- arguments:
        arguments: A commandline to process when setting up the environment
        """

        # Create the properties for this checklist
        ### FIXME: Properties is hard-coded right now.  Needs some love.
        self.properties = Properties('fedoraus.xml')

        # Load the interface
        gladefile = 'glade/qa-assistant.glade'
        gnomeglade.GnomeApp.__init__(self, __programName__, __version__,
                gladefile, 'ReviewerWindow')
        self.program.set_property(gnome.PARAM_HUMAN_READABLE_NAME, __programHumanName__)
        
        #
        # Create additional interface components
        #

        iconFile = self._GnomeApp__uninstalled_file('pixmaps/qa-icon.png')
        if iconFile == None:
            iconFile = self.locate_file(gnome.FILE_DOMAIN_APP_PIXMAP,
                                        'qa-icon.png')
            if iconFile == []:
                iconFile = None
            else:
                iconFile = iconFile[0]
        if iconFile:
            self.ReviewerWindow.set_property('icon', gnomeglade.load_pixbuf(iconFile))

        # Create a treeview for our listPane
        self.checkView = gtk.TreeView()
        self.checkView.set_rules_hint(True)
        
        # load the checklist data (Associates itself with checkView)
        self.__load_checklist()

        renderer = gtk.CellRendererToggle()
        renderer.set_radio(False)
        column = gtk.TreeViewColumn('Display', renderer,
                                    active=checklist.DISPLAY,
                                    visible=checklist.ISITEM)
        renderer.connect('toggled', self.display_toggle)
        self.checkView.append_column(column)

        renderer = OptionCellRenderer()
        column = gtk.TreeViewColumn('pass/fail', renderer,
                                    optionlist=checklist.RESLIST,
                                    selectedoption=checklist.RESOLUTION,
                                    mode=checklist.ISITEM)
        column.set_cell_data_func(renderer, self.__translate_option_mode)
        renderer.connect('changed', self.resolution_changed)
        self.checkView.append_column(column)
       
        renderer = gtk.CellRendererText()
        column = gtk.TreeViewColumn('Description', renderer,
                                    text=checklist.SUMMARY)
        self.checkView.append_column(column)
        
        renderer = gtk.CellRendererText()
        renderer.connect('edited', self.output_edited, self.checklist.tree)
        column = gtk.TreeViewColumn('Output', renderer,
                                    markup=checklist.OUTPUT,
                                    visible=checklist.DISPLAY,
                                    editable=checklist.DISPLAY)
        self.outputColumn = column
        self.checkView.append_column(column)

        self.tips = TreeTips(self.checkView, checklist.DESC)

        self.listPane.add(self.checkView)
        self.checkView.show()

        self.grabArrow=gtk.Arrow(gtk.ARROW_LEFT, gtk.SHADOW_NONE)
        self.grabArrow.set_size_request(4,4)
        label=self.grabBar.get_child()
        self.grabBar.remove(label)
        self.grabBar.add(self.grabArrow)
        self.grabArrow.show()

        self.reviewView = Review(self.checklist.tree, self.properties)
        self.reviewView.show()
        self.reviewPane.add(self.reviewView)
        self.reviewScroll.hide()

        #
        # Command line initialization
        #
        ### FIXME: take care of the command line args

        ### FIXME: Absolute dependence on arguments[1] being an SRPM without a
        # check to make sure of it.  Need to fix that up with cmd-line args.
        if len(arguments) == 2:
            self.SRPM_into_properties(arguments[1])

        #
        # Blast off!
        #
        self.__check_readiness()
        self.ReviewerWindow.show()

    #
    # Helper Functions
    # 

    def __load_checklist(self):
        ### FIXME: When calling this function to load a new checklist, we
        # need to be careful.  There was a bug where loading a new checklist
        # was causing editing of cells to no longer work.  I think we have
        # to reload our checklistPane everytime we load a new checklist....
        # -- Some restructuring of code to do there.
        # -- May only need to make sure self.checklist.tree is set correctly?
        filename = os.path.join('data', self.properties.checklistName)
        checkFile = self._GnomeApp__uninstalled_file(filename)
        if checkFile == None:
            filename = os.path.join(__programName__, filename)
            checkFile = self.locate_file(gnome.FILE_DOMAIN_APP_DATADIR,
                    filename)
            if checkFile == []:
                checkFile = None
            else:
                checkFile = checkFile[0]
        if checkFile == None:
            ### FIXME: When we can select checklists via property, we need to
            # print error and recover.
            sys.stderr.write("Unable to find checklist: %s\n" % (filename))
            sys.exit(1)
        try:
            self.checklist = checklist.CheckList(checkFile, self.properties)
        except (libxml2.parserError, libxml2.treeError, checklist.Error), msg:
            ### FIXME: When we can select checklists via property, we need to
            # print error and recover.
            sys.stderr.write("Unable to parse the checklist: %s\n" % (msg))
            sys.exit(1)

        self.checkView.set_model(self.checklist.tree)

        if self.checklist.type == 'SRPM':
            from srpmqa import SRPMQA
            qamenu = SRPMQA(self)
        else:
            from genericqa import GenericQA
            qamenu = GenericQA(self)
        self.QAMenuItem.set_submenu(qamenu)
        qamenu.show_all()
示例#42
0
                    break;
            
        for hotel in soup.findAll('a',{'class': 'property_title'}):
            hotel_name = hotel.string[1:]
            url_path = base_url + hotel['href']
            ##Initialize
            fetch = FetchInfo(url_path)
            ##fetch thumb_up rank and total_reviews
            thumb_up = fetch.fetch_thumb_up() #thumb up
            rank =  fetch.fetch_rank()  #rank
            total_reviews = fetch.fetch_total_reviews()   #total_reviews
            address = fetch.fetch_address()
    
            ##construct Review object       
            ##txt_title = """%s, %s, %s, %s """ %(hotel_name, thumb_up.string, rank.string, str(total_reviews) + " Reviews") # txt_title  
            rev  = Review(hotel_name,address,thumb_up,rank[8:]) #Review Object

            ##fill all review properties in the reviewers
            i = 0
            while i <= 4:
    
                fetch.fetch_review_properties(rev,total = total_reviews, index = i)
                i = i + 1       
            rev.write_into_file()
            count = count + 1
            print "No. " + str(count) + " finish " + rev.hotel_name + "!"
        page = page + 1
    
except Exception, e:
    print sys.exc_traceback.tb_lineno 
    print e
示例#43
0
 def find_review_summary(cls):
     from review import Review
     return Review.stats_query().join(cls).add_entity(cls).group_by(cls)
class QAReviewer(gnomeglade.GnomeApp):
    #
    # Program Initialization
    # 
    def __init__(self, arguments):
        """Creates a new QA reviewer window.
           
        Keyword -- arguments:
        arguments: A commandline to process when setting up the environment
        """

        # Create the properties for this checklist
        ### FIXME: Properties is hard-coded right now.  Needs some love.
        self.properties = Properties('fedoraus.xml')

        # Load the interface
        gladefile = 'glade/qa-assistant.glade'
        gnomeglade.GnomeApp.__init__(self, __name__, __version__, gladefile,
                'ReviewerWindow')

        #
        # Create additional interface components
        #

        # Create a treeview for our listPane
        self.checkView = gtk.TreeView()
        self.checkView.set_rules_hint(True)
        
        # load the checklist data (Associates itself with checkView)
        self.__load_checklist()

        renderer = gtk.CellRendererToggle()
        renderer.set_radio(False)
        column = gtk.TreeViewColumn('Display', renderer,
                                    active=checklist.DISPLAY,
                                    visible=checklist.ISITEM)
        renderer.connect('toggled', self.display_toggle)
        self.checkView.append_column(column)

        renderer = OptionCellRenderer()
        column = gtk.TreeViewColumn('pass/fail', renderer,
                                    optionlist=checklist.RESLIST,
                                    selectedoption=checklist.RESOLUTION,
                                    mode=checklist.ISITEM)
        column.set_cell_data_func(renderer, self.__translate_option_mode)
        renderer.connect('changed', self.resolution_changed)
        self.checkView.append_column(column)
       
        renderer = gtk.CellRendererText()
        column = gtk.TreeViewColumn('Description', renderer,
                                    text=checklist.SUMMARY)
        self.checkView.append_column(column)
        
        renderer = gtk.CellRendererText()
        renderer.connect('edited', self.output_edited, self.checklist.tree)
        column = gtk.TreeViewColumn('Output', renderer,
                                    text=checklist.OUTPUT,
                                    visible=checklist.DISPLAY,
                                    editable=checklist.DISPLAY)
        self.outputColumn = column
        self.checkView.append_column(column)

        self.tips = TreeTips(self.checkView, checklist.DESC)

        self.listPane.add(self.checkView)
        self.checkView.show()

        self.grabArrow=gtk.Arrow(gtk.ARROW_LEFT, gtk.SHADOW_NONE)
        self.grabArrow.set_size_request(4,4)
        label=self.grabBar.get_child()
        self.grabBar.remove(label)
        self.grabBar.add(self.grabArrow)
        self.grabArrow.show()

        self.reviewView = Review(self.checklist.tree, self.properties)
        self.reviewView.show()
        self.reviewPane.add(self.reviewView)
        self.reviewScroll.hide()

        #
        # Command line initialization
        #
        ### FIXME: take care of the command line args

        ### FIXME: Absolute dependence on arguments[1] being an SRPM without a
        # check to make sure of it.  Need to fix that up with cmd-line args.
        if len(arguments) == 2:
            self.__SRPM_into_properties(arguments[1])

        #
        # Blast off!
        #
        self.__check_readiness()
        self.ReviewerWindow.show()

    #
    # Helper Functions
    # 
    def __load_checklist(self):
        try:
            self.checklist = checklist.CheckList('data/'+self.properties.checklistName)
        except (libxml2.parserError, libxml2.treeError, checklist.Error), msg:
            ### FIXME: When we can select checklists via property, we need to
            # print error and recover.
            sys.stderr.write("Unable to parse the checklist: %s\n" % (msg))
            sys.exit(1)

        self.checkView.set_model(self.checklist.tree)
for cur in range(start, end):
    print 'page: ' + str(cur)
    data_dir = 'data/' + str(cur) + '/'
    paths = os.listdir(data_dir)

    paths = [relpath for relpath in paths if \
        relpath.find('index.html') == -1 and \
        relpath != "urls" and relpath.find('.arff') == -1]

    for relpath in paths:
        path = data_dir + relpath
        print path
        soup = BeautifulSoup(open(path))
        try:
            meta = soup.find('ul', {"class":"review-meta"})
            rev = Review()
            rev.id = int(re.search('\d+', relpath).group(0))
            rev.artist = meta.find('h1').find('a').get_text()
            rev.album = meta.find('h2').get_text()
            str_date = meta.find('span', {"class":"pub-date"}).get_text()
            rev.date = datetime.strptime(str_date, '%B %d, %Y')
            rev.score = float(meta.find('span', {"class":"score"}).get_text())
            rev.text = soup.find('div', {"class":"editorial"}).get_text()

            db.reviews.insert(rev.__dict__)
            count = count + 1
            print count 
            #out.write(rev.arff_row())

            #print str(rev)
        except Exception as e:
    def __init__(self, arguments):
        """Creates a new QA reviewer window.
           
        Keyword -- arguments:
        arguments: A commandline to process when setting up the environment
        """

        # Create the properties for this checklist
        ### FIXME: Properties is hard-coded right now.  Needs some love.
        self.properties = Properties('fedoraus.xml')

        # Load the interface
        gladefile = 'glade/qa-assistant.glade'
        gnomeglade.GnomeApp.__init__(self, __programName__, __version__,
                gladefile, 'ReviewerWindow')
        self.program.set_property(gnome.PARAM_HUMAN_READABLE_NAME, __programHumanName__)
        
        #
        # Create additional interface components
        #

        iconFile = self._GnomeApp__uninstalled_file('pixmaps/qa-icon.png')
        if iconFile == None:
            iconFile = self.locate_file(gnome.FILE_DOMAIN_APP_PIXMAP,
                                        'qa-icon.png')
            if iconFile == []:
                iconFile = None
            else:
                iconFile = iconFile[0]
        if iconFile:
            self.ReviewerWindow.set_property('icon', gnomeglade.load_pixbuf(iconFile))

        # Create a treeview for our listPane
        self.checkView = gtk.TreeView()
        self.checkView.set_rules_hint(True)
        
        # load the checklist data (Associates itself with checkView)
        self.__load_checklist()

        renderer = gtk.CellRendererToggle()
        renderer.set_radio(False)
        column = gtk.TreeViewColumn('Display', renderer,
                                    active=checklist.DISPLAY,
                                    visible=checklist.ISITEM)
        renderer.connect('toggled', self.display_toggle)
        self.checkView.append_column(column)

        renderer = OptionCellRenderer()
        column = gtk.TreeViewColumn('pass/fail', renderer,
                                    optionlist=checklist.RESLIST,
                                    selectedoption=checklist.RESOLUTION,
                                    mode=checklist.ISITEM)
        column.set_cell_data_func(renderer, self.__translate_option_mode)
        renderer.connect('changed', self.resolution_changed)
        self.checkView.append_column(column)
       
        renderer = gtk.CellRendererText()
        column = gtk.TreeViewColumn('Description', renderer,
                                    text=checklist.SUMMARY)
        self.checkView.append_column(column)
        
        renderer = gtk.CellRendererText()
        renderer.connect('edited', self.output_edited, self.checklist.tree)
        column = gtk.TreeViewColumn('Output', renderer,
                                    markup=checklist.OUTPUT,
                                    visible=checklist.DISPLAY,
                                    editable=checklist.DISPLAY)
        self.outputColumn = column
        self.checkView.append_column(column)

        self.tips = TreeTips(self.checkView, checklist.DESC)

        self.listPane.add(self.checkView)
        self.checkView.show()

        self.grabArrow=gtk.Arrow(gtk.ARROW_LEFT, gtk.SHADOW_NONE)
        self.grabArrow.set_size_request(4,4)
        label=self.grabBar.get_child()
        self.grabBar.remove(label)
        self.grabBar.add(self.grabArrow)
        self.grabArrow.show()

        self.reviewView = Review(self.checklist.tree, self.properties)
        self.reviewView.show()
        self.reviewPane.add(self.reviewView)
        self.reviewScroll.hide()

        #
        # Command line initialization
        #
        ### FIXME: take care of the command line args

        ### FIXME: Absolute dependence on arguments[1] being an SRPM without a
        # check to make sure of it.  Need to fix that up with cmd-line args.
        if len(arguments) == 2:
            self.SRPM_into_properties(arguments[1])

        #
        # Blast off!
        #
        self.__check_readiness()
        self.ReviewerWindow.show()