cleaning up
This commit is contained in:
147
gitfiti.py
147
gitfiti.py
@ -1,3 +1,4 @@
|
|||||||
|
#!/bin/env python
|
||||||
import os, sys, datetime, math, itertools
|
import os, sys, datetime, math, itertools
|
||||||
try:
|
try:
|
||||||
import requests
|
import requests
|
||||||
@ -5,6 +6,69 @@ except:
|
|||||||
print 'the requests module is required'
|
print 'the requests module is required'
|
||||||
exit(1)
|
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):
|
def get_calendar(username):
|
||||||
"""retrieves the github commit calendar data for a username"""
|
"""retrieves the github commit calendar data for a username"""
|
||||||
BASEURL='https://github.com/'
|
BASEURL='https://github.com/'
|
||||||
@ -22,15 +86,6 @@ def max_commits(input):
|
|||||||
output.reverse()
|
output.reverse()
|
||||||
return output[0]
|
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):
|
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
|
m = max_commits/4.0
|
||||||
@ -49,9 +104,10 @@ def get_start_date():
|
|||||||
weekday = datetime.datetime.weekday(date)
|
weekday = datetime.datetime.weekday(date)
|
||||||
return date
|
return date
|
||||||
|
|
||||||
def date_gen(start_date):
|
def date_gen(start_date, offset=0):
|
||||||
'''generator to return the next day, requires a datetime object as input'''
|
'''generator to return the next day, requires a datetime object as input. The offset is weeks'''
|
||||||
for i in itertools.count():
|
start = offset * 7
|
||||||
|
for i in itertools.count(start):
|
||||||
yield start_date + datetime.timedelta(i)
|
yield start_date + datetime.timedelta(i)
|
||||||
|
|
||||||
def values_in_date_order(image, multiplier=1):
|
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):
|
for w in range(width):
|
||||||
yield image[h][w]*multiplier
|
yield image[h][w]*multiplier
|
||||||
|
|
||||||
def fake_it(image, start_date, username, repo, multiplier=1):
|
def commit(content, commitdate):
|
||||||
template=('git init gitfiti\n'
|
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'
|
'cd gitfiti\n'
|
||||||
'touch gitfiti\n'
|
'touch gitfiti\n'
|
||||||
'git add gitfiti\n'
|
'git add gitfiti\n'
|
||||||
'%s\n'
|
'%s\n'
|
||||||
'git remote add origin git@github.com:%s/%s.git\n'
|
'git remote add origin git@github.com:%s/%s.git\n'
|
||||||
|
'git pull\n'
|
||||||
'git push -u origin master\n')
|
'git push -u origin master\n')
|
||||||
strings = []
|
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):
|
for i in range(value):
|
||||||
strings.append(commit(i, date))
|
strings.append(commit(i, date))
|
||||||
return template % ("".join(strings), username, repo)
|
return template % ("".join(strings), username, repo)
|
||||||
|
|
||||||
def commit(content, commitdate):
|
def save(output, filename):
|
||||||
template='''echo %s >> gitfiti\nGIT_AUTHOR_DATE=%s GIT_COMMITTER_DATE= %s git commit -a -m "gitfiti"\n'''
|
"""Saves the list to a given filename"""
|
||||||
return template % (content, commitdate.isoformat(), commitdate.isoformat())
|
f = open(filename, "w")
|
||||||
|
f.write('\n')
|
||||||
|
f.write(output)
|
||||||
|
f.close()
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
username='gelstudios'
|
print 'enter your github username:'
|
||||||
|
username = raw_input(">")
|
||||||
cal = get_calendar(username)
|
cal = get_calendar(username)
|
||||||
x = trim_calendar(cal)
|
m = multiplier(max_commits(cal))
|
||||||
m = max_commits(cal)
|
|
||||||
m = multiplier(m)
|
print 'enter name of the repo to be used by gitfiti:'
|
||||||
cal = cal[x:]
|
repo = raw_input(">")
|
||||||
fake_it(kitty, get_start_date(), m)
|
|
||||||
|
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__':
|
if __name__=='__main__':
|
||||||
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]]
|
|
BIN
gitfiti.pyc
BIN
gitfiti.pyc
Binary file not shown.
Reference in New Issue
Block a user