old_contents: from optparse import OptionParser
  __author__ = 'Constantin Serban'
  
  import re
  import urllib
  from multiprocessing.dummy import Pool as ThreadPool
  from sql_connect import main as gr
  
  
  def get_links(items):
      links = []
      for item in items:
          matches = 0
          if item is not None:
              matches = re.findall(r"(http(s?):([/|.|\w|\s])*\.(?:jpg|gif|png))", item[0])
              match_no = len(matches)
              if matches:
                  while match_no:
                      match_no -= 1
                      link = matches[match_no]
                      links.append(link)
      return links
  
  
  def parallel_start(links):
      pool = ThreadPool(4)
      results = pool.map(download_files, links)
      pool.close()
      pool.join()
  
  
  def download_files(link):
      # TODO allow download location selection
      f = open(str("d:\\repos\\fever_saved_download\\down\\" + link[link.rfind('/')+1:]), 'wb')
      f.write(urllib.urlopen(link).read())
      f.close()
  
  
  def main():
      parser = OptionParser()
      parser.add_option("-s", "--save", action="store_true", dest="keep_saved", default=False,
                        help="Do not mark items as unsaved")
      parser.add_option("-d", "--download", action="store", dest="download_location", default=False,
                        help="Download location")
      (options, args) = parser.parse_args()
      keep_saved = options.keep_saved
      download_location = options.download_location
      items = gr(keep_saved)
      links = get_links(items)
      download_map = []
      for a in links:
          download_map.append((a, download_location))
      parallel_start(links)
  
  if __name__ == "__main__":
      main()
new_contents: from optparse import OptionParser
  __author__ = 'Constantin Serban'
  
  import re
  import urllib
  from multiprocessing.dummy import Pool as ThreadPool
  from sql_connect import main as gr
  
  
  def get_links(items):
      links = []
      for item in items:
          matches = 0
          if item is not None:
              matches = re.findall(r"(http(s?):([/|.|\w|\s])*\.(?:jpg|gif|png))", item[0])
              match_no = len(matches)
              if matches:
                  while match_no:
                      match_no -= 1
                      link = matches[match_no]
                      links.append(link)
      return links
  
  
  def parallel_start(download_map):
      pool = ThreadPool(4)
      results = pool.map(download_files, download_map)
      pool.close()
      pool.join()
  
  
  def download_files(download_map):
      # TODO allow download location selection
      location = download_map[1]
      link = download_map[0]
      f = open((location + "\\" + link[link.rfind('/') + 1:]), 'wb')
      f.write(urllib.urlopen(link).read())
      f.close()
  
  
  def main():
      parser = OptionParser()
      parser.add_option("-s", "--save", action="store_true", dest="keep_saved", default=False,
                        help="Do not mark items as unsaved")
      parser.add_option("-d", "--download", action="store", dest="download_location", default=False,
                        help="Download location")
      (options, args) = parser.parse_args()
      keep_saved = options.keep_saved
      download_location = options.download_location
      items = gr(keep_saved)
      links = get_links(items)
      download_map = []
      for a in links:
          download_map.append((a, download_location))
      parallel_start(download_map)
  
  if __name__ == "__main__":
      main()
subject: use the download_map in parallel_start and download_files