forked from Ninjaclasher/dmoj-docker
-
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.
Signed-off-by: Jason Cameron <[email protected]>
- Loading branch information
1 parent
1b8a8ab
commit dfeabc4
Showing
1 changed file
with
46 additions
and
46 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 |
---|---|---|
|
@@ -2,16 +2,14 @@ | |
import json | ||
import secrets | ||
import string | ||
|
||
from judge.models import * | ||
from django.core.mail import * | ||
from django.contrib.auth.models import User | ||
from django.conf import settings | ||
|
||
from django.contrib.auth.models import User | ||
from django.core.mail import * | ||
from judge.models import * | ||
|
||
# Must be updated between runs when using email batches | ||
FILE_START_NUM = 0 # File offset | ||
USER_START_NUM = 1100 # Latest team number (after file offset included) | ||
USER_START_NUM = 1100 # Latest team number (after file offset included) | ||
|
||
FILE = "lcc2023-11.json" # Must be json with {"team name": [{"name": "", "email": "", "school": ""}, ...], ...} | ||
COMPETITION = "LCC23" # ex. 'Moose' or 'LCC' | ||
|
@@ -41,44 +39,46 @@ | |
This is an automated message. If you have any questions or concerns, please contact [email protected]. | ||
""" | ||
|
||
def send(real=False): | ||
org = Organization.objects.get(id=ORG_ID) | ||
with open(FILE, "r") as f: | ||
data = json.loads(f.read()) | ||
|
||
mails_sent = 0 | ||
num = 0 | ||
for team, users in data .items(): | ||
num += 1 | ||
if num < FILE_START_NUM: | ||
continue | ||
|
||
mails_sent += len(users) | ||
if mails_sent > MAIL_LIMIT: | ||
print("Sent %d mails" % (mails_sent - len(users))) | ||
print("Next team: %s)" % team) | ||
print("Update 'FILE_START_NUM' in the script to: %d" % num) | ||
return | ||
|
||
username = "%s_%s_%d" % (COMPETITION, team, num + USER_START_NUM-1) | ||
password = ''.join(secrets.choice(string.ascii_letters + string.digits) for i in range(16)) | ||
print("Making user: (%s, %s)" % (username, password)) | ||
if real: | ||
usr = User.objects.create_user(username, password=password) | ||
profile = Profile(user=usr, is_external_user=True) | ||
|
||
msg = MESSAGE.format(**{"user": username, "pass": password, "team": team}) | ||
emails = [] | ||
notes = "" | ||
for user in users: | ||
emails.append(user["email"]) | ||
notes += "%s <%s>\n" % (user["name"], user["email"]) | ||
|
||
email = EmailMessage(SUBJECT, msg, FROM_EMAIL, [], emails) | ||
print("Preparing message: %s" % emails) | ||
if real: | ||
profile.notes = notes | ||
profile.save() | ||
profile.organizations.add(org) | ||
email.send() | ||
print('email sent') | ||
def send(dry_run=False): | ||
org = Organization.objects.get(id=ORG_ID) | ||
with open(FILE, "r") as f: | ||
data = json.loads(f.read()) | ||
|
||
mails_sent = 0 | ||
num = 0 | ||
for team, users in data.items(): | ||
num += 1 | ||
if num < FILE_START_NUM: | ||
continue | ||
|
||
mails_sent += len(users) | ||
if mails_sent > MAIL_LIMIT: | ||
print("Sent %d mails" % (mails_sent - len(users))) | ||
print("Next team: %s)" % team) | ||
print("Update 'FILE_START_NUM' in the script to: %d" % num) | ||
return | ||
|
||
username = "%s_%s_%d" % (COMPETITION, team, num + USER_START_NUM - 1) | ||
password = ''.join(secrets.choice(string.ascii_letters + string.digits) for i in range(16)) | ||
profile: Profile = None | ||
print("Making user: (%s, %s)" % (username, password)) | ||
if not dry_run: | ||
usr = User.objects.create_user(username, password=password) | ||
profile = Profile(user=usr) | ||
|
||
msg = MESSAGE.format(**{"user": username, "pass": password, "team": team}) | ||
emails = [] | ||
notes = "" | ||
for user in users: | ||
emails.append(user["email"]) | ||
notes += "%s <%s>\n" % (user["name"], user["email"]) | ||
|
||
email = EmailMessage(SUBJECT, msg, FROM_EMAIL, [], emails) | ||
print("Preparing message: %s" % emails) | ||
if not dry_run: | ||
profile.notes = notes | ||
profile.save() | ||
profile.organizations.add(org) | ||
email.send() | ||
print('email sent') |