From 7ccfe917aedd65a32a9cfb965be8a681604c853b Mon Sep 17 00:00:00 2001 From: Cameron Currie Date: Fri, 30 Nov 2012 21:53:43 -0500 Subject: [PATCH 01/19] Implement __repr__ --- coderwall.py | 4 ++-- setup.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/coderwall.py b/coderwall.py index c727ab2..5fedd2a 100644 --- a/coderwall.py +++ b/coderwall.py @@ -60,7 +60,7 @@ def __init__(self, username): raise NameError(self.username + ' does not appear to be a CoderWall user') def __repr__(self): - return self.__str__() # NOTE Does not conform to standards + return "CoderWall(username=%r)" % (self.username) def __str__(self): return self.name + ' (' + self.username + '), ' + self.location + ', Endorsed ' + str(self.endorsements) + ' times: ' + str(self.badges) @@ -84,7 +84,7 @@ def __init__(self, name, description, image_uri): self.image_uri = image_uri def __repr__(self): - return self.__str__() # NOTE Does not conform to standards + return "Badge(name=%r,description=%r,image_uri=%r)" % (self.name, self.description, self.image_uri) def __str__(self): return self.name + ': ' + self.description diff --git a/setup.py b/setup.py index 434daaa..332669e 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='coderwall', - version='1.0.0', + version='1.1.0', author='Cameron Currie', author_email='me@cameroncurrie.net', url='http://github.com/cwc/coderwall-python', From afb9933739d57517f465a63acdf746dd6bab63a2 Mon Sep 17 00:00:00 2001 From: oddshocks Date: Thu, 17 Jan 2013 12:56:39 -0500 Subject: [PATCH 02/19] Add manifest file and include README.txt --- MANIFEST.in | 1 + setup.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 MANIFEST.in diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..e32fdb4 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +include README.txt diff --git a/setup.py b/setup.py index 332669e..0c46775 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='coderwall', - version='1.1.0', + version='1.1.1', author='Cameron Currie', author_email='me@cameroncurrie.net', url='http://github.com/cwc/coderwall-python', From acc6794de64d64e9dfbc23586151d0f644f58594 Mon Sep 17 00:00:00 2001 From: Cameron Currie Date: Thu, 31 Jan 2013 22:22:44 -0600 Subject: [PATCH 03/19] Add Travis CI configuration --- .travis.yml | 8 ++++++++ README.rst | 2 ++ 2 files changed, 10 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..26a9776 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,8 @@ +language: python +python: + - "2.6" + - "2.7" + - "3.2" + - "3.3" + - "pypy" +script: python -m coderwall cwc diff --git a/README.rst b/README.rst index 6e040fa..99129c2 100644 --- a/README.rst +++ b/README.rst @@ -4,6 +4,8 @@ coderwall A Python module for accessing user data at http://coderwall.com +.. image:: https://api.travis-ci.org/cwc/coderwall-python.png + Installation ------------ From daf8669bdbf5f9f130a64395cf3bfc19e0b157e1 Mon Sep 17 00:00:00 2001 From: Cameron Currie Date: Thu, 31 Jan 2013 22:28:25 -0600 Subject: [PATCH 04/19] Fix Python 3 compatibility --- coderwall.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/coderwall.py b/coderwall.py index 5fedd2a..1d8cd01 100644 --- a/coderwall.py +++ b/coderwall.py @@ -7,8 +7,15 @@ standalone script (i.e. 'python -m coderwall'). """ +import sys import json -import urllib2 + +# Handle differences in urllib imports +if sys.version_info[0] >= 3: + import urllib.request as urllib_request, urllib.error as urllib_error +else: + import urllib2 as urllib_request + urllib_error = urllib_request class CoderWall: @@ -98,11 +105,11 @@ def get_json_data(username): api_url = 'http://coderwall.com/' + username + '.json' try: - response = urllib2.urlopen(api_url, None, 5) - except urllib2.URLError: + response = urllib_request.urlopen(api_url, None, 5) + except urllib_error.URLError: return '' # TODO Better error handling - return response.read() + return response.read().decode('utf-8') def parse_json_data(json_data): """ Parse the given JSON data and return data about the user. """ @@ -136,7 +143,7 @@ def parse_badges(raw_badges): import sys if len(sys.argv) < 2: - print 'Usage: ' + sys.argv[0] + ' USERNAME...' + print('Usage: ' + sys.argv[0] + ' USERNAME...') else: for username in sys.argv[1:]: - print CoderWall(username) + print(CoderWall(username)) From 8fd7a1fa748d99edfb74fbae7d7a0d34c630284d Mon Sep 17 00:00:00 2001 From: Cameron Currie Date: Thu, 31 Jan 2013 23:18:24 -0600 Subject: [PATCH 05/19] Use README.rst in setup.py --- MANIFEST.in | 2 +- README.txt | 1 - setup.py | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) delete mode 120000 README.txt diff --git a/MANIFEST.in b/MANIFEST.in index e32fdb4..9561fb1 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1 +1 @@ -include README.txt +include README.rst diff --git a/README.txt b/README.txt deleted file mode 120000 index 92cacd2..0000000 --- a/README.txt +++ /dev/null @@ -1 +0,0 @@ -README.rst \ No newline at end of file diff --git a/setup.py b/setup.py index 0c46775..96b8a5d 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ author_email='me@cameroncurrie.net', url='http://github.com/cwc/coderwall-python', description='A Python module for accessing user data at http://coderwall.com', - long_description=open('README.txt').read(), + long_description=open('README.rst').read(), license='MIT', classifiers=[ 'Programming Language :: Python', From fd2fd0164e3fd0764f04352c5184bafc56409e37 Mon Sep 17 00:00:00 2001 From: Cameron Currie Date: Thu, 31 Jan 2013 23:21:40 -0600 Subject: [PATCH 06/19] Add link to build status image --- README.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/README.rst b/README.rst index 99129c2..4c074aa 100644 --- a/README.rst +++ b/README.rst @@ -5,6 +5,7 @@ coderwall A Python module for accessing user data at http://coderwall.com .. image:: https://api.travis-ci.org/cwc/coderwall-python.png + :target: http://travis-ci.org/cwc/coderwall-python Installation ------------ From 6f81717b6f0ac6c850902a02aa027013105d303b Mon Sep 17 00:00:00 2001 From: Cameron Currie Date: Thu, 31 Jan 2013 23:27:53 -0600 Subject: [PATCH 07/19] Update classifiers and bump version --- setup.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 96b8a5d..d9f0c79 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='coderwall', - version='1.1.1', + version='1.2.0', author='Cameron Currie', author_email='me@cameroncurrie.net', url='http://github.com/cwc/coderwall-python', @@ -11,8 +11,13 @@ license='MIT', classifiers=[ 'Programming Language :: Python', + 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.6', + 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.2', + 'Programming Language :: Python :: 3.3', + 'Programming Language :: Python :: Implementation :: PyPy', 'Development Status :: 5 - Production/Stable', 'License :: OSI Approved :: MIT License', 'Operating System :: OS Independent', From 1105355bc04aace023c3bc601becd11246f3ce03 Mon Sep 17 00:00:00 2001 From: Port Date: Tue, 12 Mar 2013 10:04:26 +0100 Subject: [PATCH 08/19] Better Python 2 support --- coderwall.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/coderwall.py b/coderwall.py index 1d8cd01..902b06f 100644 --- a/coderwall.py +++ b/coderwall.py @@ -17,7 +17,7 @@ import urllib2 as urllib_request urllib_error = urllib_request -class CoderWall: +class CoderWall(object): """ Represents a CoderWall user and provides access to all of the user's data. @@ -72,7 +72,7 @@ def __repr__(self): def __str__(self): return self.name + ' (' + self.username + '), ' + self.location + ', Endorsed ' + str(self.endorsements) + ' times: ' + str(self.badges) -class Badge: +class Badge(object): """ Represents a CoderWall badge and provides access to its attributes, such as From c19effcf2cf983a8241e62e09e23ed9c3b64b7a2 Mon Sep 17 00:00:00 2001 From: Cameron Currie Date: Sat, 25 Jan 2014 19:57:09 +0000 Subject: [PATCH 09/19] Clean up minor errors --- coderwall.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/coderwall.py b/coderwall.py index 902b06f..701bd31 100644 --- a/coderwall.py +++ b/coderwall.py @@ -134,14 +134,12 @@ def parse_badges(raw_badges): badges = [] for raw_badge in raw_badges: - badges.append(Badge(raw_badge['name'], + badges.append(Badge(raw_badge['name'], raw_badge['description'], raw_badge['badge'])) return badges if __name__ == '__main__': - import sys - if len(sys.argv) < 2: print('Usage: ' + sys.argv[0] + ' USERNAME...') else: From 90c25363ca62b7fe20b513b2ff93be302d2e9c82 Mon Sep 17 00:00:00 2001 From: Cameron Currie Date: Mon, 25 May 2015 18:19:13 -0500 Subject: [PATCH 10/19] Add shebang to main module --- coderwall.py | 1 + 1 file changed, 1 insertion(+) mode change 100644 => 100755 coderwall.py diff --git a/coderwall.py b/coderwall.py old mode 100644 new mode 100755 index 701bd31..61c7465 --- a/coderwall.py +++ b/coderwall.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python """ This module provides a simple interface to the API at http://coderwall.com. From b6a3932168d4c9d1f0525b96c4cc181ad9068805 Mon Sep 17 00:00:00 2001 From: Cameron Currie Date: Mon, 25 May 2015 18:23:06 -0500 Subject: [PATCH 11/19] Tweak usage info --- coderwall.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coderwall.py b/coderwall.py index 61c7465..c3365da 100755 --- a/coderwall.py +++ b/coderwall.py @@ -142,7 +142,7 @@ def parse_badges(raw_badges): if __name__ == '__main__': if len(sys.argv) < 2: - print('Usage: ' + sys.argv[0] + ' USERNAME...') + print('Usage: ' + sys.argv[0] + ' [username ...]') else: for username in sys.argv[1:]: print(CoderWall(username)) From a1ac81cbff54b696ef6fbf0d3a4a5739a6d926d1 Mon Sep 17 00:00:00 2001 From: Cameron Currie Date: Mon, 25 May 2015 18:57:18 -0500 Subject: [PATCH 12/19] Fix most deviations from PEP8 --- coderwall.py | 53 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/coderwall.py b/coderwall.py index c3365da..2e430cd 100755 --- a/coderwall.py +++ b/coderwall.py @@ -13,11 +13,13 @@ # Handle differences in urllib imports if sys.version_info[0] >= 3: - import urllib.request as urllib_request, urllib.error as urllib_error + import urllib.request as urllib_request + import urllib.error as urllib_error else: import urllib2 as urllib_request urllib_error = urllib_request + class CoderWall(object): """ @@ -40,17 +42,17 @@ class CoderWall(object): >>> cwc.endorsements 0 >>> cwc.badges - [Charity: Fork and commit to someone's open source project in need, - Python: Would you expect anything less? Have at least one original repo - where Python is the dominant language, T-Rex: Have at least one original + [Charity: Fork and commit to someone's open source project in need, + Python: Would you expect anything less? Have at least one original repo + where Python is the dominant language, T-Rex: Have at least one original repo where C is the dominant language] >>> cwc.badges[0].image_uri http://cdn.coderwall.com/assets/badges/charity-bf61e713137d910534ff805f389bcffb.png >>> print cwc - Cameron Currie (cwc), Austin, TX, Endorsed 0 times: [Charity: Fork and - commit to someone's open source project in need, Python: Would you expect - anything less? Have at least one original repo where Python is the dominant - language, T-Rex: Have at least one original repo where C is the dominant + Cameron Currie (cwc), Austin, TX, Endorsed 0 times: [Charity: Fork and + commit to someone's open source project in need, Python: Would you expect + anything less? Have at least one original repo where Python is the dominant + language, T-Rex: Have at least one original repo where C is the dominant language] """ @@ -65,13 +67,15 @@ def __init__(self, username): self.endorsements = data[2] self.badges = parse_badges(data[3]) else: - raise NameError(self.username + ' does not appear to be a CoderWall user') + raise NameError(self.username + + ' does not appear to be a CoderWall user') def __repr__(self): return "CoderWall(username=%r)" % (self.username) - def __str__(self): - return self.name + ' (' + self.username + '), ' + self.location + ', Endorsed ' + str(self.endorsements) + ' times: ' + str(self.badges) + def __str__(self): + return '%s (%s), %s, Endorsed %s times: %s' % (self.name, self.username, self.location, str(self.endorsements), str(self.badges)) + class Badge(object): @@ -84,8 +88,8 @@ class Badge(object): name description image_uri - """ - + """ + def __init__(self, name, description, image_uri): self.name = name self.description = description @@ -97,10 +101,11 @@ def __repr__(self): def __str__(self): return self.name + ': ' + self.description + def get_json_data(username): """ - Connect to CoderWall and return the raw JSON data for the given - username. + Connect to CoderWall and return the raw JSON data for the given + username. """ api_url = 'http://coderwall.com/' + username + '.json' @@ -108,38 +113,44 @@ def get_json_data(username): try: response = urllib_request.urlopen(api_url, None, 5) except urllib_error.URLError: - return '' # TODO Better error handling + return '' # TODO Better error handling return response.read().decode('utf-8') + def parse_json_data(json_data): """ Parse the given JSON data and return data about the user. """ try: data = json.loads(json_data) except ValueError: - return None # TODO Better error handling + return None # TODO Better error handling name = data['name'] location = data['location'] - endorsements = data['endorsements'] + endorsements = data['endorsements'] badges = data['badges'] return (name, location, endorsements, badges) + def parse_badges(raw_badges): """ - Parse the given list of dictionaries, interpret each as a + Parse the given list of dictionaries, interpret each as a CoderWall badge, and return a list of Badge objects. """ badges = [] for raw_badge in raw_badges: - badges.append(Badge(raw_badge['name'], - raw_badge['description'], raw_badge['badge'])) + badges.append(Badge( + raw_badge['name'], + raw_badge['description'], + raw_badge['badge'] + )) return badges + if __name__ == '__main__': if len(sys.argv) < 2: print('Usage: ' + sys.argv[0] + ' [username ...]') From a7448341c335d7e8220f3b2095c8623a1ac75164 Mon Sep 17 00:00:00 2001 From: Cameron Currie Date: Mon, 25 May 2015 20:22:07 -0500 Subject: [PATCH 13/19] Add unit tests --- coderwall_test.py | 87 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 coderwall_test.py diff --git a/coderwall_test.py b/coderwall_test.py new file mode 100644 index 0000000..ef34e07 --- /dev/null +++ b/coderwall_test.py @@ -0,0 +1,87 @@ +import sys +from nose import with_setup + +import coderwall +from coderwall import CoderWall + +real_get_json_data = coderwall.get_json_data + + +def get_mock_data(*username): + return """ + { + "name": "Cameron Currie", + "location": "Texas", + "endorsements": 7, + "badges": [ + { + "name": "Test Badge 1", + "description": "A test badge 1", + "badge": "http://test.badge1" + }, + { + "name": "Test Badge 2", + "description": "A test badge 2", + "badge": "http://test.badge2" + } + ] + } + """ + + +def setUp(): + coderwall.get_json_data = get_mock_data + + +def tearDown(): + coderwall.get_json_data = real_get_json_data + + +@with_setup(setUp, tearDown) +def test_parse_json_data(): + result = coderwall.parse_json_data(get_mock_data()) + + assert result[0] == 'Cameron Currie' + assert result[1] == 'Texas' + assert result[2] == 7 + + assert len(result[3]) == 2 + assert result[3][0]['name'] == 'Test Badge 1' + assert result[3][0]['badge'] == 'http://test.badge1' + + +@with_setup(setUp, tearDown) +def test_parse_badges(): + raw_badges = coderwall.parse_json_data(get_mock_data())[3] + badges = coderwall.parse_badges(raw_badges) + + assert len(badges) == 2 + assert badges[0].name == 'Test Badge 1' + assert badges[0].image_uri == 'http://test.badge1' + + +@with_setup(setUp, tearDown) +def test_coderwall_parsing(): + cwc = CoderWall('cwc') + + assert cwc.username == 'cwc' + assert cwc.location == 'Texas' + assert cwc.endorsements == 7 + + assert len(cwc.badges) == 2 + assert cwc.badges[0].name == 'Test Badge 1' + assert cwc.badges[0].image_uri == 'http://test.badge1' + + +@with_setup(setUp, tearDown) +def test_coderwall_to_str(): + cwc = CoderWall('cwc') + expStr2 = """Cameron Currie (cwc), Texas, Endorsed 7 times: [Badge(name=u'Test Badge 1',description=u'A test badge 1',image_uri=u'http://test.badge1'), Badge(name=u'Test Badge 2',description=u'A test badge 2',image_uri=u'http://test.badge2')]""" + expStr3 = """Cameron Currie (cwc), Texas, Endorsed 7 times: [Badge(name='Test Badge 1',description='A test badge 1',image_uri='http://test.badge1'), Badge(name='Test Badge 2',description='A test badge 2',image_uri='http://test.badge2')]""" + + if sys.version_info[0] >= 3: + expStr = expStr3 + else: + expStr = expStr2 + + assert str(cwc) == expStr, "str(cwc) was: %s, expected: %s" % (str(cwc), expStr) From d049846de82569cb3306a8438585e42707f7f7a0 Mon Sep 17 00:00:00 2001 From: Cameron Currie Date: Mon, 25 May 2015 20:25:04 -0500 Subject: [PATCH 14/19] Add .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d646835 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.pyc +__pycache__/ From 419b4a07d21c02b936988d5e4942ac5a96a8c0ea Mon Sep 17 00:00:00 2001 From: Cameron Currie Date: Mon, 25 May 2015 20:29:35 -0500 Subject: [PATCH 15/19] Update Travis config to test with nosetests --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 26a9776..fc92020 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,4 +5,4 @@ python: - "3.2" - "3.3" - "pypy" -script: python -m coderwall cwc +script: nosetests From 3e875c178818f455380538ea88e0c85f412452cc Mon Sep 17 00:00:00 2001 From: Cameron Currie Date: Tue, 26 May 2015 01:01:21 -0500 Subject: [PATCH 16/19] Update classifiers and Travis config for 3.4 --- .travis.yml | 2 ++ setup.py | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index fc92020..fa61552 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,5 +4,7 @@ python: - "2.7" - "3.2" - "3.3" + - "3.4" - "pypy" + - "pypy3" script: nosetests diff --git a/setup.py b/setup.py index d9f0c79..036c9fa 100644 --- a/setup.py +++ b/setup.py @@ -17,12 +17,17 @@ 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.2', 'Programming Language :: Python :: 3.3', + 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: Implementation :: PyPy', - 'Development Status :: 5 - Production/Stable', + 'Development Status :: 6 - Mature', 'License :: OSI Approved :: MIT License', 'Operating System :: OS Independent', 'Intended Audience :: Developers', - 'Topic :: Software Development :: Libraries :: Python Modules' + 'Topic :: Software Development :: Libraries :: Python Modules', + 'Topic :: Internet', + 'Topic :: Internet :: WWW/HTTP', + 'Environment :: Console', + 'Environment :: Web Environment' ], py_modules=['coderwall'] ) From b120bfc7a936b221a0e2bb0e29a453bb77416903 Mon Sep 17 00:00:00 2001 From: Cameron Currie Date: Tue, 26 May 2015 01:07:07 -0500 Subject: [PATCH 17/19] Release 1.3.0 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 036c9fa..3fbbf62 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='coderwall', - version='1.2.0', + version='1.3.0', author='Cameron Currie', author_email='me@cameroncurrie.net', url='http://github.com/cwc/coderwall-python', From 4acfb19fb17a1e16813174d4b34b45e84e82cc62 Mon Sep 17 00:00:00 2001 From: Cameron Currie Date: Thu, 1 Oct 2015 13:06:46 -0500 Subject: [PATCH 18/19] Add test-requirements.txt --- test-requirements.txt | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 test-requirements.txt diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000..31246d1 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,2 @@ +nose==1.3.7 +wheel==0.24.0 From 74172c7bae6542441e7ab4efb3200c2f35616ca7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 26 Dec 2022 19:47:46 +0000 Subject: [PATCH 19/19] Bump wheel from 0.24.0 to 0.38.1 Bumps [wheel](https://github.com/pypa/wheel) from 0.24.0 to 0.38.1. - [Release notes](https://github.com/pypa/wheel/releases) - [Changelog](https://github.com/pypa/wheel/blob/main/docs/news.rst) - [Commits](https://github.com/pypa/wheel/compare/0.24.0...0.38.1) --- updated-dependencies: - dependency-name: wheel dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- test-requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-requirements.txt b/test-requirements.txt index 31246d1..6b8408f 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,2 +1,2 @@ nose==1.3.7 -wheel==0.24.0 +wheel==0.38.1