forked from Shpota/github-activity-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f8401f2
commit 3b9021b
Showing
1 changed file
with
32 additions
and
41 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,29 +44,26 @@ 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: | ||
run(['git', 'remote', 'add', 'origin', repository]) | ||
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: [email protected]:user/repo.git or | ||
https://github.com/user/repo.git""") | ||
help="""A link on an empty non-initialized remote git repository. For example: [email protected]: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() |