From f7f2b5554795df67342725241e8268bac27bc562 Mon Sep 17 00:00:00 2001 From: Eric Romano Date: Mon, 29 Apr 2013 18:15:40 -0400 Subject: [PATCH] cleaning up --- gitfiti.py | 151 ++++++++++++++++++++++++++++++++++------------------ gitfiti.pyc | Bin 4847 -> 0 bytes 2 files changed, 98 insertions(+), 53 deletions(-) delete mode 100644 gitfiti.pyc diff --git a/gitfiti.py b/gitfiti.py index 1ab7c2342..e87c2d34a 100644 --- a/gitfiti.py +++ b/gitfiti.py @@ -1,3 +1,4 @@ +#!/bin/env python import os, sys, datetime, math, itertools try: import requests @@ -5,6 +6,69 @@ except: print 'the requests module is required' exit(1) +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]] + +oneup=[ +[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]] + +twoup=[ +[0,0,4,4,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,0,0,4,2,2,1,1,1,2,2,4,0], +[4,3,2,2,1,1,1,2,2,3,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,3,3,4,4,4,4,4,3,3,4], +[0,4,4,1,4,1,4,1,4,4,0,0,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,1,1,1,1,1,4,0,0], +[0,0,0,4,4,4,4,4,0,0,0,0,0,0,0,4,4,4,4,4,0,0,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]] + +hackerschool=[ +[4,4,4,4,4,4], +[4,3,3,3,3,4], +[4,1,3,3,3,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]] + +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]] + def get_calendar(username): """retrieves the github commit calendar data for a username""" BASEURL='https://github.com/' @@ -22,15 +86,6 @@ def max_commits(input): output.reverse() return output[0] -def trim_calendar(input): - """returns index of first sunday in the input""" - for i, j in enumerate(input): - day = input[i][0] - day = datetime.datetime.strptime(day, '%Y/%m/%d') - weekday = datetime.datetime.weekday(day) - if weekday == 6: - return i - def multiplier(max_commits): """calculates a multiplier to scale github colors to commit history""" m = max_commits/4.0 @@ -49,9 +104,10 @@ def get_start_date(): weekday = datetime.datetime.weekday(date) return date -def date_gen(start_date): - '''generator to return the next day, requires a datetime object as input''' - for i in itertools.count(): +def date_gen(start_date, offset=0): + '''generator to return the next day, requires a datetime object as input. The offset is weeks''' + start = offset * 7 + for i in itertools.count(start): yield start_date + datetime.timedelta(i) def values_in_date_order(image, multiplier=1): @@ -61,59 +117,48 @@ def values_in_date_order(image, multiplier=1): for w in range(width): yield image[h][w]*multiplier -def fake_it(image, start_date, username, repo, multiplier=1): - template=('git init gitfiti\n' +def commit(content, commitdate): + template = '''echo %s >> gitfiti\nGIT_AUTHOR_DATE=%s GIT_COMMITTER_DATE= %s git commit -a -m "gitfiti"\n''' + return template % (content, commitdate.isoformat(), commitdate.isoformat()) + +def fake_it(image, start_date, username, repo, offset=0, multiplier=1): + template = ('#!/bin/bash\n' + 'git init gitfiti\n' 'cd gitfiti\n' 'touch gitfiti\n' 'git add gitfiti\n' '%s\n' 'git remote add origin git@github.com:%s/%s.git\n' + 'git pull\n' 'git push -u origin master\n') strings = [] - for value, date in zip(values_in_date_order(image, multiplier), date_gen(start_date)): + 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 % ("".join(strings), username, repo) - -def commit(content, commitdate): - template='''echo %s >> gitfiti\nGIT_AUTHOR_DATE=%s GIT_COMMITTER_DATE= %s git commit -a -m "gitfiti"\n''' - return template % (content, commitdate.isoformat(), commitdate.isoformat()) + +def save(output, filename): + """Saves the list to a given filename""" + f = open(filename, "w") + f.write('\n') + f.write(output) + f.close() def main(): - username='gelstudios' + print 'enter your github username:' + username = raw_input(">") cal = get_calendar(username) - x = trim_calendar(cal) - m = max_commits(cal) - m = multiplier(m) - cal = cal[x:] - fake_it(kitty, get_start_date(), m) + m = multiplier(max_commits(cal)) + + print 'enter name of the repo to be used by gitfiti:' + repo = raw_input(">") + + print 'enter weeks to offset the image:' + offset = raw_input(">") + + output = fake_it(image, get_start_date(), username, repo, offset, m) + save(output, 'gitfiti.sh') + print 'gitfiti.sh saved, run it from inside the repo you want to gitfiti' if __name__=='__main__': - main() - -kitty=[ -[0,0,0,4,0,0,0,0,4,0,0,0], -[3,3,4,2,4,4,4,4,2,4,3,3], -[0,0,4,2,2,2,2,2,2,4,0,0], -[3,3,4,2,4,2,2,4,2,4,3,3], -[0,0,4,2,2,3,3,2,2,4,0,0], -[3,3,4,2,2,2,2,2,2,4,3,3], -[0,0,0,4,4,4,4,4,4,0,0,0]] - -oneup=[ -[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]] - -hello=[ -[0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], -[0,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], -[0,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], -[0,4,4,4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0], -[0,3,3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0], -[0,2,2,0,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0], -[0,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0]] \ No newline at end of file + main() \ No newline at end of file diff --git a/gitfiti.pyc b/gitfiti.pyc deleted file mode 100644 index f22779d516b6ecb416d8bff3e40a07ef9f790db4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4847 zcmbVP?Q$Ep6$SVqiPVP`f61D9nvD}Rs$E%5r_(kb*Og;=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