Last active
December 31, 2015 17:09
-
-
Save ivan-loh/8018298 to your computer and use it in GitHub Desktop.
ignore errors and added custom date. copied from https://github.com/skazhy/github-decorator python decorator.py ascii.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # github decorator | |
| # https://github.com/skazhy/github-decorator | |
| # \m/ 2013, skazhy | |
| import os | |
| import fileinput | |
| from datetime import date, timedelta | |
| from subprocess import Popen | |
| REPO = "decorator" | |
| repodir = os.path.join(os.path.dirname(__file__), REPO) | |
| start = date(2013, 7, 10) # either your own date or date.today(); | |
| densities = {".": 1, "-": 10, "+": 20, "#": 30} | |
| class HumbleList(list): | |
| def __getitem__(self, i): | |
| try: | |
| return super(HumbleList, self).__getitem__(i) | |
| except IndexError: | |
| return " " | |
| def transform_matrix(matrix): | |
| rows = max(len(r) for r in matrix) | |
| return [[matrix[c][r] for c in range(7)] for r in range(rows)] | |
| def exe(*cmds, **kwargs): | |
| cwd = kwargs.get("cwd", repodir) | |
| for cmd in cmds: | |
| pid = Popen(["/bin/sh", "-c", cmd], cwd=cwd).pid | |
| try: | |
| while(os.waitpid(pid, 0)[1] != 0): | |
| continue | |
| except: | |
| print "errrod" | |
| return | |
| def create_repo(): | |
| exe("git init --quiet %s" % REPO, cwd=None) | |
| def commit(day, minutes): | |
| timestamp = day.strftime("%Y.%m.%d " + "16:%02i:00 +0200" % minutes) | |
| filename = "coolfile" | |
| exe("echo '%s' > %s" % (timestamp, filename), | |
| "git add %s" % filename, | |
| "git commit -m '%s' --date='%s' " % (timestamp, timestamp)) | |
| def closest_sunday(day): | |
| # GitHub weeks start on Sundays. *americans* | |
| return day - timedelta(days=day.weekday() + 1 % 7) | |
| def decorate(matrix): | |
| create_repo() | |
| d = closest_sunday(start - timedelta(weeks=len(matrix)-1)) | |
| for row in matrix: | |
| for col in row: | |
| minutes = 0 | |
| for _ in range(densities.get(col, 0)): | |
| commit(d, minutes) | |
| minutes += 1 | |
| d += timedelta(days=1) | |
| if __name__ == "__main__": | |
| stdin_matrix = [HumbleList(line[:-1]) for line in fileinput.input()] | |
| for _ in range(len(stdin_matrix), 7): | |
| stdin_matrix.append(HumbleList([None])) | |
| decorate(transform_matrix(stdin_matrix)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment