コード例 #1
0
    def agregarVolumen(self):
        cnf = Config(self.session)
        cv = ComicVineSearcher(cnf.getClave('volume'), self.session)
        cv.entidad = 'volume'
        volumenAndIssues = cv.getVineEntity(self.volume.id)

        self.session.query(ComicInVolumes).filter(
            ComicInVolumes.volumeId == self.volume.id).delete()
        for index, numeroComic in enumerate(volumenAndIssues[1], start=0):
            numeroComic.offset = int(index / 100)
            self.session.add(numeroComic)

        self.session.add(volumenAndIssues[0])
        self.session.commit()
コード例 #2
0
 def copiarInfo(self):
     cnf = Config(self.session)
     print('clave: ' + cnf.getClave('issue'))
     cv = ComicVineSearcher(cnf.getClave('issue'),session=self.session)
     cv.setEntidad('issue')
     completComicInfo = cv.getVineEntity(self.comicBookVine.idExterno)
     self.comicbook = self.session.query(ComicBook).filter(ComicBook.path==self.comicbook.path).first()
     catalogador = Catalogador(self.session)
     catalogador.copyFromComicToComic(completComicInfo,self.comicbook)
     self.setup.ultimoNumeroConsultadoHasta = self.entryNumeroHasta.get()
     self.setup.ultimoNumeroConsultadoDesde = self.entryNumeroDesde.get()
     self.setup.ultimoVolumeIdUtilizado = self.entrySerie.get()
     self.setup.expresionRegularNumero = self.entryPathRe.get()
     print(self.setup)
     self.session.commit()
コード例 #3
0
    def copiarInfoGrupo(self):

        cantidadZeros=0
        for comic in self.comicbooks:
            if comic.numero == 0:
                cantidadZeros+=1
        if cantidadZeros>1:
            print("hay mas de un cero en la lista a catalogar. Se anula el proceso")
            return

        cnf = Config(self.session)
        print('clave: ' + cnf.getClave('issue'))
        cv = ComicVineSearcher(cnf.getClave('issue'),session=self.session)
        cv.setEntidad('issue')
        catalogador = Catalogador(self.session)
        for comic in self.comicbooks:
            print("Vamos a ACTUALIZAR EL COMIC")
            print(comic)
            comicInfo=None
            '''Buscamos en la lista de Vine el numero de comic'''
            for comicVine in self.listaAMostrar:
                    if comicVine.numero==comic.numero:
                        comicInfo = comicVine
                        break
            print("Encontramos el comic:")
            print(comicInfo)
            '''Si existe lo catalogamos'''
            if comicInfo is not None:
                print("LA INFO COMPLETA")
                print(comicInfo)
                cv.setEntidad('issue')
                completComicInfo = cv.getVineEntity(comicInfo.comicVineId)
                comicbook = self.session.query(ComicBook).filter(ComicBook.path==comic.path).first()
                catalogador.copyFromComicToComic(completComicInfo,comicbook)

                for item in self.listViewComics.get_children():
                    if completComicInfo.numero == self.listViewComics.item(item, 'text'):
                        print("ACTUALIZANDO GUI")
                        t = threading.Thread(target=self.updateGui, args=[item])
                        t.start()

        self.setup.ultimoNumeroConsultadoHasta = self.entryNumeroHasta.get()
        self.setup.ultimoNumeroConsultadoDesde = self.entryNumeroDesde.get()
        self.setup.ultimoVolumeIdUtilizado = self.entrySerie.get()
        self.setup.expresionRegularNumero = self.entryPathRe.get()
        print(self.setup)
        self.session.commit()
