diff --git a/glitch_random.py b/glitch_random.py index 27ceabf..b419156 100755 --- a/glitch_random.py +++ b/glitch_random.py @@ -40,7 +40,6 @@ import sys import getopt import webbrowser -import requests from PIL import Image from collections import Counter, defaultdict from StringIO import StringIO @@ -69,6 +68,7 @@ def __init__(self, path, from_file = False, outdir = '.'): # if not from_file, path is a URL to image online else: + import requests self.data = requests.get(path).content # use regex to extract name (id) for image from end of URL # after final backslash (greedy match) but before '_' diff --git a/utils.py b/utils.py index 1b506ed..85b8631 100644 --- a/utils.py +++ b/utils.py @@ -1,6 +1,6 @@ import os, subprocess, glob import re -import webbrowser, requests +import webbrowser import random @@ -60,6 +60,7 @@ def random(self, pop_open=True, write=False): if write: # write image data to file in directory specified by global PATH_OUT outfile = outfile_path( self.outdir, '{}.jpg'.format(d_hit['id']) ) + import requests with open(outfile, "w") as file_out: file_out.write( requests.get(hit_url).content )