From bf1af8813f3e1053eeb161b7acf24e0bfd5384f4 Mon Sep 17 00:00:00 2001 From: Mark Kubiak Date: Tue, 28 Oct 2014 20:06:25 -0400 Subject: [PATCH] Fixed a bug where the double space fix removed the last character of the title line... AP Computer Science teaches you to use for loops instead of built-in libs. --- wallpaper-reddit.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/wallpaper-reddit.py b/wallpaper-reddit.py index 880d625..e186181 100755 --- a/wallpaper-reddit.py +++ b/wallpaper-reddit.py @@ -148,7 +148,7 @@ def check_not_redirected(): #Not reloading /etc/resolv.conf, since it will have to be reloaded for the function right before this is called uaurl = urllib.request.Request('http://www.reddit.com/.json', headers={ 'User-Agent' : 'wallpaper-reddit python script by /u/MarcusTheGreat7'}) url = urllib.request.urlopen(uaurl,timeout=3) - json.loads(url.read().decode("utf8")) + json.loads(url.read().decode('utf8')) url.close() return True except (HTTPError, URLError, timeout, AttributeError, ValueError): @@ -288,7 +288,7 @@ def get_links(subreddits): response = urllib.request.urlopen(uaurl) content = response.read() try: - data = json.loads(content.decode("utf8")) + data = json.loads(content.decode('iso8859-1')) except (AttributeError, ValueError): print('Was redirected from valid Reddit formatting. Likely a router redirect, such as a hotel or airport. Exiting...') sys.exit(0) @@ -423,11 +423,7 @@ def remove_tags(str): if i == ')': tag = False #removes any double spaces (from previous removals) and any spaces at the beginning and end - title = '' - for i in (range(len(str2)-1)): - if not(str2[i] == ' ' and str2[i+1] == ' '): - title = title + str2[i] - title = title.strip() + title = str2.replace(' ', ' ').strip() return title #saves the wallpaper in the save directory from the config