コード例 #4
0
    def updateVolume(self):
        cnf = Config(self.session)
        cv = ComicVineSearcher(cnf.getClave('volume'),session=self.session)
        cv.entidad='volume'
        volumenAndComics = cv.getVineEntity(self.volume.id)

        volumeUpdated = volumenAndComics[0]

        self.volume.cantidadNumeros = volumeUpdated.cantidadNumeros
        self.volume.nombre = volumeUpdated.nombre
        print(volumeUpdated.image_url)
        self.volume.image_url = volumeUpdated.image_url
        self.volume.publisher_name = volumeUpdated.publisher_name
        self.volume.publisherId = volumeUpdated.publisherId
        self.setVolume(self.volume)
        self.loadVolume()
        self.numerosPorVolumen = volumenAndComics[1]
        self.guardar()
コード例 #5
0
class Volumen_vine_search_Gtk():
    def __init__(self, session=None):

        config = Config()

        self.listaFiltrada = []
        if session is None:
            self.session = Entidades.Init.Session()
        else:
            self.session = session

        self.comicVineSearcher = ComicVineSearcher(config.getClave('volumes'),
                                                   session=self.session)
        self.comicVineSearcher.setEntidad("volumes")
        self.publishers_manager = Publishers()

        self.handlers = {
            'click_lookup_editorial': self.click_lookup_editorial,
            'click_buscar_serie': self.click_buscar_serie,
            'click_buscar_mas_serie': self.click_buscar_mas_serie,
            'click_aceptar': self.click_aceptar,
            'entry_id_editorial_change': self.entry_id_editorial_change,
            'seleccion': self.seleccion,
            'click_detener': self.click_detener,
            'intro_detection': self.intro_detection
        }

        self.builder = Gtk.Builder()
        self.builder.add_from_file(
            "../Glade_files/Volumen_vine_search_gtk.glade")
        self.builder.connect_signals(self.handlers)
        self.window = self.builder.get_object("Volumen_vine_search_Gtk")
        self.window.set_icon_from_file('../iconos/BabelComic.png')
        self.entry_serie_nombre = self.builder.get_object("entry_serie_nombre")
        self.label_descripcion_editorial = self.builder.get_object(
            "label_descripcion_editorial")
        self.entry_id_editorial = self.builder.get_object("entry_id_editorial")
        self.gtk_tree_view_volumens = self.builder.get_object(
            "gtk_tree_view_volumens")
        self.listmodel_volumenes = self.builder.get_object(
            'listmodel_volumenes')
        self.listmodel_volumenes.clear()

        self.label_status = self.builder.get_object("label_status")
        self.volume_logo_image = self.builder.get_object("volumen_logo_image")
        self.spinner = self.builder.get_object("spinner")
        self.volume = None
        self.publisher = None
        self.cargarResultado(self.listmodel_volumenes)
        # self.entry_id_editorial.set_text('2707')
        # self.entry_serie_nombre.set_text('iron man')

    def intro_detection(self, widget, event):
        if event.keyval == Gdk.KEY_Return:
            self.click_buscar_serie(None)

    def click_detener(self, widget):
        self.comicVineSearcher.detener = True
        for hilo in self.comicVineSearcher.lista_hilos_ejecucion.items():
            print(hilo)
            hilo[1].join(1)
            self.comicVineSearcher.lock.acquire(True)
            self.comicVineSearcher.cantidad_hilos -= 1
            self.comicVineSearcher.lock.release()

    def _copy_to_window(self):
        if self.publisher:
            self.entry_id_editorial.set_text(str(self.publisher.id_publisher))
            self.label_descripcion_editorial.set_text(self.publisher.name)
        else:
            self.label_descripcion_editorial.set_text('')

    def entry_id_editorial_change(self, widget):
        self.publisher = None
        self.publisher = self.publishers_manager.get(
            self.entry_id_editorial.get_text())
        self._copy_to_window()
        if self.publisher is not None or self.entry_id_editorial.get_text(
        ) == '':
            self.cargarResultado(self.comicVineSearcher.listaBusquedaVine)
        print("Publisher recueperado")
        print(self.publisher)

    def click_lookup_editorial(self, widget):
        lookup = Publisher_lookup_gtk(self.session,
                                      self.return_lookup_editorial)
        lookup.window.show()

    def return_lookup_editorial(self, id_publisher):
        if id_publisher is not None:
            self.publisher = None
            self.publisher = self.publishers_manager.get(id_publisher)
            self._copy_to_window()
            if self.publisher is not None or self.entry_id_editorial.get_text(
            ) == '':
                self.cargarResultado(self.comicVineSearcher.listaBusquedaVine)
        print("Publisher recueperado")

    def _buscarMas(self):
        self.comicVineSearcher.vineSearchMore()
        GLib.idle_add(self.cargarResultado,
                      self.comicVineSearcher.listaBusquedaVine)
        # print(self.comicVineSearcher.listaBusquedaVine)

    def click_buscar_mas_serie(self, widget):

        self.spinner.start()
        for i in range(self.comicVineSearcher.cantidadPaginas - 4):
            print("buscando mas")
            self.hilo1 = threading.Thread(target=self._buscarMas)
            self.hilo1.start()
            time.sleep(1)

    def _buscar(self):
        self.offset = 0
        self.comicVineSearcher.clearFilter()
        self.comicVineSearcher.setEntidad("volumes")
        lista_palabras = '+'.join(
            str(palabra)
            for palabra in self.entry_serie_nombre.get_text().split(' '))
        self.comicVineSearcher.addFilter("name:" + lista_palabras)
        self.comicVineSearcher.vine_Search_all()
        GLib.idle_add(self.cargarResultado,
                      self.comicVineSearcher.listaBusquedaVine)

    def click_buscar_serie(self, widget):
        self.spinner.start()
        self.listmodel_volumenes.clear()
        self.hilo1 = threading.Thread(target=self._buscar)
        self.hilo1.start()

    def cargar_mensaje_status(self, mensaje):
        self.label_status.set_text(mensaje)

    def hilo_cargar_volume(self, id_volume_externo):

        self.comicVineSearcher.entidad = 'volume'
        volumen = self.comicVineSearcher.getVineEntity(id_volume_externo)
        # recuperamos los isseues del volumen estan en una lista de comic_vine_searcher
        self.comicVineSearcher.cargar_comicbook_info(volumen)
        while self.comicVineSearcher.porcentaje_procesado != 100 and not self.comicVineSearcher.detener:
            time.sleep(2)
            GLib.idle_add(
                self.cargar_mensaje_status, "Porcentaje completado {}%".format(
                    self.comicVineSearcher.porcentaje_procesado))
        if self.comicVineSearcher.detener:
            GLib.idle_add(self.cargar_mensaje_status,
                          "Proceso de descarga detenido")
            print("Proceso de descarga detenido")
            return

        volumen_in_db = self.session.query(Volume).filter(
            Volume.id_volume == volumen.id_volume).first()
        if volumen_in_db is not None:
            # actualizo la cantidad de ejemplares nada mas
            print(volumen)
            volumen_in_db.actualizar_con(volumen)
            volumen = volumen_in_db
        self.session.add(volumen)
        self.session.commit()
        #print(volumen)
        for comicbook_info in self.comicVineSearcher.lista_comicbooks_info:
            cbi_db = self.session.query(
                Entidades.Agrupado_Entidades.Comicbook_Info).get(
                    comicbook_info.id_comicbook_info)
            if cbi_db is not None and not cbi_db.actualizado_externamente:
                self.session.query(Comicbook_Info).filter(
                    Comicbook_Info.id_comicbook_info ==
                    comicbook_info.id_comicbook_info).delete()
                self.session.commit()
                self.session.add(comicbook_info)
            elif cbi_db is not None and cbi_db.actualizado_externamente:
                print("Actualizando info de comicbook_info DATOS A ACTUALIZAR")
                cbi_db.numero = comicbook_info.numero
                cbi_db.fecha_tapa = comicbook_info.fecha_tapa
                cbi_db.orden = comicbook_info.orden
                cbi_db.url = comicbook_info.url
                cbi_db.api_detail_url = comicbook_info.api_detail_url

                for url_cover in comicbook_info.thumbs_url:
                    copiar_cover = True
                    for url_cover_cbi in cbi_db.thumbs_url:
                        if url_cover.thumb_url == url_cover_cbi.thumb_url:
                            copiar_cover = False
                            break

                    if copiar_cover:
                        cbi_db.thumbs_url.append(url_cover)

                    # cbi_db.thumbs_url = comicbook_info.thumbs_url
                print(cbi_db)
            else:
                print("agregando comic por primera vez")
                print(cbi_db)
                self.session.add(comicbook_info)
            self.session.commit()
        lista_arcos = []
        for arco in self.comicVineSearcher.lista_arcos:
            arco_db = self.session.query(Arco_Argumental).filter(
                Arco_Argumental.id_arco_argumental ==
                arco.id_arco_argumental).first()
            if arco_db is not None:
                lista_arcos.append(arco_db)
                arco_db.lista_ids_comicbook_info_para_procesar = arco.lista_ids_comicbook_info_para_procesar
            else:
                self.session.add(arco)
                lista_arcos.append(arco)
        self.session.commit()
        # reemplazo todos los arcos por los que estan la base o los que acabo de guardar
        self.comicVineSearcher.lista_arcos = lista_arcos
        # construimos la relacion para cada arco con la lista de comics.
        for arco in self.comicVineSearcher.lista_arcos:
            try:
                print("Lista de arcos de cv {}".format(
                    arco.lista_ids_comicbook_info_para_procesar))
            except Exception:
                print("Arco con error {}".format(arco))
                raise
            for comicbook_info in self.comicVineSearcher.lista_comicbooks_info:
                for pos, arco_comicbook_info in enumerate(
                        arco.lista_ids_comicbook_info_para_procesar):
                    # print("Comic Info {} tipo {} comic info arco {} tipo {}".format(comicbook_info.id_comicbook_info,
                    #                                                                 type(comicbook_info.id_comicbook_info),
                    #                                                                 arco_comicbook_info,
                    #                                                                 type(arco_comicbook_info)))
                    if int(comicbook_info.id_comicbook_info
                           ) == arco_comicbook_info:
                        comicbook_info_db = self.session.query(
                            Comicbook_Info).get(
                                comicbook_info.id_comicbook_info)
                        rel = self.session.query(
                            Arcos_Argumentales_Comics_Reference).get(
                                (comicbook_info.id_comicbook_info,
                                 arco.id_arco_argumental))
                        if rel is None:
                            print("El comic book_info {} pertenece al arco {}".
                                  format(comicbook_info.id_comicbook_info,
                                         arco.id_arco_argumental))
                            arco_argumental_comicsbook_reference = Arcos_Argumentales_Comics_Reference(
                            )
                            arco_argumental_comicsbook_reference.orden = pos
                            arco_argumental_comicsbook_reference.ids_arco_argumental = arco
                            print("COMIC A RELACIONAR")
                            print(type(comicbook_info))
                            print(type(comicbook_info_db))
                            if comicbook_info_db is not None:
                                arco_argumental_comicsbook_reference.ids_comicbooks_info = comicbook_info_db
                            else:
                                arco_argumental_comicsbook_reference.ids_comicbooks_info = comicbook_info
                            self.session.add(
                                arco_argumental_comicsbook_reference)
                            self.session.commit()

        # Descargamos los covers de los issues del volumen
        for comicbook_info in self.comicVineSearcher.lista_comicbooks_info:
            print('Bajando covers {}'.format(comicbook_info.id_comicbook_info))
            # comicbook_info.get_first_cover_complete_path()
            comicbooks_info_manager = Comicbooks_Info(session=self.session)
            comicbooks_info_manager.get(comicbook_info.id_comicbook_info)
            print(comicbooks_info_manager.get)
            threading.Thread(target=comicbooks_info_manager.
                             get_first_cover_complete_path).start()

    def click_aceptar(self, widget):
        self.comicVineSearcher.detener = False
        threading.Thread(target=self.hilo_cargar_volume,
                         args=[self.volume.id_volume]).start()
        # 86343 - 5868-106705-18216-
        # 32561 - Brightest Day
        # 32562 - The flash vol3
        # 18127 - Justice League of America
        # 4363 - green lantern vol 3
        # 18058 - detective comics106705
        # 18216 - green lantern vol 4
        # 6498 - birdth of prey
        # 773 - superman Vol2
        # threading.Thread(target=self.hilo_cargar_volume, args=['3816']).start()
        # threading.Thread(target=self.hilo_cargar_volume, args=['18216']).start()
        # threading.Thread(target=self.hilo_cargar_volume, args=['25372']).start()
        # threading.Thread(target=self.hilo_cargar_volume, args=['25543']).start()
        # threading.Thread(target=self.hilo_cargar_volume, args=['18058']).start()
        # threading.Thread(target=self.hilo_cargar_volume, args=['7300']).start()
        #threading.Thread(target=self.hilo_cargar_volume, args=['4740']).start()
        # threading.Thread(target=self.hilo_cargar_volume, args=['106705']).start()


