Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix humans to work with new github api

  • Loading branch information...
commit b96636705dd638e95e5e8b201cc45bd80c9e79d8 1 parent 6d8f983
@groovecoder authored
View
3  apps/humans/cron.py
@@ -2,7 +2,8 @@
from humans.models import HumansTXT
+
@cronjobs.register
def humans_txt():
- humans = HumansTXT()
+ humans = HumansTXT()
humans.generate_file()
View
155 apps/humans/fixtures/contributors.json
@@ -1 +1,154 @@
-{"contributors":[{"name":"James Socol","company":"Mozilla","gravatar_id":"8371744716a9335eb3dcae228fd9d996","location":"Brooklyn, NY (NYC)","blog":"http://coffeeonthekeyboard.com/","contributions":444,"type":"User","login":"jsocol","email":"james@mozilla.com"},{"name":"Paul Craciunoiu","company":"SoWink","gravatar_id":"6fc085eaf76816eac513107778607b5b","location":"San Jose","blog":"http://embrangler.com","contributions":318,"type":"User","login":"pcraciunoiu","email":"paul@sowink.com"},{"name":"l.m.orchard","company":"0xDECAFBAD","gravatar_id":"2377f34a68801b861c3e54e1301f0dce","location":"Livonia, MI, USA","blog":"http://decafbad.com/blog/","contributions":300,"type":"User","login":"lmorchard","email":"l.m.orchard@pobox.com"},{"name":"ricky rosario","company":"Mozilla","gravatar_id":"00e30f0c3219349c80f3ff7aacc9d34a","location":"south florida","blog":"http://rickyrosario.com","contributions":280,"type":"User","login":"rlr"},{"name":"luke crouch","company":"mozilla","gravatar_id":"ec25d046746de3be33779256f6957d8f","location":"tulsa, ok","blog":"http://groovecoder.com","contributions":237,"type":"User","login":"groovecoder","email":"luke.crouch@gmail.com"},{"name":"Erik Rose","company":"Mozilla","gravatar_id":"73bfa51d6f44afed026160b59299faf2","location":"Mountain View, CA","blog":"http://www.ploneforeducation.com/","contributions":130,"type":"User","login":"erikrose","email":"erik@mozilla.com"},{"name":"Craig Cook","gravatar_id":"3b7f519c31ada9be3fb3bd4532df919c","location":"California","blog":"http://focalcurve.com","contributions":99,"type":"User","login":"craigcook"},{"name":"Joshua Gross","gravatar_id":"ac2bc9a2a1b2fa5a4eb2ab7d5c58029d","blog":"http://unwieldy.net","contributions":32,"type":"User","login":"endtwist","email":"josh [is at] unwieldy.net"},{"name":"Fred Wenzel","company":"Mozilla","gravatar_id":"e5de50a7b017e490940c7b12eb7de99f","location":"Mountain View, CA","blog":"http://fredericiana.com","contributions":31,"type":"User","login":"fwenzel","email":"fwenzel@mozilla.com"},{"name":"James Bennett","gravatar_id":"108534f65d8d2d7de6995973c1f49889","location":"Lawrence, Kansas, USA","blog":"http://www.b-list.org/","contributions":7,"type":"User","login":"ubernostrum","email":""},{"name":"Buddy Lindsey, Jr.","company":"Sourcehold.com","gravatar_id":"d5c7efa3f66d6fc8ef6750fa07558c8a","location":"Oklahoma","blog":"http://buddylindsey.com","contributions":5,"type":"User","login":"buddylindsey","email":"buddy@buddylindsey.com"},{"name":"Manuel Strehl","gravatar_id":"d4d55e6108bf1e879aca4afc00e6a1a0","location":"Germany","blog":"http://www.manuel-strehl.de","contributions":2,"type":"User","login":"Boldewyn","email":""},{"name":"Tanner","company":"TestWiki","gravatar_id":"b535900d4d649c41a0aef7d70aa83c43","location":"Iowa","blog":"tannermoz.wordpress.com","contributions":1,"type":"User","login":"pilif12p"},{"name":"Staś Małolepszy","company":"Mozilla","gravatar_id":"6c5e47150144fb3f7cdc61aa12ef9f7c","contributions":1,"type":"User","login":"stasm","email":"stas@mozilla.com"},{"name":"Connor Montgomery","gravatar_id":"f12ed6301268a1a8d40f292135e6bfca","location":"San Francisco, CA; St. Louis, MO","blog":"www.connormontgomery.com","contributions":1,"type":"User","login":"connormontgomery","email":"connor@connormontgomery.com"},{"gravatar_id":"54c4411c7ce75330abf7f18a265b83b4","contributions":1,"type":"User","login":"chengwang"}]}
+[
+ {
+ "login": "lmorchard",
+ "url": "https://api.github.com/users/lmorchard",
+ "gravatar_id": "2377f34a68801b861c3e54e1301f0dce",
+ "avatar_url": "https://secure.gravatar.com/avatar/2377f34a68801b861c3e54e1301f0dce?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
+ "id": 21687,
+ "contributions": 599
+ },
+ {
+ "login": "groovecoder",
+ "url": "https://api.github.com/users/groovecoder",
+ "gravatar_id": "ec25d046746de3be33779256f6957d8f",
+ "avatar_url": "https://secure.gravatar.com/avatar/ec25d046746de3be33779256f6957d8f?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
+ "id": 71928,
+ "contributions": 530
+ },
+ {
+ "login": "jsocol",
+ "url": "https://api.github.com/users/jsocol",
+ "gravatar_id": "8371744716a9335eb3dcae228fd9d996",
+ "avatar_url": "https://secure.gravatar.com/avatar/8371744716a9335eb3dcae228fd9d996?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
+ "id": 180459,
+ "contributions": 444
+ },
+ {
+ "login": "pcraciunoiu",
+ "url": "https://api.github.com/users/pcraciunoiu",
+ "gravatar_id": "8cac07b53b4220ede6e26a602d8b10c3",
+ "avatar_url": "https://secure.gravatar.com/avatar/8cac07b53b4220ede6e26a602d8b10c3?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
+ "id": 191195,
+ "contributions": 318
+ },
+ {
+ "login": "rlr",
+ "url": "https://api.github.com/users/rlr",
+ "gravatar_id": "00e30f0c3219349c80f3ff7aacc9d34a",
+ "avatar_url": "https://secure.gravatar.com/avatar/00e30f0c3219349c80f3ff7aacc9d34a?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
+ "id": 36629,
+ "contributions": 280
+ },
+ {
+ "login": "craigcook",
+ "url": "https://api.github.com/users/craigcook",
+ "gravatar_id": "3b7f519c31ada9be3fb3bd4532df919c",
+ "avatar_url": "https://secure.gravatar.com/avatar/3b7f519c31ada9be3fb3bd4532df919c?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
+ "id": 205591,
+ "contributions": 165
+ },
+ {
+ "login": "darkwing",
+ "url": "https://api.github.com/users/darkwing",
+ "gravatar_id": "e15d8725aa42ce94ff509dd9136284d8",
+ "avatar_url": "https://secure.gravatar.com/avatar/e15d8725aa42ce94ff509dd9136284d8?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
+ "id": 46655,
+ "contributions": 78
+ },
+ {
+ "login": "ubernostrum",
+ "url": "https://api.github.com/users/ubernostrum",
+ "gravatar_id": "108534f65d8d2d7de6995973c1f49889",
+ "avatar_url": "https://secure.gravatar.com/avatar/108534f65d8d2d7de6995973c1f49889?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
+ "id": 12384,
+ "contributions": 74
+ },
+ {
+ "login": "fwenzel",
+ "url": "https://api.github.com/users/fwenzel",
+ "gravatar_id": "e5de50a7b017e490940c7b12eb7de99f",
+ "avatar_url": "https://secure.gravatar.com/avatar/e5de50a7b017e490940c7b12eb7de99f?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
+ "id": 87232,
+ "contributions": 31
+ },
+ {
+ "login": "openjck",
+ "url": "https://api.github.com/users/openjck",
+ "gravatar_id": "990aba50a39806f6cb0f97e00ad5685c",
+ "avatar_url": "https://secure.gravatar.com/avatar/990aba50a39806f6cb0f97e00ad5685c?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
+ "id": 933396,
+ "contributions": 19
+ },
+ {
+ "login": "pmclanahan",
+ "url": "https://api.github.com/users/pmclanahan",
+ "gravatar_id": "f0287ea2cfd2cefcc61d774dc118a278",
+ "avatar_url": "https://secure.gravatar.com/avatar/f0287ea2cfd2cefcc61d774dc118a278?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
+ "id": 19934,
+ "contributions": 10
+ },
+ {
+ "login": "nickolay",
+ "url": "https://api.github.com/users/nickolay",
+ "gravatar_id": "ea331e778d54effc15b5fbc694bc8232",
+ "avatar_url": "https://secure.gravatar.com/avatar/ea331e778d54effc15b5fbc694bc8232?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
+ "id": 247067,
+ "contributions": 9
+ },
+ {
+ "login": "buddylindsey",
+ "url": "https://api.github.com/users/buddylindsey",
+ "gravatar_id": "d5c7efa3f66d6fc8ef6750fa07558c8a",
+ "avatar_url": "https://secure.gravatar.com/avatar/d5c7efa3f66d6fc8ef6750fa07558c8a?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
+ "id": 226303,
+ "contributions": 8
+ },
+ {
+ "login": "LucianU",
+ "url": "https://api.github.com/users/LucianU",
+ "gravatar_id": "b3074e1515db1a3d79acf5d954eac0d1",
+ "avatar_url": "https://secure.gravatar.com/avatar/b3074e1515db1a3d79acf5d954eac0d1?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
+ "id": 912849,
+ "contributions": 5
+ },
+ {
+ "login": "Boldewyn",
+ "url": "https://api.github.com/users/Boldewyn",
+ "gravatar_id": "d4d55e6108bf1e879aca4afc00e6a1a0",
+ "avatar_url": "https://secure.gravatar.com/avatar/d4d55e6108bf1e879aca4afc00e6a1a0?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
+ "id": 48738,
+ "contributions": 2
+ },
+ {
+ "login": "paulbooker",
+ "url": "https://api.github.com/users/paulbooker",
+ "gravatar_id": "9f29abeeb8e9ebba956e0f0c60d360d2",
+ "avatar_url": "https://secure.gravatar.com/avatar/9f29abeeb8e9ebba956e0f0c60d360d2?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
+ "id": 54085,
+ "contributions": 1
+ },
+ {
+ "login": "chengwang",
+ "url": "https://api.github.com/users/chengwang",
+ "gravatar_id": "54c4411c7ce75330abf7f18a265b83b4",
+ "avatar_url": "https://secure.gravatar.com/avatar/54c4411c7ce75330abf7f18a265b83b4?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
+ "id": 361172,
+ "contributions": 1
+ },
+ {
+ "login": "connor",
+ "url": "https://api.github.com/users/connor",
+ "gravatar_id": "f12ed6301268a1a8d40f292135e6bfca",
+ "avatar_url": "https://secure.gravatar.com/avatar/f12ed6301268a1a8d40f292135e6bfca?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
+ "id": 97697,
+ "contributions": 1
+ },
+ {
+ "login": "stasm",
+ "url": "https://api.github.com/users/stasm",
+ "gravatar_id": "6c5e47150144fb3f7cdc61aa12ef9f7c",
+ "avatar_url": "https://secure.gravatar.com/avatar/6c5e47150144fb3f7cdc61aa12ef9f7c?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
+ "id": 265818,
+ "contributions": 1
+ }
+]
View
16 apps/humans/models.py
@@ -2,23 +2,25 @@
import urllib
from django.conf import settings
-GITHUB_REPOS = "https://github.com/api/v2/json/repos/show/mozilla/kuma/contributors"
+GITHUB_REPOS = "https://api.github.com/repos/mozilla/kuma/contributors"
+
class Human:
def __init__(self):
self.name = None
self.website = None
+
class HumansTXT:
def generate_file(self):
githubbers = self.get_github(json.load(urllib.urlopen(GITHUB_REPOS)))
-
+
target = open("%s/humans.txt" % settings.HUMANSTXT_ROOT, 'w')
self.write_to_file(githubbers, target, "Contributors on Github")
target.close()
-
+
def write_to_file(self, humans, target, message):
target.write("%s \n" % message)
for h in humans:
@@ -32,13 +34,13 @@ def get_github(self, data=None):
raw_data = json.load(urllib.urlopen(GITHUB_REPOS))
else:
raw_data = data
-
+
humans = []
- for contributor in raw_data['contributors']:
+ for contributor in raw_data:
human = Human()
try:
human.name = contributor['name']
- except: # Github doesn't have a name if profile isn't filled out
+ except: # Github doesn't have a name if profile isn't filled out
human.name = contributor['login']
try:
@@ -49,5 +51,3 @@ def get_github(self, data=None):
humans.append(human)
return humans
-
-
View
16 apps/humans/tests.py
@@ -8,7 +8,7 @@
from django.test import TestCase
from os.path import dirname
from os.path import exists
-from nose.tools import assert_equal, with_setup, assert_false, eq_, ok_
+from nose.tools import assert_equal, ok_
import json
import fileinput
@@ -17,6 +17,7 @@
APP_DIR = dirname(__file__)
CONTRIBUTORS_JSON = "%s/fixtures/contributors.json" % APP_DIR
+
class HumansTest(TestCase):
def test_basic_get_github(self):
"""
@@ -25,7 +26,7 @@ def test_basic_get_github(self):
data = json.load(open(CONTRIBUTORS_JSON, 'rb'))
ht = HumansTXT()
humans = ht.get_github(data)
- assert_equal(len(humans), 16)
+ assert_equal(len(humans), 19)
def test_for_login_name_when_no_name(self):
"""
@@ -34,7 +35,7 @@ def test_for_login_name_when_no_name(self):
data = json.load(open(CONTRIBUTORS_JSON, 'rb'))
ht = HumansTXT()
humans = ht.get_github(data)
- human = Human()
+ human = Human()
for h in humans:
if h.name == "chengwang":
human = h
@@ -55,12 +56,12 @@ def test_write_to_file(self):
humans.append(human2)
ht = HumansTXT()
- ht.write_to_file(humans, target, "Banner Message")
+ ht.write_to_file(humans, target, "Banner Message")
ok_(True, exists("%s/tmp/humans.txt" % APP_DIR))

Had one small issue here, since my /vagrant/apps/humans/tmp/ directory didn't exist. Might want to have Vagrant create that dir, or use http://docs.python.org/library/tempfile.html

Not a big deal, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
-
- message = False
- name = False
+
+ message = False
+ name = False
for line in fileinput.input("%s/tmp/humans.txt" % APP_DIR):
if line == "Banner Message":
@@ -70,4 +71,3 @@ def test_write_to_file(self):
ok_(True, message)
ok_(True, name)
-
Please sign in to comment.
Something went wrong with that request. Please try again.