Skip to content

Instantly share code, notes, and snippets.

@craffel
Created April 24, 2016 22:24
Show Gist options
  • Save craffel/fc79d952154e6c2d8efb007a09637077 to your computer and use it in GitHub Desktop.
Save craffel/fc79d952154e6c2d8efb007a09637077 to your computer and use it in GitHub Desktop.
Count your total contributions on GitHub of a certain filetype (a hack)
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import requests\n",
"import os\n",
"import subprocess\n",
"import tempfile\n",
"import shutil\n",
"import traceback"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"username = 'craffel'\n",
"extension = '.py'"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"alignment-search: +1569, -687\n",
"alignment-search-icassp2016: +0, -0\n",
"align_midi: +1007, -702\n",
"craffel.github.io: +60, -10\n",
"crucialpython: +450, -3\n",
"deepdish: +4, -15\n",
"dhs: +2838, -2037\n",
"djitw: +405, -108\n",
"feature-inversion: +741, -125\n",
"ff-attention: +373, -100\n",
"fnn_on_mi: +0, -0\n",
"Gooey: +1, -1\n",
"hickle: +118, -132\n",
"iclr2016feed: +0, -0\n",
"labrosa_website: +396, -101\n",
"Lasagne-tutorial: +3172, -2253\n",
"lattice-harp: +0, -0\n",
"librosa: +467, -109\n",
"live-sets: +0, -0\n",
"lstm_benchmarks: +432, -204\n",
"lstm_problems: +349, -45\n",
"madmom: +0, -0\n",
"median-filter: +38, -7\n",
"midi-dataset: +13049, -10428\n",
"midi-dataset-ismir: +0, -0\n",
"mir_eval: +10751, -9236\n",
"mir_eval-ismir: +1577, -704\n",
"mir_eval_service: +205, -61\n",
"music-evolution: +4316, -2170\n",
"nips_mmml_2015: +0, -0\n",
"nntools: +3529, -2302\n",
"paper_templates: +0, -0\n",
"performerSynchronization: +940, -6\n",
"pickle-chai-peanut-butter: +0, -0\n",
"pretty-midi: +4894, -2588\n",
"pruning_icassp2016: +0, -0\n",
"pse: +1937, -1445\n",
"python-midi: +2, -2\n",
"remixavier: +2733, -1598\n",
"rnntools: +499, -499\n",
"simple_spearmint: +537, -4\n",
"Snowball: +0, -0\n",
"Spearmint: +0, -0\n",
"spikegram-coding: +1426, -665\n",
"text_convnet: +9, -7\n",
"Theano: +78, -13\n",
"theano-tutorial: +0, -0\n",
"thesis: +0, -0\n",
"Total: 58902 added, 38367 removed, 20535 net\n"
]
}
],
"source": [
"original_dir = os.getcwd()\n",
"tempdir = tempfile.gettempdir()\n",
"os.chdir(tempdir)\n",
"total_added, total_removed = 0, 0\n",
"r = requests.get('https://api.github.com/users/{}/repos?per_page=100'.format(username))\n",
"for repository in r.json():\n",
" subprocess.check_output(['git', 'clone', repository['clone_url']])\n",
" try:\n",
" os.chdir(repository['name'])\n",
" command = ['git', 'log', '--author={}'.format(username),\n",
" '--pretty=tformat:', '--numstat', '-C']\n",
" repo_added, repo_removed = 0, 0\n",
" for line in subprocess.check_output(command).split('\\n'):\n",
" line = line.split('\\t')\n",
" if len(line) == 3:\n",
" added, removed, filename = line\n",
" if os.path.splitext(filename)[1] == extension:\n",
" repo_added += int(added)\n",
" repo_removed += int(removed)\n",
" print '{}: +{}, -{}'.format(repository['name'], repo_added, repo_removed)\n",
" total_added += repo_added\n",
" total_removed += repo_removed\n",
" except Exception as e:\n",
" print traceback.format_exc(e)\n",
" os.chdir(tempdir)\n",
" if os.path.exists(repository['name']):\n",
" shutil.rmtree(repository['name'])\n",
"print 'Total: {} added, {} removed, {} net'.format(\n",
" total_added, total_removed, total_added - total_removed)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment