uris = grfetch.get_all_wikipedia_image_uris(wiki_page)
    if not uris:
        print(f"Could not find any images for {name} on their wiki page!")
        #sys.exit(1)        

    for uri in uris:
        display_image(uri, 200, 200, False)
        cur.execute("SELECT COUNT(1) FROM images WHERE url=?", (uri,))
        row = cur.fetchone()
        if row[0] == 1:
            print("We already have that url in the database!")
            continue
        response = input("Do you want to use this image? ")
        if response[0].lower() == 'y':
            f = generate_image(uri, author_image_size, author_image_size)
            image = f.getvalue()
            store_image(conn, author_id, uri, image, author_image_size)

    response = input("Do you want to do a google search for images? ")
    if response[0].lower() != 'y':
        sys.exit()
    uris = get_google_images(name)
    if not uris:
        print(f"Could not find any google images for {name}!")
        sys.exit(1)        

    for uri in uris:
        result = display_image(uri, 200, 200, False)
        if not result:
            continue
Exemple #2
0
            if rows:
                if alpha > 1.0:
                    # first time through with  new track img_current is None
                    img_previous = img_current
                    while 1:
                        row = rows.pop()
                        #sys.stdout.buffer.write(b"\x1b[2J")
                        cur.execute("SELECT image FROM image_files WHERE image_id=%s", (row[0],))
                        r = cur.fetchone()
                        if r:
                            s = "This image is being stored as BYTES in the database"
                            img_current = BytesIO(r[0])
                            print()
                        else:
                            s = "This image is being stored as just a URL in the database"
                            img_current = generate_image(row[1], sonos_image_size, sonos_image_size)
                            print()
                        if img_current:
                            break
                        if not rows:
                            rows = all_rows[::]
                    alpha = 0

                if img_previous and img_current:
                    #alpha += .015 # .025 goes will with time.sleep(.05)
                    img_blend = blend_images(img_previous, img_current, alpha)
                    if img_blend:
                        sys.stdout.buffer.write(b"\x1b[H")
                        show_image(img_blend)
                        print(f"\n\x1b[1m{title} {artist}\x1b[0m\n{s}")
                        alpha += .015 
        except Exception as e:
            print(e)
            continue

    return uris


if __name__ == '__main__':

    # Use input as song title and artist name
    artist = sys.argv[1]
    z = get_wiki_images2(artist)
    for x in z:
        print(x)
        if os.path.splitext(x)[1].lower() in ['.png', '.jpg']:
            img = generate_image(x, 900, 900)
            show_image(img)
            save_image(img, "testing123.png")
            print()

    exit(0)
    z = get_wiki_images(artist)
    a = artist.lower().replace(" ", "_")
    b = artist.lower().replace(" ", "")
    for x in z:
        if a in x.lower().replace("-", "_"):
            print(x, "Good url 1")
        elif b in x.lower():
            print(
                x, "Good url 2"
            )  # this situation where there is no space between names is rare and may not be worth it`
Exemple #4
0
                images = all_images[::]

        # for blended I think we actually hold the PIL image
        # I think we continuously blend images like once every second
        # everything is a blend potentially that runs from 0 to 1
        # I think you would have:
        #     img_previous  and img_next and at some point img_next becomes img_previous

            if images:
                if alpha > 1.0:
                    img_previous = img_current
                    while 1:
                        image = images.pop()
                        #sys.stdout.buffer.write(b"\x1b[2J")
                        img_current = generate_image(image.link,
                                                     sonos_image_size,
                                                     sonos_image_size)
                        if img_current:
                            break
                        if not images:
                            images = all_images[::]
                    alpha = 0

                if img_previous and img_current:
                    alpha += .015  # .025 goes will with time.sleep(.05)
                    img_blend = blend_images(img_previous, img_current, alpha)
                    if img_blend:
                        sys.stdout.buffer.write(b"\x1b[H")
                        show_image(img_blend)
                elif img_current:
                    alpha = 1.1
Exemple #5
0
                            print(ret.join(zz[first_line:]))
                            need_scroll = False
                        else:
                            print(ret.join(zz[prev_line_num:line_num + 1]))
                            prev_line_num = line_num
                            n += 1

                        sys.stdout.write("\x1b[0m")

            if rows:
                if alpha > 1.0:
                    # first time through with new track img_current is None
                    img_previous = img_current
                    while 1:
                        row = rows.pop()
                        img_current = generate_image(row, display_size,
                                                     display_size)
                        if img_current:
                            break

                        if not rows:
                            rows = all_rows[::]

                        time.sleep(10)

                    if img_previous:
                        alpha = 0

                if img_previous and img_current:
                    #alpha += .015 # .025 goes will with time.sleep(.05)
                    img_blend = blend_images(img_previous, img_current, alpha)
                    if img_blend:
                response = input(
                    "This image is being stored as bytes in the database  - do you want to KEEP it? "
                )
                if response[0].lower() != 'y':
                    cur.execute("DELETE FROM image_files WHERE image_id=%s",
                                (image_id, ))
                    cur.execute("DELETE FROM images WHERE id=%s", (image_id, ))
                    conn.commit()
            else:
                display_image(link)
                print()
                response = input(
                    "This image is NOT being stored as bytes yet - do you want to KEEP it? "
                )
                if response[0].lower() == 'y':
                    f = generate_image(link, sonos_image_size,
                                       sonos_image_size)
                    image = f.getvalue()
                    store_image_file(conn, image_id, image)
                else:
                    cur.execute("DELETE FROM images WHERE link=%s", (link, ))
                    conn.commit()

    response = input("Do you want to look for images in the wikipedia? ")
    if response[0].lower() == 'y':
        wiki_page = get_page(name)
        if wiki_page:
            uris = get_all_wikipedia_image_uris(wiki_page)
            if not uris:
                print(
                    f"Could not find any images for {name} on their wiki page!"
                )