github 刷小绿点

出处声明:https://ahangchen.gitbooks.io/windy-afternoon/content/kit/git/green_blush.html

最终效果图:

love.jpg

开发环境:

Windows
python3

开始:

步骤一:

安装python3,下载地址:www.python.org
安装注意事项:注意选中add python to path,不然要手动添加环境变量,安装之后cmd输入python,如下图表示成功:

QQ截图20160819140559.jpg
步骤二:

github中新建工程,clone到本地,新建zero.md文件,将https://github.com/ahangchen/green

QQ截图20160819141816.jpg

工程中的文件拷贝到本地目录下。

步骤三:

修改代码中的路径和时间
green.py

import datetime
import os

# from heavy import special_commit


def modify():
    file = open('D:\GIthubWorkspace\Love-master\zero.md', 'r')第一个参数改为zero.md所在的路径
    flag = int(file.readline()) == 0
    file.close()
    file = open('D:\GIthubWorkspace\Love-master\zero.md', 'w+')
    if flag:
        file.write('1')
    else:
        file.write('0')
        file.close()


def commit():
    os.system('git commit -a -m "test"')


def set_sys_time(year, month, day):
    os.system('date %04d/%02d/%02d' % (year, month, day))


def trick_commit(year, month, day):
    set_sys_time(year, month, day)
    modify()
    commit()


def daily_commit(start_date, end_date):
    for i in range((end_date - start_date).days + 1):
        cur_date = start_date + datetime.timedelta(days=i)
        trick_commit(cur_date.year, cur_date.month, cur_date.day)


if __name__ == '__main__':
    daily_commit(datetime.date(2015, 5, 16), datetime.date(2016, 7, 16))第一个参数为开始日期(小绿点表格左上),第二个结束日期(小绿点表格右下)

heavy.py

import datetime
import os

from green import set_sys_time, commit


def modify_other(path):
    file = open(path, 'r')
    flag = int(file.readline()) == 0
    file.close()
    file = open(path, 'w+')
    if flag:
        file.write('1')
    else:
        file.write('0')
        file.close()


def hard_commit(path, year, month, day, times):
    set_sys_time(year, month, day)
    while times > 0:
        modify_other(path)
        os.chdir(os.path.dirname(path))
        commit()
        times -= 1


def special_commit(path, date, times):
    hard_commit(path, date.year, date.month, date.day, times)


def read_etc(path):
    idxes = []
    file = open(path, 'r')
    while True:
        word = file.readline()
        if not word:
            break
        else:
            idxes.extend(word.split())
    intIdxes = []
    for idx in idxes:
        intIdxes.append(int(idx))
    return intIdxes


def love_commit(start_date, path, etc_path):
    words = read_etc(etc_path)
    for index in words:
        cur_date = start_date + datetime.timedelta(days=index)
        special_commit(path, cur_date, 15)


if __name__ == '__main__':
    love_commit(datetime.date(2015, 8, 16), 'D:\GIthubWorkspace\Love-master\zero.md', 'D:\GIthubWorkspace\Love-master\etc\love')
    第一个参数为开始日期(小绿点表格左上),第二个参数为zero.md所在路劲,第三个为love文件所在路径
步骤四:

cmd进入工程所在目录

git add *
git commit -m "test"

QQ截图20160819142915.jpg

python green.py 添加浅色的小绿点
git push origin master

将系统时间修改为当前时间,登录github查看效果

python heavy.py 根据love中记录的位置添加深色的小绿点
git push origin master

将系统时间修改为当前时间,登录github查看效果

我的github地址

小白程序员一枚,各路大神有空进来给个star - -!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1. 安装 Github 查看是否安装git: $ git config --global user.name "...
    Albert_Sun阅读 13,737评论 9 163
  • 我们看这题目,是不是会稍微感觉点新鲜和温馨?亲人聚一堆儿斜倚在温暖炕头的叠被上或坐在枝叶茂密的大树下,吃着家乡的炒...
    横笛云海阅读 700评论 9 7
  • 对于内向矫情的不自在星人来讲,如果在一个人面前可以不用在乎自己的形象,想哭就哭想笑就笑,可以肆无忌惮的分享各种稀奇...
    你说我听好么阅读 268评论 1 1