#4740

# 25543

#
# self.hilo_cargar_volume('6498')
# self.hilo_cargar_volume('18216')

    def _seleccion(self):
        self.volume.localLogoImagePath = self.volume.getImageCover()
        pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
            filename=self.volume.getImagePath(),
            width=250,
            height=250,
            preserve_aspect_ratio=True)
        self.spinner.stop()
        GLib.idle_add(self.volume_logo_image.set_from_pixbuf, pixbuf)
        # self.volume_logo_image.set_from_pixbuf(pixbuf)

    def seleccion(self, selection):
        self.spinner.start()
        GLib.idle_add(self.cargar_mensaje_status, "")
        (model, iter) = selection.get_selected()
        if iter:
            self.volume = self.listaFiltrada[int(model[iter][0])]
            self.hilo1 = threading.Thread(target=self._seleccion)
            self.hilo1.start()

    def cargarResultado(self, listavolumes):
        self.listmodel_volumenes.clear()
        self.listaFiltrada.clear()
        for volume in listavolumes:
            if self.publisher is not None:
                print("Editorial de fitro: {} Editorial Comics: {}".format(
                    self.publisher.id_publisher, volume.id_publisher))
                if self.publisher.id_publisher == volume.id_publisher:
                    self.listaFiltrada.append(volume)
            else:
                self.listaFiltrada.append(volume)
        print("Longitud: {}".format(len(self.listaFiltrada)))
        if len(self.listaFiltrada) > 1400:
            self.label_status.set_text(
                "La cantidad de registros es mayor a 1400. Trate de filtrar la consulta."
            )
            return
        for idx, volume in enumerate(self.listaFiltrada):
            nombre = ''
            cantidad_numeros = 0
            anio = 0
            publisher_name = ""
            if volume.nombre is not None:
                nombre = volume.nombre
            if volume.anio_inicio is not None:
                if str.isdigit(volume.anio_inicio):
                    anio = int(volume.anio_inicio)

            if str.isdigit(volume.cantidad_numeros):
                cantidad_numeros = int(volume.cantidad_numeros)

            if volume.publisher_name is not None:
                publisher_name = volume.publisher_name
            print("cargand el volumen {}".format(str(idx) + " " + nombre))
            self.listmodel_volumenes.append(
                [str(idx), nombre, cantidad_numeros, publisher_name, anio])

        self.label_status.set_text(
            "Cantidad Resultados: {} - Cantidad Resultados sin filtro: {}- Cantidad Total de Res"
            "ultados en ComicVine: {}".format(
                len(self.listaFiltrada),
                len(self.comicVineSearcher.listaBusquedaVine),
                self.comicVineSearcher.cantidadResultados))
        self.spinner.stop()