Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add end_date_before arg to the script #22

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,16 @@ will keep committing.
```sh
python contribute.py --days_before=10 --days_after=15
```
Use `--start_date` to specify start date of commits. This option doesn't work if used with days_before.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would propose making them mutually exclusive. If one of them is specified, the script should work. If both are specified, it should show an error.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't.
Imagine you need to set a period of time in last year.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, if someone uses both --days_before and --start_date this should lead to an error

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be. But I thought to make it more error free and handle them in the code.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better when the logic is explicit and the user doesn't have to guess what would happen when they specify two parameters that collide

Copy link

@johnwyles johnwyles Jun 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I vote --days_before be removed altogether or just error out on if both are specified and if --days_before is removed also want to remove --days_after of course. I think specifying a date is the better route for the tool since it's more intrinsically what a user expects for options. Additionally it allows you to splice up your commit dates uniquely so the graph can be a bit more chaotic whereas --days_before (and especially --days_after) I find fairly useless.

And of course it would break backwards compatibility if anyone cares about that 😄


```sh
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
Expand Down
44 changes: 34 additions & 10 deletions contribute.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
#!/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)
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
Expand All @@ -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'])
Expand All @@ -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])
Expand All @@ -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')
Expand Down Expand Up @@ -109,18 +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.""")
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)


Expand Down