From 3b9021b39f01c7cfd25e93e607669b0a7e5ff6f9 Mon Sep 17 00:00:00 2001 From: Ankush1oo8 <154556772+Ankush1oo8@users.noreply.github.com> Date: Wed, 6 Nov 2024 15:30:54 +0530 Subject: [PATCH] ISSUE #43 --- contribute.py | 73 ++++++++++++++++++++++----------------------------- 1 file changed, 32 insertions(+), 41 deletions(-) diff --git a/contribute.py b/contribute.py index 0bb6202fd..9764df7f1 100755 --- a/contribute.py +++ b/contribute.py @@ -15,18 +15,24 @@ def main(def_args=sys.argv[1:]): repository = args.repository user_name = args.user_name user_email = args.user_email + if repository is not None: start = repository.rfind('/') + 1 end = repository.rfind('.') directory = repository[start:end] + no_weekends = args.no_weekends frequency = args.frequency days_before = args.days_before + if days_before < 0: sys.exit('days_before must not be negative') + days_after = args.days_after + if days_after < 0: sys.exit('days_after must not be negative') + os.mkdir(directory) os.chdir(directory) run(['git', 'init', '-b', 'main']) @@ -38,12 +44,10 @@ def main(def_args=sys.argv[1:]): 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) \ - and randint(0, 100) < frequency: - for commit_time in (day + timedelta(minutes=m) - for m in range(contributions_per_day(args))): + + for day in (start_date + timedelta(n) for n in range(days_before + days_after)): + if (not no_weekends or day.weekday() < 5) and randint(0, 100) < frequency: + for commit_time in (day + timedelta(minutes=m) for m in range(contributions_per_day(args))): contribute(commit_time) if repository is not None: @@ -51,16 +55,15 @@ def main(def_args=sys.argv[1:]): run(['git', 'branch', '-M', 'main']) run(['git', 'push', '-u', 'origin', 'main']) - print('\nRepository generation ' + - '\x1b[6;30;42mcompleted successfully\x1b[0m!') + print('\nRepository generation completed successfully!') def contribute(date): with open(os.path.join(os.getcwd(), 'README.md'), 'a') as file: file.write(message(date) + '\n\n') + run(['git', 'add', '.']) - run(['git', 'commit', '-m', '"%s"' % message(date), - '--date', date.strftime('"%Y-%m-%d %H:%M:%S"')]) + run(['git', 'commit', '-m', '"%s"' % message(date), '--date', date.strftime('"%Y-%m-%d %H:%M:%S"')]) def run(commands): @@ -82,47 +85,35 @@ def contributions_per_day(args): def arguments(argsval): parser = argparse.ArgumentParser() + + # Changed positional argument to optional by adding '--' prefix to make it valid. parser.add_argument('-nw', '--no_weekends', required=False, action='store_true', default=False, - help="""do not commit on weekends""") + help="""Do not commit on weekends""") + parser.add_argument('-mc', '--max_commits', type=int, default=10, - required=False, help="""Defines the maximum amount of - commits a day the script can make. Accepts a number - from 1 to 20. If N is specified the script commits - from 1 to N times a day. The exact number of commits - is defined randomly for each day. The default value - is 10.""") + required=False, help="""Defines the maximum amount of commits a day the script can make. Accepts a number from 1 to 20. The default value is 10.""") + parser.add_argument('-fr', '--frequency', type=int, default=80, - required=False, help="""Percentage of days when the - script performs commits. If N is specified, the script - will commit N%% of days in a year. The default value - is 80.""") + required=False, help="""Percentage of days when the script performs commits. The default value is 80.""") + parser.add_argument('-r', '--repository', type=str, required=False, - help="""A link on an empty non-initialized remote git - repository. If specified, the script pushes the changes - to the repository. The link is accepted in SSH or HTTPS - format. For example: git@github.com:user/repo.git or - https://github.com/user/repo.git""") + help="""A link on an empty non-initialized remote git repository. For example: git@github.com:user/repo.git or https://github.com/user/repo.git""") + parser.add_argument('-un', '--user_name', type=str, required=False, - help="""Overrides user.name git config. - If not specified, the global config is used.""") + help="""Overrides user.name git config. If not specified, the global config is used.""") + parser.add_argument('-ue', '--user_email', type=str, required=False, - help="""Overrides user.email git config. - If not specified, the global config is used.""") + help="""Overrides user.email git config. If not specified, the global config is used.""") + parser.add_argument('-db', '--days_before', type=int, default=365, - 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.""") + required=False, help="""Specifies the number of days before the current date when the script will start adding commits.""") + 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.""") + required=False, help="""Specifies the number of days after the current date until which the script will be adding commits.""") + return parser.parse_args(argsval) if __name__ == "__main__": - main() + main() \ No newline at end of file