Skip to content

Commit a1ac81c

Browse files
committed
Fix most deviations from PEP8
1 parent b6a3932 commit a1ac81c

File tree

1 file changed

+32
-21
lines changed

1 file changed

+32
-21
lines changed

coderwall.py

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313

1414
# Handle differences in urllib imports
1515
if sys.version_info[0] >= 3:
16-
import urllib.request as urllib_request, urllib.error as urllib_error
16+
import urllib.request as urllib_request
17+
import urllib.error as urllib_error
1718
else:
1819
import urllib2 as urllib_request
1920
urllib_error = urllib_request
2021

22+
2123
class CoderWall(object):
2224

2325
"""
@@ -40,17 +42,17 @@ class CoderWall(object):
4042
>>> cwc.endorsements
4143
0
4244
>>> cwc.badges
43-
[Charity: Fork and commit to someone's open source project in need,
44-
Python: Would you expect anything less? Have at least one original repo
45-
where Python is the dominant language, T-Rex: Have at least one original
45+
[Charity: Fork and commit to someone's open source project in need,
46+
Python: Would you expect anything less? Have at least one original repo
47+
where Python is the dominant language, T-Rex: Have at least one original
4648
repo where C is the dominant language]
4749
>>> cwc.badges[0].image_uri
4850
http://cdn.coderwall.com/assets/badges/charity-bf61e713137d910534ff805f389bcffb.png
4951
>>> print cwc
50-
Cameron Currie (cwc), Austin, TX, Endorsed 0 times: [Charity: Fork and
51-
commit to someone's open source project in need, Python: Would you expect
52-
anything less? Have at least one original repo where Python is the dominant
53-
language, T-Rex: Have at least one original repo where C is the dominant
52+
Cameron Currie (cwc), Austin, TX, Endorsed 0 times: [Charity: Fork and
53+
commit to someone's open source project in need, Python: Would you expect
54+
anything less? Have at least one original repo where Python is the dominant
55+
language, T-Rex: Have at least one original repo where C is the dominant
5456
language]
5557
"""
5658

@@ -65,13 +67,15 @@ def __init__(self, username):
6567
self.endorsements = data[2]
6668
self.badges = parse_badges(data[3])
6769
else:
68-
raise NameError(self.username + ' does not appear to be a CoderWall user')
70+
raise NameError(self.username +
71+
' does not appear to be a CoderWall user')
6972

7073
def __repr__(self):
7174
return "CoderWall(username=%r)" % (self.username)
7275

73-
def __str__(self):
74-
return self.name + ' (' + self.username + '), ' + self.location + ', Endorsed ' + str(self.endorsements) + ' times: ' + str(self.badges)
76+
def __str__(self):
77+
return '%s (%s), %s, Endorsed %s times: %s' % (self.name, self.username, self.location, str(self.endorsements), str(self.badges))
78+
7579

7680
class Badge(object):
7781

@@ -84,8 +88,8 @@ class Badge(object):
8488
name
8589
description
8690
image_uri
87-
"""
88-
91+
"""
92+
8993
def __init__(self, name, description, image_uri):
9094
self.name = name
9195
self.description = description
@@ -97,49 +101,56 @@ def __repr__(self):
97101
def __str__(self):
98102
return self.name + ': ' + self.description
99103

104+
100105
def get_json_data(username):
101106
"""
102-
Connect to CoderWall and return the raw JSON data for the given
103-
username.
107+
Connect to CoderWall and return the raw JSON data for the given
108+
username.
104109
"""
105110

106111
api_url = 'http://coderwall.com/' + username + '.json'
107112

108113
try:
109114
response = urllib_request.urlopen(api_url, None, 5)
110115
except urllib_error.URLError:
111-
return '' # TODO Better error handling
116+
return '' # TODO Better error handling
112117

113118
return response.read().decode('utf-8')
114119

120+
115121
def parse_json_data(json_data):
116122
""" Parse the given JSON data and return data about the user. """
117123

118124
try:
119125
data = json.loads(json_data)
120126
except ValueError:
121-
return None # TODO Better error handling
127+
return None # TODO Better error handling
122128

123129
name = data['name']
124130
location = data['location']
125-
endorsements = data['endorsements']
131+
endorsements = data['endorsements']
126132
badges = data['badges']
127133

128134
return (name, location, endorsements, badges)
129135

136+
130137
def parse_badges(raw_badges):
131138
"""
132-
Parse the given list of dictionaries, interpret each as a
139+
Parse the given list of dictionaries, interpret each as a
133140
CoderWall badge, and return a list of Badge objects.
134141
"""
135142

136143
badges = []
137144
for raw_badge in raw_badges:
138-
badges.append(Badge(raw_badge['name'],
139-
raw_badge['description'], raw_badge['badge']))
145+
badges.append(Badge(
146+
raw_badge['name'],
147+
raw_badge['description'],
148+
raw_badge['badge']
149+
))
140150

141151
return badges
142152

153+
143154
if __name__ == '__main__':
144155
if len(sys.argv) < 2:
145156
print('Usage: ' + sys.argv[0] + ' <username> [username ...]')

0 commit comments

Comments
 (0)