Ejemplo n.º 1
0
    def on_row_activated(self, tree_view, path, column):
        model = tree_view.get_model()
        iter = model.get_iter(path)
        id = model[iter][0]
        qu = Urls.select(Urls.thumb).where(Urls.set_id == id).limit(4).tuples()
        urls = [q[0] for q in qu]

        popover = tree_view.thumb_view
        rect = tree_view.get_background_area(path, column)
        rect.y = rect.y + 24
        popover.set_pointing_to(rect)

        # pool = Pool(4)

        def get_pix(url):
            req = request.Request(url, headers=firefox)
            response = request.urlopen(req)
            input_stream = Gio.MemoryInputStream.new_from_data(
                response.read(), None)

            def idle(input_stream):
                pixbuf = Pixbuf.new_from_stream(input_stream, None)
                popover.add_image(pixbuf, id)

            GObject.idle_add(idle, input_stream)

        for url in urls:
            t = threading.Thread(target=get_pix, args=(url, ))
            t.start()

        popover.popup()
Ejemplo n.º 2
0
 def append_from_id(self, id, set_iter):
     qu = Urls.select(Urls,
                      Sets).join(Sets).where(Urls.set_id == id).dicts()
     for q in qu:
         # print(q)
         self.que.put((
             q,
             set_iter,
         ))
     info.que_len += self.que.qsize()
Ejemplo n.º 3
0
def get_comments():
    while True:
        try:
            url = Urls.select().where(Urls.status=='new').limit(1).get().url
            # print url
            if not url:
                break
            Urls.update(status='done').where(Urls.url==url).execute()
            hotel_id = url.split('/')[2].split('.')[0]
            comments_driver.get(base_url + url)
            soup = BeautifulSoup(comments_driver.page_source, 'html.parser')
            try:
                name = soup.find(attrs={'itemprop': 'name'}).text.encode('utf-8')
            except Exception, e:
                print "hotel name not found ", e
                name = hotel_id
            Hotel.create(hotel_id=hotel_id, hotel_name=name)
        except Exception, e:
            print "Insert into hotel error ", e
            Urls.update(status='new').where(Urls.url==url).execute()
            continue