From be6bd58080d4ff02b9ef7a285bdd46cd8c8359c4 Mon Sep 17 00:00:00 2001 From: Jochen Kupperschmidt Date: Sun, 5 Jun 2016 22:21:27 +0200 Subject: [PATCH 01/25] Formatted with PEP 8 in mind. Inserted additional blank lines for readability. Ordered imports alphabetically. Removed unnecessary parentheses. --- gitfiti.py | 272 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 165 insertions(+), 107 deletions(-) diff --git a/gitfiti.py b/gitfiti.py index 6dba15365..7f2c67864 100755 --- a/gitfiti.py +++ b/gitfiti.py @@ -7,14 +7,14 @@ gitfiti noun : Carefully crafted graffiti in a github commit history calendar - """ import datetime -import math import itertools -import urllib2 import json +import math +import urllib2 + TITLE = ''' _ __ _____ __ _ @@ -25,101 +25,116 @@ TITLE = ''' /____/ ''' + KITTY = [ -[0,0,0,4,0,0,0,0,4,0,0,0], -[0,0,4,2,4,4,4,4,2,4,0,0], -[0,0,4,2,2,2,2,2,2,4,0,0], -[2,2,4,2,4,2,2,4,2,4,2,2], -[0,0,4,2,2,3,3,2,2,4,0,0], -[2,2,4,2,2,2,2,2,2,4,2,2], -[0,0,0,3,4,4,4,4,3,0,0,0]] + [0,0,0,4,0,0,0,0,4,0,0,0], + [0,0,4,2,4,4,4,4,2,4,0,0], + [0,0,4,2,2,2,2,2,2,4,0,0], + [2,2,4,2,4,2,2,4,2,4,2,2], + [0,0,4,2,2,3,3,2,2,4,0,0], + [2,2,4,2,2,2,2,2,2,4,2,2], + [0,0,0,3,4,4,4,4,3,0,0,0], +] ONEUP = [ -[0,4,4,4,4,4,4,4,0], -[4,3,2,2,1,2,2,3,4], -[4,2,2,1,1,1,2,2,4], -[4,3,4,4,4,4,4,3,4], -[4,4,1,4,1,4,1,4,4], -[0,4,1,1,1,1,1,4,0], -[0,0,4,4,4,4,4,0,0]] + [0,4,4,4,4,4,4,4,0], + [4,3,2,2,1,2,2,3,4], + [4,2,2,1,1,1,2,2,4], + [4,3,4,4,4,4,4,3,4], + [4,4,1,4,1,4,1,4,4], + [0,4,1,1,1,1,1,4,0], + [0,0,4,4,4,4,4,0,0], +] ONEUP2 = [ -[0,0,4,4,4,4,4,4,4,0,0], -[0,4,2,2,1,1,1,2,2,4,0], -[4,3,2,2,1,1,1,2,2,3,4], -[4,3,3,4,4,4,4,4,3,3,4], -[0,4,4,1,4,1,4,1,4,4,0], -[0,0,4,1,1,1,1,1,4,0,0], -[0,0,0,4,4,4,4,4,0,0,0]] + [0,0,4,4,4,4,4,4,4,0,0], + [0,4,2,2,1,1,1,2,2,4,0], + [4,3,2,2,1,1,1,2,2,3,4], + [4,3,3,4,4,4,4,4,3,3,4], + [0,4,4,1,4,1,4,1,4,4,0], + [0,0,4,1,1,1,1,1,4,0,0], + [0,0,0,4,4,4,4,4,0,0,0], +] HACKERSCHOOL = [ -[4,4,4,4,4,4], -[4,3,3,3,3,4], -[4,1,3,3,1,4], -[4,3,3,3,3,4], -[4,4,4,4,4,4], -[0,0,4,4,0,0], -[4,4,4,4,4,4]] + [4,4,4,4,4,4], + [4,3,3,3,3,4], + [4,1,3,3,1,4], + [4,3,3,3,3,4], + [4,4,4,4,4,4], + [0,0,4,4,0,0], + [4,4,4,4,4,4], +] OCTOCAT = [ -[0,0,0,4,0,0,0,4,0], -[0,0,4,4,4,4,4,4,4], -[0,0,4,1,3,3,3,1,4], -[4,0,3,4,3,3,3,4,3], -[0,4,0,0,4,4,4,0,0], -[0,0,4,4,4,4,4,4,4], -[0,0,4,0,4,0,4,0,4]] + [0,0,0,4,0,0,0,4,0], + [0,0,4,4,4,4,4,4,4], + [0,0,4,1,3,3,3,1,4], + [4,0,3,4,3,3,3,4,3], + [0,4,0,0,4,4,4,0,0], + [0,0,4,4,4,4,4,4,4], + [0,0,4,0,4,0,4,0,4], +] OCTOCAT2 = [ -[0,0,4,0,0,4,0], -[0,4,4,4,4,4,4], -[0,4,1,3,3,1,4], -[0,4,4,4,4,4,4], -[4,0,0,4,4,0,0], -[0,4,4,4,4,4,0], -[0,0,0,4,4,4,0]] + [0,0,4,0,0,4,0], + [0,4,4,4,4,4,4], + [0,4,1,3,3,1,4], + [0,4,4,4,4,4,4], + [4,0,0,4,4,0,0], + [0,4,4,4,4,4,0], + [0,0,0,4,4,4,0], +] HELLO = [ -[0,1,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,4], -[0,2,0,0,0,0,0,0,0,2,0,2,0,0,0,0,0,4], -[0,3,3,3,0,2,3,3,0,3,0,3,0,1,3,1,0,3], -[0,4,0,4,0,4,0,4,0,4,0,4,0,4,0,4,0,3], -[0,3,0,3,0,3,3,3,0,3,0,3,0,3,0,3,0,2], -[0,2,0,2,0,2,0,0,0,2,0,2,0,2,0,2,0,0], -[0,1,0,1,0,1,1,1,0,1,0,1,0,1,1,1,0,4]] + [0,1,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,4], + [0,2,0,0,0,0,0,0,0,2,0,2,0,0,0,0,0,4], + [0,3,3,3,0,2,3,3,0,3,0,3,0,1,3,1,0,3], + [0,4,0,4,0,4,0,4,0,4,0,4,0,4,0,4,0,3], + [0,3,0,3,0,3,3,3,0,3,0,3,0,3,0,3,0,2], + [0,2,0,2,0,2,0,0,0,2,0,2,0,2,0,2,0,0], + [0,1,0,1,0,1,1,1,0,1,0,1,0,1,1,1,0,4], +] HIREME = [ -[1,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], -[2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], -[3,3,3,0,2,0,3,3,3,0,2,3,3,0,0,3,3,0,3,0,0,2,3,3], -[4,0,4,0,4,0,4,0,0,0,4,0,4,0,0,4,0,4,0,4,0,4,0,4], -[3,0,3,0,3,0,3,0,0,0,3,3,3,0,0,3,0,3,0,3,0,3,3,3], -[2,0,2,0,2,0,2,0,0,0,2,0,0,0,0,2,0,2,0,2,0,2,0,0], -[1,0,1,0,1,0,1,0,0,0,1,1,1,0,0,1,0,1,0,1,0,1,1,1]] + [1,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], + [2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], + [3,3,3,0,2,0,3,3,3,0,2,3,3,0,0,3,3,0,3,0,0,2,3,3], + [4,0,4,0,4,0,4,0,0,0,4,0,4,0,0,4,0,4,0,4,0,4,0,4], + [3,0,3,0,3,0,3,0,0,0,3,3,3,0,0,3,0,3,0,3,0,3,3,3], + [2,0,2,0,2,0,2,0,0,0,2,0,0,0,0,2,0,2,0,2,0,2,0,0], + [1,0,1,0,1,0,1,0,0,0,1,1,1,0,0,1,0,1,0,1,0,1,1,1], +] + ASCII_TO_NUMBER = { '_': 0, '_': 1, '~': 2, '=': 3, - '*': 4 + '*': 4, } + def str_to_sprite(content): # Break out lines and filter any excess lines = content.split('\n') def is_empty_line(line): return len(line) != 0 lines = filter(is_empty_line, lines) + # Break up lines into each character split_lines = map(list, lines) + # Replace each character with its numeric equivalent for line in split_lines: for index, char in enumerate(line): line[index] = ASCII_TO_NUMBER.get(char, 0) + # Return the formatted str return split_lines + ONEUP_STR = str_to_sprite(""" ******* *=~~-~~=* @@ -130,22 +145,25 @@ ONEUP_STR = str_to_sprite(""" ***** """) + IMAGES = { -'kitty': KITTY, -'oneup':ONEUP, -'oneup2':ONEUP2, -'hackerschool':HACKERSCHOOL, -'octocat':OCTOCAT, -'octocat2':OCTOCAT2, -'hello':HELLO, -'hireme':HIREME, -'oneup_str':ONEUP_STR + 'kitty': KITTY, + 'oneup': ONEUP, + 'oneup2': ONEUP2, + 'hackerschool': HACKERSCHOOL, + 'octocat': OCTOCAT, + 'octocat2': OCTOCAT2, + 'hello': HELLO, + 'hireme': HIREME, + 'oneup_str': ONEUP_STR, } + def load_images(img_names): """loads user images from given file(s)""" if img_names[0] == '': return dict() + for image_name in img_names: img = open(image_name) loaded_imgs = {} @@ -158,61 +176,78 @@ def load_images(img_names): img_line = img.readline() if img_line == '': break + img_line.replace('\n', '') - if(img_line[0] == ':'): + if img_line[0] == ':': loaded_imgs[name] = json.loads(img_list) name = img_line[1:] img_list = '' else: img_list += img_line + loaded_imgs[name] = json.loads(img_list) + return loaded_imgs + def get_calendar(username, base_url='https://github.com/'): """retrieves the github commit calendar data for a username""" base_url = base_url + 'users/' + username + try: url = base_url + '/contributions' page = urllib2.urlopen(url) - except (urllib2.HTTPError,urllib2.URLError) as e: - print ("There was a problem fetching data from {0}".format(url)) - print (e) + except (urllib2.HTTPError, urllib2.URLError) as e: + print("There was a problem fetching data from {0}".format(url)) + print(e) raise SystemExit + return page.readlines() + def max_commits(input): """finds the highest number of commits in one day""" output = set() + for line in input: for day in line.split(): if "data-count=" in day: commit = day.split('=')[1] commit = commit.strip('"') output.add(int(commit)) + output = list(output) output.sort() output.reverse() return output[0] + def multiplier(max_commits): """calculates a multiplier to scale github colors to commit history""" - m = max_commits/4.0 - if m == 0: return 1 + m = max_commits / 4.0 + + if m == 0: + return 1 + m = math.ceil(m) m = int(m) return m + def get_start_date(): """returns a datetime object for the first sunday after one year ago today at 12:00 noon""" d = datetime.datetime.today() - date = datetime.datetime(d.year-1, d.month, d.day, 12) + date = datetime.datetime(d.year - 1, d.month, d.day, 12) weekday = datetime.datetime.weekday(date) + while weekday < 6: date = date + datetime.timedelta(1) weekday = datetime.datetime.weekday(date) + return date + def date_gen(start_date, offset=0): """generator that returns the next date, requires a datetime object as input. The offset is in weeks""" @@ -220,23 +255,30 @@ def date_gen(start_date, offset=0): for i in itertools.count(start): yield start_date + datetime.timedelta(i) + def values_in_date_order(image, multiplier=1): height = 7 width = len(image[0]) + for w in range(width): for h in range(height): - yield image[h][w]*multiplier + yield image[h][w] * multiplier + def commit(content, commitdate): - template = ("""echo {0} >> gitfiti\n""" - """GIT_AUTHOR_DATE={1} GIT_COMMITTER_DATE={2} """ - """git commit -a -m "gitfiti" > /dev/null\n""") + template = ( + """echo {0} >> gitfiti\n""" + """GIT_AUTHOR_DATE={1} GIT_COMMITTER_DATE={2} """ + """git commit -a -m "gitfiti" > /dev/null\n""" + ) return template.format(content, commitdate.isoformat(), commitdate.isoformat()) + def fake_it(image, start_date, username, repo, offset=0, multiplier=1, - git_url='git@github.com'): - template = ('#!/bin/bash\n' + git_url='git@github.com'): + template = ( + '#!/bin/bash\n' 'REPO={0}\n' 'git init $REPO\n' 'cd $REPO\n' @@ -247,66 +289,80 @@ def fake_it(image, start_date, username, repo, offset=0, multiplier=1, '{1}\n' 'git remote add origin {2}:{3}/$REPO.git\n' 'git pull\n' - 'git push -u origin master\n') + 'git push -u origin master\n' + ) + strings = [] for value, date in zip(values_in_date_order(image, multiplier), date_gen(start_date, offset)): for i in range(value): strings.append(commit(i, date)) + return template.format(repo, "".join(strings), git_url, username) + def save(output, filename): """Saves the list to a given filename""" f = open(filename, "w") f.write(output) f.close() + def main(): - print (TITLE) - print ("Enter github url") + print(TITLE) + + print("Enter github url") ghe = raw_input("Enter nothing for https://github.com/ to be used: ") - print ('Enter your github username:') + + print('Enter your github username:') username = raw_input(">") + if not ghe: git_base = "https://github.com/" cal = get_calendar(username) else: - cal = get_calendar(username,base_url=ghe) + cal = get_calendar(username, base_url=ghe) git_base = ghe + m = multiplier(max_commits(cal)) - print ('Enter name of the repo to be used by gitfiti:') + print('Enter name of the repo to be used by gitfiti:') repo = raw_input(">") - print ('Enter the number of weeks to offset the image (from the left):') + print('Enter the number of weeks to offset the image (from the left):') offset = raw_input(">") + if not offset.strip(): offset = 0 else: offset = int(offset) - print ('By default gitfiti.py matches the darkest pixel to the highest\n' - 'number of commits found in your github commit/activity calendar,\n' - '\n' - 'Currently this is : {0} commits\n' - '\n' - 'Enter the word "gitfiti" to exceed your max\n' - '(this option generates WAY more commits)\n' - 'Any other input will cause the default matching behavior' - ).format(max_commits(cal)) + print(( + 'By default gitfiti.py matches the darkest pixel to the highest\n' + 'number of commits found in your github commit/activity calendar,\n' + '\n' + 'Currently this is: {0} commits\n' + '\n' + 'Enter the word "gitfiti" to exceed your max\n' + '(this option generates WAY more commits)\n' + 'Any other input will cause the default matching behavior' + ).format(max_commits(cal))) match = raw_input(">") + if match == "gitfiti": match = m else: match = 1 - print ('enter file(s) to load images from (blank if not applicable)') + print('enter file(s) to load images from (blank if not applicable)') img_names = raw_input(">").split(' ') + images = dict(IMAGES, **load_images(img_names)) - print ('enter the image name to gitfiti') - print ('images: ' + ", ".join(images.keys())) + print('enter the image name to gitfiti') + print('images: ' + ", ".join(images.keys())) image = raw_input(">") + if not image: image = IMAGES['kitty'] else: @@ -314,17 +370,19 @@ def main(): image = images[image] except: image = IMAGES['kitty'] + if not ghe: - output = fake_it(image, get_start_date(), username, repo, offset, - m*match) + output = fake_it(image, get_start_date(), username, repo, + offset, m * match) else: git_url = raw_input("Enter git url like git@site.github.com: ") - output = fake_it(image, get_start_date(), username, repo, offset, - m*match,git_url=git_url) + output = fake_it(image, get_start_date(), username, repo, + offset, m * match, git_url=git_url) save(output, 'gitfiti.sh') - print ('gitfiti.sh saved.') - print ('Create a new(!) repo at: {0}new and run it.'.format(git_base)) + print('gitfiti.sh saved.') + print('Create a new(!) repo at: {0}new and run it.'.format(git_base)) + if __name__ == '__main__': main() From e1b2657ff022c959cc10146c6d50a95e11527c05 Mon Sep 17 00:00:00 2001 From: Jochen Kupperschmidt Date: Sun, 5 Jun 2016 22:24:48 +0200 Subject: [PATCH 02/25] Open file via `with` statement so it gets closed automatically. --- gitfiti.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/gitfiti.py b/gitfiti.py index 7f2c67864..f2459d93d 100755 --- a/gitfiti.py +++ b/gitfiti.py @@ -303,9 +303,8 @@ def fake_it(image, start_date, username, repo, offset=0, multiplier=1, def save(output, filename): """Saves the list to a given filename""" - f = open(filename, "w") - f.write(output) - f.close() + with open(filename, "w") as f: + f.write(output) def main(): From b717414e7bdfe759efa7345653105c359f63155a Mon Sep 17 00:00:00 2001 From: Jochen Kupperschmidt Date: Sun, 5 Jun 2016 22:26:30 +0200 Subject: [PATCH 03/25] Import the `datetime` and `timedelta` classes from the `datetime` package without having to fully qualify their uses. --- gitfiti.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/gitfiti.py b/gitfiti.py index f2459d93d..871f0017c 100755 --- a/gitfiti.py +++ b/gitfiti.py @@ -9,7 +9,7 @@ gitfiti noun : Carefully crafted graffiti in a github commit history calendar """ -import datetime +from datetime import datetime, timedelta import itertools import json import math @@ -237,13 +237,13 @@ def multiplier(max_commits): def get_start_date(): """returns a datetime object for the first sunday after one year ago today at 12:00 noon""" - d = datetime.datetime.today() - date = datetime.datetime(d.year - 1, d.month, d.day, 12) - weekday = datetime.datetime.weekday(date) + d = datetime.today() + date = datetime(d.year - 1, d.month, d.day, 12) + weekday = datetime.weekday(date) while weekday < 6: - date = date + datetime.timedelta(1) - weekday = datetime.datetime.weekday(date) + date = date + timedelta(1) + weekday = datetime.weekday(date) return date @@ -253,7 +253,7 @@ def date_gen(start_date, offset=0): input. The offset is in weeks""" start = offset * 7 for i in itertools.count(start): - yield start_date + datetime.timedelta(i) + yield start_date + timedelta(i) def values_in_date_order(image, multiplier=1): From a76dd860f302dac91202e2c4e9c4aec41f7d1089 Mon Sep 17 00:00:00 2001 From: Jochen Kupperschmidt Date: Sun, 5 Jun 2016 22:34:19 +0200 Subject: [PATCH 04/25] Use string literal delimiters consistently (triple double-quotes for docstrings, [triple] single quotes for everything else where feasible). --- gitfiti.py | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/gitfiti.py b/gitfiti.py index 871f0017c..88e6ebe8e 100755 --- a/gitfiti.py +++ b/gitfiti.py @@ -135,7 +135,7 @@ def str_to_sprite(content): return split_lines -ONEUP_STR = str_to_sprite(""" +ONEUP_STR = str_to_sprite(''' ******* *=~~-~~=* *~~---~~* @@ -143,7 +143,7 @@ ONEUP_STR = str_to_sprite(""" **-*-*-** *-----* ***** -""") +''') IMAGES = { @@ -198,7 +198,7 @@ def get_calendar(username, base_url='https://github.com/'): url = base_url + '/contributions' page = urllib2.urlopen(url) except (urllib2.HTTPError, urllib2.URLError) as e: - print("There was a problem fetching data from {0}".format(url)) + print('There was a problem fetching data from {0}'.format(url)) print(e) raise SystemExit @@ -211,7 +211,7 @@ def max_commits(input): for line in input: for day in line.split(): - if "data-count=" in day: + if 'data-count=' in day: commit = day.split('=')[1] commit = commit.strip('"') output.add(int(commit)) @@ -267,9 +267,9 @@ def values_in_date_order(image, multiplier=1): def commit(content, commitdate): template = ( - """echo {0} >> gitfiti\n""" - """GIT_AUTHOR_DATE={1} GIT_COMMITTER_DATE={2} """ - """git commit -a -m "gitfiti" > /dev/null\n""" + '''echo {0} >> gitfiti\n''' + '''GIT_AUTHOR_DATE={1} GIT_COMMITTER_DATE={2} ''' + '''git commit -a -m "gitfiti" > /dev/null\n''' ) return template.format(content, commitdate.isoformat(), commitdate.isoformat()) @@ -298,26 +298,26 @@ def fake_it(image, start_date, username, repo, offset=0, multiplier=1, for i in range(value): strings.append(commit(i, date)) - return template.format(repo, "".join(strings), git_url, username) + return template.format(repo, ''.join(strings), git_url, username) def save(output, filename): """Saves the list to a given filename""" - with open(filename, "w") as f: + with open(filename, 'w') as f: f.write(output) def main(): print(TITLE) - print("Enter github url") - ghe = raw_input("Enter nothing for https://github.com/ to be used: ") + print('Enter github url') + ghe = raw_input('Enter nothing for https://github.com/ to be used: ') print('Enter your github username:') - username = raw_input(">") + username = raw_input('>') if not ghe: - git_base = "https://github.com/" + git_base = 'https://github.com/' cal = get_calendar(username) else: cal = get_calendar(username, base_url=ghe) @@ -326,10 +326,10 @@ def main(): m = multiplier(max_commits(cal)) print('Enter name of the repo to be used by gitfiti:') - repo = raw_input(">") + repo = raw_input('>') print('Enter the number of weeks to offset the image (from the left):') - offset = raw_input(">") + offset = raw_input('>') if not offset.strip(): offset = 0 @@ -346,21 +346,21 @@ def main(): '(this option generates WAY more commits)\n' 'Any other input will cause the default matching behavior' ).format(max_commits(cal))) - match = raw_input(">") + match = raw_input('>') - if match == "gitfiti": + if match == 'gitfiti': match = m else: match = 1 print('enter file(s) to load images from (blank if not applicable)') - img_names = raw_input(">").split(' ') + img_names = raw_input('>').split(' ') images = dict(IMAGES, **load_images(img_names)) print('enter the image name to gitfiti') - print('images: ' + ", ".join(images.keys())) - image = raw_input(">") + print('images: ' + ', '.join(images.keys())) + image = raw_input('>') if not image: image = IMAGES['kitty'] @@ -374,7 +374,7 @@ def main(): output = fake_it(image, get_start_date(), username, repo, offset, m * match) else: - git_url = raw_input("Enter git url like git@site.github.com: ") + git_url = raw_input('Enter git url like git@site.github.com: ') output = fake_it(image, get_start_date(), username, repo, offset, m * match, git_url=git_url) From c2870bb4ec7f849c920130cdac633fcff6124177 Mon Sep 17 00:00:00 2001 From: Jochen Kupperschmidt Date: Sun, 5 Jun 2016 22:39:52 +0200 Subject: [PATCH 05/25] Clarified variable name. --- gitfiti.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gitfiti.py b/gitfiti.py index 88e6ebe8e..7f7e50c8a 100755 --- a/gitfiti.py +++ b/gitfiti.py @@ -237,8 +237,8 @@ def multiplier(max_commits): def get_start_date(): """returns a datetime object for the first sunday after one year ago today at 12:00 noon""" - d = datetime.today() - date = datetime(d.year - 1, d.month, d.day, 12) + today = datetime.today() + date = datetime(today.year - 1, today.month, today.day, 12) weekday = datetime.weekday(date) while weekday < 6: From c7ffdcde4de8b62965d3b9b5e5201e6c3af9b31d Mon Sep 17 00:00:00 2001 From: Jochen Kupperschmidt Date: Sun, 5 Jun 2016 22:44:53 +0200 Subject: [PATCH 06/25] Renamed function argument to reveal its meaning and to not override the built-in `input` function. --- gitfiti.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gitfiti.py b/gitfiti.py index 7f7e50c8a..66a4fbf4a 100755 --- a/gitfiti.py +++ b/gitfiti.py @@ -205,11 +205,11 @@ def get_calendar(username, base_url='https://github.com/'): return page.readlines() -def max_commits(input): +def max_commits(calendar): """finds the highest number of commits in one day""" output = set() - for line in input: + for line in calendar: for day in line.split(): if 'data-count=' in day: commit = day.split('=')[1] From bb31c8eb46a511ba9a29641417c0020808843618 Mon Sep 17 00:00:00 2001 From: Jochen Kupperschmidt Date: Sun, 5 Jun 2016 22:46:25 +0200 Subject: [PATCH 07/25] Create empty dict via literal syntax instead of function call. --- gitfiti.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitfiti.py b/gitfiti.py index 66a4fbf4a..54fa9a699 100755 --- a/gitfiti.py +++ b/gitfiti.py @@ -162,7 +162,7 @@ IMAGES = { def load_images(img_names): """loads user images from given file(s)""" if img_names[0] == '': - return dict() + return {} for image_name in img_names: img = open(image_name) From 60c2aae15fc2331ecd15d0dd192b09441a81eda3 Mon Sep 17 00:00:00 2001 From: Jochen Kupperschmidt Date: Sun, 5 Jun 2016 22:52:06 +0200 Subject: [PATCH 08/25] Fixed name and acronym case. --- gitfiti.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/gitfiti.py b/gitfiti.py index 54fa9a699..a3ab4f946 100755 --- a/gitfiti.py +++ b/gitfiti.py @@ -6,7 +6,7 @@ """ gitfiti -noun : Carefully crafted graffiti in a github commit history calendar +noun : Carefully crafted graffiti in a GitHub commit history calendar """ from datetime import datetime, timedelta @@ -191,7 +191,7 @@ def load_images(img_names): def get_calendar(username, base_url='https://github.com/'): - """retrieves the github commit calendar data for a username""" + """retrieves the GitHub commit calendar data for a username""" base_url = base_url + 'users/' + username try: @@ -223,7 +223,7 @@ def max_commits(calendar): def multiplier(max_commits): - """calculates a multiplier to scale github colors to commit history""" + """calculates a multiplier to scale GitHub colors to commit history""" m = max_commits / 4.0 if m == 0: @@ -310,10 +310,10 @@ def save(output, filename): def main(): print(TITLE) - print('Enter github url') + print('Enter GitHub URL') ghe = raw_input('Enter nothing for https://github.com/ to be used: ') - print('Enter your github username:') + print('Enter your GitHub username:') username = raw_input('>') if not ghe: @@ -338,7 +338,7 @@ def main(): print(( 'By default gitfiti.py matches the darkest pixel to the highest\n' - 'number of commits found in your github commit/activity calendar,\n' + 'number of commits found in your GitHub commit/activity calendar,\n' '\n' 'Currently this is: {0} commits\n' '\n' @@ -374,7 +374,7 @@ def main(): output = fake_it(image, get_start_date(), username, repo, offset, m * match) else: - git_url = raw_input('Enter git url like git@site.github.com: ') + git_url = raw_input('Enter Git URL like git@site.github.com: ') output = fake_it(image, get_start_date(), username, repo, offset, m * match, git_url=git_url) From 822048909b8b49170503d465c5b2e34cceed6f19 Mon Sep 17 00:00:00 2001 From: Jochen Kupperschmidt Date: Sun, 5 Jun 2016 23:03:32 +0200 Subject: [PATCH 09/25] Extracted function to request user input. --- gitfiti.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/gitfiti.py b/gitfiti.py index a3ab4f946..e632ffc43 100755 --- a/gitfiti.py +++ b/gitfiti.py @@ -307,14 +307,19 @@ def save(output, filename): f.write(output) +def request_user_input(prompt='> '): + """Request input from the user and return what has been entered.""" + return raw_input(prompt) + + def main(): print(TITLE) print('Enter GitHub URL') - ghe = raw_input('Enter nothing for https://github.com/ to be used: ') + ghe = request_user_input('Enter nothing for https://github.com/ to be used: ') print('Enter your GitHub username:') - username = raw_input('>') + username = request_user_input() if not ghe: git_base = 'https://github.com/' @@ -326,10 +331,10 @@ def main(): m = multiplier(max_commits(cal)) print('Enter name of the repo to be used by gitfiti:') - repo = raw_input('>') + repo = request_user_input() print('Enter the number of weeks to offset the image (from the left):') - offset = raw_input('>') + offset = request_user_input() if not offset.strip(): offset = 0 @@ -346,7 +351,7 @@ def main(): '(this option generates WAY more commits)\n' 'Any other input will cause the default matching behavior' ).format(max_commits(cal))) - match = raw_input('>') + match = request_user_input() if match == 'gitfiti': match = m @@ -354,13 +359,13 @@ def main(): match = 1 print('enter file(s) to load images from (blank if not applicable)') - img_names = raw_input('>').split(' ') + img_names = request_user_input().split(' ') images = dict(IMAGES, **load_images(img_names)) print('enter the image name to gitfiti') print('images: ' + ', '.join(images.keys())) - image = raw_input('>') + image = request_user_input() if not image: image = IMAGES['kitty'] @@ -374,7 +379,7 @@ def main(): output = fake_it(image, get_start_date(), username, repo, offset, m * match) else: - git_url = raw_input('Enter Git URL like git@site.github.com: ') + git_url = request_user_input('Enter Git URL like git@site.github.com: ') output = fake_it(image, get_start_date(), username, repo, offset, m * match, git_url=git_url) From bdcdd8f137ace83a10be5265e0e3758d95c6d75f Mon Sep 17 00:00:00 2001 From: Jochen Kupperschmidt Date: Sun, 5 Jun 2016 23:06:54 +0200 Subject: [PATCH 10/25] Selectively employ one-liner conditionals for brevity. --- gitfiti.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/gitfiti.py b/gitfiti.py index e632ffc43..340369064 100755 --- a/gitfiti.py +++ b/gitfiti.py @@ -336,10 +336,7 @@ def main(): print('Enter the number of weeks to offset the image (from the left):') offset = request_user_input() - if not offset.strip(): - offset = 0 - else: - offset = int(offset) + offset = int(offset) if offset.strip() else 0 print(( 'By default gitfiti.py matches the darkest pixel to the highest\n' @@ -353,10 +350,7 @@ def main(): ).format(max_commits(cal))) match = request_user_input() - if match == 'gitfiti': - match = m - else: - match = 1 + match = m if (match == 'gitfiti') else 1 print('enter file(s) to load images from (blank if not applicable)') img_names = request_user_input().split(' ') From 73361c64d9ea09c2de681b5b14db8643914ef887 Mon Sep 17 00:00:00 2001 From: Jochen Kupperschmidt Date: Sun, 5 Jun 2016 23:11:29 +0200 Subject: [PATCH 11/25] Prefix function names with verbs to avoid confusion (or upcoming conflicts) with variables. --- gitfiti.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/gitfiti.py b/gitfiti.py index 340369064..ed8d128bc 100755 --- a/gitfiti.py +++ b/gitfiti.py @@ -205,7 +205,7 @@ def get_calendar(username, base_url='https://github.com/'): return page.readlines() -def max_commits(calendar): +def find_max_commits(calendar): """finds the highest number of commits in one day""" output = set() @@ -222,7 +222,7 @@ def max_commits(calendar): return output[0] -def multiplier(max_commits): +def calculate_multiplier(max_commits): """calculates a multiplier to scale GitHub colors to commit history""" m = max_commits / 4.0 @@ -248,7 +248,7 @@ def get_start_date(): return date -def date_gen(start_date, offset=0): +def generate_next_dates(start_date, offset=0): """generator that returns the next date, requires a datetime object as input. The offset is in weeks""" start = offset * 7 @@ -256,7 +256,7 @@ def date_gen(start_date, offset=0): yield start_date + timedelta(i) -def values_in_date_order(image, multiplier=1): +def generate_values_in_date_order(image, multiplier=1): height = 7 width = len(image[0]) @@ -293,8 +293,8 @@ def fake_it(image, start_date, username, repo, offset=0, multiplier=1, ) strings = [] - for value, date in zip(values_in_date_order(image, multiplier), - date_gen(start_date, offset)): + for value, date in zip(generate_values_in_date_order(image, multiplier), + generate_next_dates(start_date, offset)): for i in range(value): strings.append(commit(i, date)) @@ -328,7 +328,7 @@ def main(): cal = get_calendar(username, base_url=ghe) git_base = ghe - m = multiplier(max_commits(cal)) + m = calculate_multiplier(find_max_commits(cal)) print('Enter name of the repo to be used by gitfiti:') repo = request_user_input() @@ -347,7 +347,7 @@ def main(): 'Enter the word "gitfiti" to exceed your max\n' '(this option generates WAY more commits)\n' 'Any other input will cause the default matching behavior' - ).format(max_commits(cal))) + ).format(find_max_commits(cal))) match = request_user_input() match = m if (match == 'gitfiti') else 1 From 68a1fb2b031bcd605e027cc45cf1d4ee3637211e Mon Sep 17 00:00:00 2001 From: Jochen Kupperschmidt Date: Sun, 5 Jun 2016 23:20:31 +0200 Subject: [PATCH 12/25] Extracted "constant" for GitHub base URL. --- gitfiti.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/gitfiti.py b/gitfiti.py index ed8d128bc..a84c5295b 100755 --- a/gitfiti.py +++ b/gitfiti.py @@ -16,6 +16,9 @@ import math import urllib2 +GITHUB_BASE_URL = 'https://github.com/' + + TITLE = ''' _ __ _____ __ _ ____ _(_) /_/ __(_) /_(_) @@ -190,7 +193,7 @@ def load_images(img_names): return loaded_imgs -def get_calendar(username, base_url='https://github.com/'): +def get_calendar(username, base_url=GITHUB_BASE_URL): """retrieves the GitHub commit calendar data for a username""" base_url = base_url + 'users/' + username @@ -316,13 +319,14 @@ def main(): print(TITLE) print('Enter GitHub URL') - ghe = request_user_input('Enter nothing for https://github.com/ to be used: ') + ghe = request_user_input('Enter nothing for {} to be used: ' + .format(GITHUB_BASE_URL)) print('Enter your GitHub username:') username = request_user_input() if not ghe: - git_base = 'https://github.com/' + git_base = GITHUB_BASE_URL cal = get_calendar(username) else: cal = get_calendar(username, base_url=ghe) From 71c88fc0842a4442ee34c85af1da2b3b250766b6 Mon Sep 17 00:00:00 2001 From: Jochen Kupperschmidt Date: Sun, 5 Jun 2016 23:23:24 +0200 Subject: [PATCH 13/25] Turn the optional base URL argument into a mandatory one. --- gitfiti.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gitfiti.py b/gitfiti.py index a84c5295b..5a09f2ead 100755 --- a/gitfiti.py +++ b/gitfiti.py @@ -193,7 +193,7 @@ def load_images(img_names): return loaded_imgs -def get_calendar(username, base_url=GITHUB_BASE_URL): +def get_calendar(username, base_url): """retrieves the GitHub commit calendar data for a username""" base_url = base_url + 'users/' + username @@ -327,9 +327,9 @@ def main(): if not ghe: git_base = GITHUB_BASE_URL - cal = get_calendar(username) + cal = get_calendar(username, git_base) else: - cal = get_calendar(username, base_url=ghe) + cal = get_calendar(username, ghe) git_base = ghe m = calculate_multiplier(find_max_commits(cal)) From 02d049b1a3b9b14eba98e9422e5fdf9ea0f787a0 Mon Sep 17 00:00:00 2001 From: Jochen Kupperschmidt Date: Sun, 5 Jun 2016 23:37:54 +0200 Subject: [PATCH 14/25] Introduced a few variables. --- gitfiti.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/gitfiti.py b/gitfiti.py index 5a09f2ead..acaefa8e4 100755 --- a/gitfiti.py +++ b/gitfiti.py @@ -359,27 +359,33 @@ def main(): print('enter file(s) to load images from (blank if not applicable)') img_names = request_user_input().split(' ') - images = dict(IMAGES, **load_images(img_names)) + loaded_images = load_images(img_names) + images = dict(IMAGES, **loaded_images) print('enter the image name to gitfiti') print('images: ' + ', '.join(images.keys())) image = request_user_input() + image_name_fallback = 'kitty' + if not image: - image = IMAGES['kitty'] + image = IMAGES[image_name_fallback] else: try: image = images[image] except: - image = IMAGES['kitty'] + image = IMAGES[image_name_fallback] + + start_date = get_start_date() + fake_it_multiplier = m * match if not ghe: - output = fake_it(image, get_start_date(), username, repo, - offset, m * match) + output = fake_it(image, start_date, username, repo, offset, + fake_it_multiplier) else: git_url = request_user_input('Enter Git URL like git@site.github.com: ') - output = fake_it(image, get_start_date(), username, repo, - offset, m * match, git_url=git_url) + output = fake_it(image, start_date, username, repo, offset, + fake_it_multiplier, git_url=git_url) save(output, 'gitfiti.sh') print('gitfiti.sh saved.') From ca1dc8f00e69691f4425372a33dcd65c301b7678 Mon Sep 17 00:00:00 2001 From: Jochen Kupperschmidt Date: Sun, 5 Jun 2016 23:39:47 +0200 Subject: [PATCH 15/25] Turn the optional Git URL argument into a mandatory one. --- gitfiti.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gitfiti.py b/gitfiti.py index acaefa8e4..713695b6c 100755 --- a/gitfiti.py +++ b/gitfiti.py @@ -278,8 +278,7 @@ def commit(content, commitdate): commitdate.isoformat()) -def fake_it(image, start_date, username, repo, offset=0, multiplier=1, - git_url='git@github.com'): +def fake_it(image, start_date, username, repo, git_url, offset=0, multiplier=1): template = ( '#!/bin/bash\n' 'REPO={0}\n' @@ -380,12 +379,13 @@ def main(): fake_it_multiplier = m * match if not ghe: - output = fake_it(image, start_date, username, repo, offset, + git_url = 'git@github.com' + output = fake_it(image, start_date, username, repo, git_url, offset, fake_it_multiplier) else: git_url = request_user_input('Enter Git URL like git@site.github.com: ') - output = fake_it(image, start_date, username, repo, offset, - fake_it_multiplier, git_url=git_url) + output = fake_it(image, start_date, username, repo, git_url, offset, + fake_it_multiplier) save(output, 'gitfiti.sh') print('gitfiti.sh saved.') From f6727b25557be48eda76e08b08d5dd169cd3fa29 Mon Sep 17 00:00:00 2001 From: Jochen Kupperschmidt Date: Sun, 5 Jun 2016 23:41:47 +0200 Subject: [PATCH 16/25] Extracted function calls. --- gitfiti.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/gitfiti.py b/gitfiti.py index 713695b6c..982b06447 100755 --- a/gitfiti.py +++ b/gitfiti.py @@ -326,11 +326,11 @@ def main(): if not ghe: git_base = GITHUB_BASE_URL - cal = get_calendar(username, git_base) else: - cal = get_calendar(username, ghe) git_base = ghe + cal = get_calendar(username, git_base) + m = calculate_multiplier(find_max_commits(cal)) print('Enter name of the repo to be used by gitfiti:') @@ -380,12 +380,11 @@ def main(): if not ghe: git_url = 'git@github.com' - output = fake_it(image, start_date, username, repo, git_url, offset, - fake_it_multiplier) else: git_url = request_user_input('Enter Git URL like git@site.github.com: ') - output = fake_it(image, start_date, username, repo, git_url, offset, - fake_it_multiplier) + + output = fake_it(image, start_date, username, repo, git_url, offset, + fake_it_multiplier) save(output, 'gitfiti.sh') print('gitfiti.sh saved.') From 302e83416d0934535b509ecb92484aa11321b7fe Mon Sep 17 00:00:00 2001 From: Jochen Kupperschmidt Date: Sun, 5 Jun 2016 23:43:46 +0200 Subject: [PATCH 17/25] Use one-liner. --- gitfiti.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/gitfiti.py b/gitfiti.py index 982b06447..d0ef78ae8 100755 --- a/gitfiti.py +++ b/gitfiti.py @@ -324,10 +324,7 @@ def main(): print('Enter your GitHub username:') username = request_user_input() - if not ghe: - git_base = GITHUB_BASE_URL - else: - git_base = ghe + git_base = ghe if ghe else GITHUB_BASE_URL cal = get_calendar(username, git_base) From 5b6a3cfc2c580005208172498e6e9dafbf1f155b Mon Sep 17 00:00:00 2001 From: Jochen Kupperschmidt Date: Sun, 5 Jun 2016 23:48:56 +0200 Subject: [PATCH 18/25] Finding the highest daily commit count once is sufficient. --- gitfiti.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gitfiti.py b/gitfiti.py index d0ef78ae8..08030f84b 100755 --- a/gitfiti.py +++ b/gitfiti.py @@ -328,7 +328,9 @@ def main(): cal = get_calendar(username, git_base) - m = calculate_multiplier(find_max_commits(cal)) + max_commits = find_max_commits(cal) + + m = calculate_multiplier(max_commits) print('Enter name of the repo to be used by gitfiti:') repo = request_user_input() @@ -347,7 +349,7 @@ def main(): 'Enter the word "gitfiti" to exceed your max\n' '(this option generates WAY more commits)\n' 'Any other input will cause the default matching behavior' - ).format(find_max_commits(cal))) + ).format(max_commits)) match = request_user_input() match = m if (match == 'gitfiti') else 1 From e7e67834c873a68fd8ec2dcfbdcd1429660126e3 Mon Sep 17 00:00:00 2001 From: Jochen Kupperschmidt Date: Mon, 6 Jun 2016 00:20:27 +0200 Subject: [PATCH 19/25] Introduced package for tests and added a test case for `str_to_sprite`. The string variant of the "one-up" image, however, does not match the number-based one, to the expectation for the test had to be adjusted (basically replacing 1s with 0s). --- tests/__init__.py | 0 tests/test_str_to_sprite.py | 27 +++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 tests/__init__.py create mode 100644 tests/test_str_to_sprite.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/test_str_to_sprite.py b/tests/test_str_to_sprite.py new file mode 100644 index 000000000..41cc43c10 --- /dev/null +++ b/tests/test_str_to_sprite.py @@ -0,0 +1,27 @@ +from gitfiti import str_to_sprite, ONEUP_STR + + +SYMBOLS = ''' + ******* +*=~~-~~=* +*~~---~~* +*=*****=* +**-*-*-** + *-----* + ***** +''' + +NUMBERS = [ + [0,4,4,4,4,4,4,4,0], + [4,3,2,2,0,2,2,3,4], + [4,2,2,0,0,0,2,2,4], + [4,3,4,4,4,4,4,3,4], + [4,4,0,4,0,4,0,4,4], + [0,4,0,0,0,0,0,4,0], + [0,0,4,4,4,4,4,0,0], +] + + +def test_symbols_to_numbers(): + actual = str_to_sprite(SYMBOLS) + assert actual == NUMBERS From 811a7c2a443de7f1b5ce5458171c953671b1bed0 Mon Sep 17 00:00:00 2001 From: Jochen Kupperschmidt Date: Mon, 6 Jun 2016 00:07:27 +0200 Subject: [PATCH 20/25] Fixed import of `urlopen[2]` on Python 3. --- gitfiti.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/gitfiti.py b/gitfiti.py index 08030f84b..e05432fcc 100755 --- a/gitfiti.py +++ b/gitfiti.py @@ -13,7 +13,13 @@ from datetime import datetime, timedelta import itertools import json import math -import urllib2 +try: + # Python 3+ + from urllib.error import HTTPError, URLError + from urllib.request import urlopen +except ImportError: + # Python 2 + from urllib2 import HTTPError, URLError, urlopen GITHUB_BASE_URL = 'https://github.com/' @@ -199,8 +205,8 @@ def get_calendar(username, base_url): try: url = base_url + '/contributions' - page = urllib2.urlopen(url) - except (urllib2.HTTPError, urllib2.URLError) as e: + page = urlopen(url) + except (HTTPError, URLError) as e: print('There was a problem fetching data from {0}'.format(url)) print(e) raise SystemExit From 3e92a86161ab72f0d660f9318407e6728b450b6e Mon Sep 17 00:00:00 2001 From: Jochen Kupperschmidt Date: Mon, 6 Jun 2016 00:25:36 +0200 Subject: [PATCH 21/25] Fix `str_to_sprite` on Python 3. I'm using a list comprehension as it is easier to grok than `list(map(list, lines))`. --- gitfiti.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitfiti.py b/gitfiti.py index e05432fcc..67efb4dc0 100755 --- a/gitfiti.py +++ b/gitfiti.py @@ -133,7 +133,7 @@ def str_to_sprite(content): lines = filter(is_empty_line, lines) # Break up lines into each character - split_lines = map(list, lines) + split_lines = [list(line) for line in lines] # Replace each character with its numeric equivalent for line in split_lines: From 777f264796323aad09fbfb89d6dc79e02c097c51 Mon Sep 17 00:00:00 2001 From: Jochen Kupperschmidt Date: Mon, 6 Jun 2016 00:29:32 +0200 Subject: [PATCH 22/25] Make `raw_input` available on Python 3 by aliasing it to `input`. --- gitfiti.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gitfiti.py b/gitfiti.py index 67efb4dc0..959ecf0ba 100755 --- a/gitfiti.py +++ b/gitfiti.py @@ -21,6 +21,13 @@ except ImportError: # Python 2 from urllib2 import HTTPError, URLError, urlopen +try: + # Python 2 + raw_input +except NameError: + # Python 3 (Python 2's `raw_input` was renamed to `input`) + raw_input = input + GITHUB_BASE_URL = 'https://github.com/' From 580c13ab6884b297eec5047bce5b5197942225fa Mon Sep 17 00:00:00 2001 From: Jochen Kupperschmidt Date: Mon, 6 Jun 2016 00:46:05 +0200 Subject: [PATCH 23/25] Slightly streamlined user interface. --- gitfiti.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/gitfiti.py b/gitfiti.py index 959ecf0ba..af41a608a 100755 --- a/gitfiti.py +++ b/gitfiti.py @@ -330,12 +330,10 @@ def request_user_input(prompt='> '): def main(): print(TITLE) - print('Enter GitHub URL') - ghe = request_user_input('Enter nothing for {} to be used: ' - .format(GITHUB_BASE_URL)) + ghe = request_user_input( + 'Enter GitHub URL (leave blank to use {}): '.format(GITHUB_BASE_URL)) - print('Enter your GitHub username:') - username = request_user_input() + username = request_user_input('Enter your GitHub username: ') git_base = ghe if ghe else GITHUB_BASE_URL @@ -345,11 +343,11 @@ def main(): m = calculate_multiplier(max_commits) - print('Enter name of the repo to be used by gitfiti:') - repo = request_user_input() + repo = request_user_input( + 'Enter the name of the repository to use by gitfiti: ') - print('Enter the number of weeks to offset the image (from the left):') - offset = request_user_input() + offset = request_user_input( + 'Enter the number of weeks to offset the image (from the left): ') offset = int(offset) if offset.strip() else 0 @@ -367,14 +365,14 @@ def main(): match = m if (match == 'gitfiti') else 1 - print('enter file(s) to load images from (blank if not applicable)') + print('Enter file(s) to load images from (blank if not applicable)') img_names = request_user_input().split(' ') loaded_images = load_images(img_names) images = dict(IMAGES, **loaded_images) - print('enter the image name to gitfiti') - print('images: ' + ', '.join(images.keys())) + print('Enter the image name to gitfiti') + print('Images: ' + ', '.join(images.keys())) image = request_user_input() image_name_fallback = 'kitty' @@ -400,7 +398,7 @@ def main(): save(output, 'gitfiti.sh') print('gitfiti.sh saved.') - print('Create a new(!) repo at: {0}new and run it.'.format(git_base)) + print('Create a new(!) repo at {0}new and run the script'.format(git_base)) if __name__ == '__main__': From 603c7f30e7c93a9242efe1d8da381b391e7cb3d7 Mon Sep 17 00:00:00 2001 From: Jochen Kupperschmidt Date: Mon, 6 Jun 2016 00:50:12 +0200 Subject: [PATCH 24/25] Extracted "constant" for fallback image name. --- gitfiti.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gitfiti.py b/gitfiti.py index af41a608a..9129cce59 100755 --- a/gitfiti.py +++ b/gitfiti.py @@ -30,6 +30,7 @@ except NameError: GITHUB_BASE_URL = 'https://github.com/' +FALLBACK_IMAGE = 'kitty' TITLE = ''' @@ -375,7 +376,7 @@ def main(): print('Images: ' + ', '.join(images.keys())) image = request_user_input() - image_name_fallback = 'kitty' + image_name_fallback = FALLBACK_IMAGE if not image: image = IMAGES[image_name_fallback] From 6aa52725a604ae6802424849be3dfc10c7ee8b88 Mon Sep 17 00:00:00 2001 From: Jochen Kupperschmidt Date: Mon, 6 Jun 2016 01:07:04 +0200 Subject: [PATCH 25/25] Adjusted calendar SVG retrieval to work on Python 3, too. --- gitfiti.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitfiti.py b/gitfiti.py index 9129cce59..ac1afcdb5 100755 --- a/gitfiti.py +++ b/gitfiti.py @@ -219,7 +219,7 @@ def get_calendar(username, base_url): print(e) raise SystemExit - return page.readlines() + return page.read().decode('utf-8').splitlines() def find_max_commits(calendar):