Skip to content
This repository has been archived by the owner on Oct 16, 2020. It is now read-only.

Commit

Permalink
Fixed a bug where the double space fix removed the last character of …
Browse files Browse the repository at this point in the history
…the title line...

AP Computer Science teaches you to use for loops instead of built-in libs.
  • Loading branch information
Mark Kubiak committed Oct 29, 2014
1 parent e6e630f commit bf1af88
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions wallpaper-reddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bf1af88

Please sign in to comment.