
import feedparser, requests, ui

url = 'https://itunes.apple.com/us/rss/topsongs/limit=10/xml'

def get_image_urls(itunes_url):
    for entry in feedparser.parse(itunes_url).entries:
        yield entry['summary'].partition('src="')[2].partition('"')[0]

class TopTenView(ui.View):
    def __init__(self, image_urls):
        self.present()
        for i, url in enumerate(image_urls):
            button = ui.Button()
            button.background_image = ui.Image.from_data(requests.get(url).content)
            button.border_width = 2
            button.x = (i % 5) * 128 + 10
            button.y = (i / 5) * 128 + 10
            button.width = button.height = 128
            self.add_subview(button)

TopTenView(list(get_image_urls(url)))


import feedparser, requests, ui

url = 'https://itunes.apple.com/us/rss/topsongs/limit=10/xml'

def get_image_urls(itunes_url):
    for entry in feedparser.parse(itunes_url).entries:
        yield entry['summary'].partition('src="')[2].partition('"')[0]

class TopTenView(ui.View):
    def __init__(self, image_urls):
        self.present()
        for i, url in enumerate(image_urls):
            button = ui.Button()
            button.background_image = ui.Image.from_data(requests.get(url).content)
            w, h = button.background_image.size
            button.x = i % 5 * w
            button.y = i / 5 * h
            button.width, button.height = w, h
            button.border_width = 2
            self.add_subview(button)

TopTenView(list(get_image_urls(url)))

Move to buttons & remove hardcoding of image size
Move to buttons & remove hardcoding of image size
  
  import feedparser, requests, ui
  
  url = 'https://itunes.apple.com/us/rss/topsongs/limit=10/xml'
  
  def get_image_urls(itunes_url):
      for entry in feedparser.parse(itunes_url).entries:
          yield entry['summary'].partition('src="')[2].partition('"')[0]
  
  class TopTenView(ui.View):
      def __init__(self, image_urls):
          self.present()
          for i, url in enumerate(image_urls):
              button = ui.Button()
              button.background_image = ui.Image.from_data(requests.get(url).content)
+             w, h = button.background_image.size
+             button.x = i % 5 * w
+             button.y = i / 5 * h
+             button.width, button.height = w, h
              button.border_width = 2
-             button.x = (i % 5) * 128 + 10
-             button.y = (i / 5) * 128 + 10
-             button.width = button.height = 128
              self.add_subview(button)
  
  TopTenView(list(get_image_urls(url)))
  
Move to buttons & remove hardcoding of image size
## Code Before:

import feedparser, requests, ui

url = 'https://itunes.apple.com/us/rss/topsongs/limit=10/xml'

def get_image_urls(itunes_url):
    for entry in feedparser.parse(itunes_url).entries:
        yield entry['summary'].partition('src="')[2].partition('"')[0]

class TopTenView(ui.View):
    def __init__(self, image_urls):
        self.present()
        for i, url in enumerate(image_urls):
            button = ui.Button()
            button.background_image = ui.Image.from_data(requests.get(url).content)
            button.border_width = 2
            button.x = (i % 5) * 128 + 10
            button.y = (i / 5) * 128 + 10
            button.width = button.height = 128
            self.add_subview(button)

TopTenView(list(get_image_urls(url)))

## Instruction:
Move to buttons & remove hardcoding of image size
## Code After:

import feedparser, requests, ui

url = 'https://itunes.apple.com/us/rss/topsongs/limit=10/xml'

def get_image_urls(itunes_url):
    for entry in feedparser.parse(itunes_url).entries:
        yield entry['summary'].partition('src="')[2].partition('"')[0]

class TopTenView(ui.View):
    def __init__(self, image_urls):
        self.present()
        for i, url in enumerate(image_urls):
            button = ui.Button()
            button.background_image = ui.Image.from_data(requests.get(url).content)
            w, h = button.background_image.size
            button.x = i % 5 * w
            button.y = i / 5 * h
            button.width, button.height = w, h
            button.border_width = 2
            self.add_subview(button)

TopTenView(list(get_image_urls(url)))
