From 9811bc380dcc1b075b603cf7c89b18182a4adfdb Mon Sep 17 00:00:00 2001 From: Shahin Gharghi Date: Tue, 8 Nov 2022 16:55:06 +0000 Subject: [PATCH 1/5] Add end_days_before arg to set the finish date of script instead of current day --- contribute.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/contribute.py b/contribute.py index 0bb6202f..65664416 100755 --- a/contribute.py +++ b/contribute.py @@ -10,7 +10,7 @@ def main(def_args=sys.argv[1:]): args = arguments(def_args) - curr_date = datetime.now() + curr_date = datetime.now() - timedelta(args.end_days_before) directory = 'repository-' + curr_date.strftime('%Y-%m-%d-%H-%M-%S') repository = args.repository user_name = args.user_name @@ -121,6 +121,12 @@ def arguments(argsval): adding commits. For example: if it is set to 30 the last commit will be on a future date which is the current date plus 30 days.""") + parser.add_argument('-edb', '--end_days_before', type=int, default=0, + required=False, help="""Specifies the number of days + before the current date when the script will finish + adding commits. For example: if it is set to 30 the + last commit date will be the current date minus 30 + days.""") return parser.parse_args(argsval) From ce8d42d9a38d6524ef7f85a1549d2ca9f3031343 Mon Sep 17 00:00:00 2001 From: Shahin Gharghi Date: Tue, 8 Nov 2022 16:57:50 +0000 Subject: [PATCH 2/5] Update Readme Add "end_days_before" documents --- .github/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/README.md b/.github/README.md index 5d8ed194..54132d1a 100644 --- a/.github/README.md +++ b/.github/README.md @@ -58,6 +58,12 @@ will keep committing. ```sh python contribute.py --days_before=10 --days_after=15 ``` +Use `--end_days_before` to specify how many days before the current +date the script should finish committing. + +```sh +python contribute.py --end_days_before=5 +``` Run `python contribute.py --help` to get help. From 3e7b2c6898259f7696d32fabdc430775092db88f Mon Sep 17 00:00:00 2001 From: Shahin Gharghi Date: Wed, 9 Nov 2022 15:07:20 +0000 Subject: [PATCH 3/5] Add strat_date and end_date options --- contribute.py | 52 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/contribute.py b/contribute.py index 65664416..f6ad5626 100755 --- a/contribute.py +++ b/contribute.py @@ -1,16 +1,23 @@ #!/usr/bin/env python import argparse import os +import sys from datetime import datetime from datetime import timedelta from random import randint from subprocess import Popen -import sys def main(def_args=sys.argv[1:]): args = arguments(def_args) - curr_date = datetime.now() - timedelta(args.end_days_before) + try: + start_date = datetime.strptime(args.start_date, "%Y-%m-%d") + end_date = datetime.strptime(args.end_date, "%Y-%m-%d") + except ValueError: + sys.exit('Date format is not correct. Please use YYY-MM-DD format.') + + + curr_date = datetime.now() directory = 'repository-' + curr_date.strftime('%Y-%m-%d-%H-%M-%S') repository = args.repository user_name = args.user_name @@ -22,11 +29,16 @@ def main(def_args=sys.argv[1:]): no_weekends = args.no_weekends frequency = args.frequency days_before = args.days_before + days_after = args.days_after if days_before < 0: sys.exit('days_before must not be negative') - days_after = args.days_after + if days_before > 0: + start_date = curr_date - timedelta(days_before) if days_after < 0: sys.exit('days_after must not be negative') + if days_after > 0: + end_date = curr_date + timedelta(days_before) + start_date.replace(hour=20, minute=0) os.mkdir(directory) os.chdir(directory) run(['git', 'init', '-b', 'main']) @@ -37,14 +49,15 @@ def main(def_args=sys.argv[1:]): if user_email is not None: run(['git', 'config', 'user.email', user_email]) - start_date = curr_date.replace(hour=20, minute=0) - timedelta(days_before) - for day in (start_date + timedelta(n) for n - in range(days_before + days_after)): - if (not no_weekends or day.weekday() < 5) \ + delta = timedelta(days=1) + + while start_date <= end_date: + if (not no_weekends or start_date.weekday() < 5) \ and randint(0, 100) < frequency: - for commit_time in (day + timedelta(minutes=m) + for commit_time in (start_date + timedelta(minutes=m) for m in range(contributions_per_day(args))): contribute(commit_time) + start_date += delta if repository is not None: run(['git', 'remote', 'add', 'origin', repository]) @@ -55,6 +68,7 @@ def main(def_args=sys.argv[1:]): '\x1b[6;30;42mcompleted successfully\x1b[0m!') + def contribute(date): with open(os.path.join(os.getcwd(), 'README.md'), 'a') as file: file.write(message(date) + '\n\n') @@ -109,24 +123,28 @@ def arguments(argsval): parser.add_argument('-ue', '--user_email', type=str, required=False, help="""Overrides user.email git config. If not specified, the global config is used.""") - parser.add_argument('-db', '--days_before', type=int, default=365, + parser.add_argument('-db', '--days_before', type=int, default=0, required=False, help="""Specifies the number of days before the current date when the script will start adding commits. For example: if it is set to 30 the first commit date will be the current date minus 30 - days.""") + days. This option ignores start_date.""") parser.add_argument('-da', '--days_after', type=int, default=0, required=False, help="""Specifies the number of days after the current date until which the script will be adding commits. For example: if it is set to 30 the last commit will be on a future date which is the - current date plus 30 days.""") - parser.add_argument('-edb', '--end_days_before', type=int, default=0, - required=False, help="""Specifies the number of days - before the current date when the script will finish - adding commits. For example: if it is set to 30 the - last commit date will be the current date minus 30 - days.""") + current date plus 30 days. This option ignores end_date.""") + parser.add_argument('-sd', '--start_date', type=str, default=(datetime.now() - timedelta(365)).strftime('%Y-%m-%d'), + required=False, help="""Specifies the date to start adding + commits. The format should be YYYY-MM-DD. This value + can be in future too. For example: 25-02-2019 + This option will get ignored if used with days_before""") + parser.add_argument('-ed', '--end_date', type=str, default=datetime.now().strftime('%Y-%m-%d'), + required=False, help="""Specifies the last date to adding + commits. The format should be YYYY-MM-DD. This value + can be in future too. For example 25-02-2019 + This option will get ignored if used with days_after""") return parser.parse_args(argsval) From 320943348f969940acb74949d7f06b03c1b37870 Mon Sep 17 00:00:00 2001 From: Shahin Gharghi Date: Wed, 9 Nov 2022 15:10:09 +0000 Subject: [PATCH 4/5] Reformat code --- contribute.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/contribute.py b/contribute.py index f6ad5626..d2244a42 100755 --- a/contribute.py +++ b/contribute.py @@ -137,14 +137,14 @@ def arguments(argsval): current date plus 30 days. This option ignores end_date.""") parser.add_argument('-sd', '--start_date', type=str, default=(datetime.now() - timedelta(365)).strftime('%Y-%m-%d'), required=False, help="""Specifies the date to start adding - commits. The format should be YYYY-MM-DD. This value - can be in future too. For example: 25-02-2019 - This option will get ignored if used with days_before""") + commits. The format should be YYYY-MM-DD. This value + can be in future too. For example: 25-02-2019 + This option will get ignored if used with days_before""") parser.add_argument('-ed', '--end_date', type=str, default=datetime.now().strftime('%Y-%m-%d'), required=False, help="""Specifies the last date to adding - commits. The format should be YYYY-MM-DD. This value - can be in future too. For example 25-02-2019 - This option will get ignored if used with days_after""") + commits. The format should be YYYY-MM-DD. This value + can be in future too. For example 25-02-2019 + This option will get ignored if used with days_after""") return parser.parse_args(argsval) From e669f8ddb0fab5e8b0be766e18107fb0eba16043 Mon Sep 17 00:00:00 2001 From: Shahin Gharghi Date: Wed, 9 Nov 2022 15:13:56 +0000 Subject: [PATCH 5/5] Update README.md Update instruction of using stat_date and end_date --- .github/README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/README.md b/.github/README.md index 54132d1a..3708bb82 100644 --- a/.github/README.md +++ b/.github/README.md @@ -58,13 +58,16 @@ will keep committing. ```sh python contribute.py --days_before=10 --days_after=15 ``` -Use `--end_days_before` to specify how many days before the current -date the script should finish committing. +Use `--start_date` to specify start date of commits. This option doesn't work if used with days_before. ```sh -python contribute.py --end_days_before=5 +python contribute.py --start_date=2019-05-14 ``` +Use `--end_date` to specify end date of commits. This option doesn't work if used with days_after. +```sh +python contribute.py --end_end=2019-07-22 +``` Run `python contribute.py --help` to get help. ## System requirements