Private
Public Access
1
0
This commit is contained in:
Sander Roosendaal
2022-02-17 11:39:13 +01:00
parent adbb5bb02f
commit 3c2454cb3e
5 changed files with 59 additions and 61 deletions

View File

@@ -1,5 +1,3 @@
#!/srv/venv/bin/python
import sys
import os
@@ -10,11 +8,12 @@ import json
from simplejson.errors import JSONDecodeError
PY3K = sys.version_info >= (3,0)
from django.core.management.base import BaseCommand
from rowers.models import BlogPost
PY3K = sys.version_info >= (3, 0)
class Command(BaseCommand):
def handle(self, *args, **options):
blogs_json = []
@@ -24,7 +23,7 @@ class Command(BaseCommand):
if response.status_code == 200:
try:
blogs_json = response.json()
except JSONDecodeError:
except JSONDecodeError:
try:
blogs_json = json.loads(response.text)
except JSONDecodeError:
@@ -35,16 +34,13 @@ class Command(BaseCommand):
pass
if blogs_json:
result = BlogPost.objects.all().delete()
_ = BlogPost.objects.all().delete()
for postdata in blogs_json[0:3]:
title = postdata['title']['rendered']
link = postdata['link']
datetime = postdata['date']
datetime = arrow.get(datetime).datetime
date = datetime.date()
blogpost = BlogPost(
link=link,
date=date,

View File

@@ -1,52 +1,51 @@
#!/srv/venv/bin/python
import sys
import os
# If you find a solution that does not need the two paths, please comment!
sys.path.append('$path_to_root_of_project$')
sys.path.append('$path_to_root_of_project$/$project_name$')
os.environ['DJANGO_SETTINGS_MODULE'] = '$project_name$.settings'
from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
from django.core.mail import send_mail, BadHeaderError,EmailMessage
from django.core.mail import send_mail, BadHeaderError, EmailMessage
import datetime
from rowers.models import Rower
from rowsandall_app.settings import BASE_DIR
sys.path.append('$path_to_root_of_project$')
sys.path.append('$path_to_root_of_project$/$project_name$')
os.environ['DJANGO_SETTINGS_MODULE'] = '$project_name$.settings'
def getexpired():
rs = Rower.objects.all()
lijst = []
for r in rs:
if r.planexpires < datetime.datetime.now().date():
if r.rowerplan == 'pro' or r.rowerplan == 'coach' or r.rowerplan == 'plan':
lijst.append(r)
if r.teamplanexpires < datetime.datetime.now().date():
if r.rowerplan == 'pro' or r.rowerplan == 'coach' or r.rowerplan == 'plan':
lijst.append(r)
return lijst
rs = Rower.objects.all()
lijst = []
for r in rs:
if r.planexpires < datetime.datetime.now().date():
if r.rowerplan == 'pro' or r.rowerplan == 'coach' or r.rowerplan == 'plan':
lijst.append(r)
if r.teamplanexpires < datetime.datetime.now().date():
if r.rowerplan == 'pro' or r.rowerplan == 'coach' or r.rowerplan == 'plan':
lijst.append(r)
return lijst
class Command(BaseCommand):
def handle(self, *args, **options):
expiredrowers = getexpired()
if len(expiredrowers) > 0:
fullemail = 'roosendaalsander@gmail.com'
subject = "Expired rowers report"
message = "Dear Sander,\n\n"
message += "Best Regards, the Rowsandall Team"
message += "Expired rowers report\n\n"
for r in expiredrowers:
message += r.user.first_name+" "+r.user.last_name+" "+r.user.username
message += "\n"
email = EmailMessage(subject, message,
'Rowsandall <info@rowsandall.com>',
[fullemail])
res = email.send()
email = EmailMessage(
subject, message,
'Rowsandall <info@rowsandall.com>',
[fullemail])
_ = email.send()

View File

@@ -3,8 +3,6 @@
import sys
import os
PY3K = sys.version_info >= (3,0)
from django.core.management.base import BaseCommand
from rowers.models import Alert, Condition, User
from rowers.tasks import handle_send_email_alert
@@ -13,15 +11,17 @@ from rowers import alerts
from rowers.utils import myqueue
import datetime
import django_rq
PY3K = sys.version_info >= (3, 0)
queue = django_rq.get_queue('default')
queuelow = django_rq.get_queue('low')
queuehigh = django_rq.get_queue('low')
import datetime
class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument(
@@ -29,8 +29,7 @@ class Command(BaseCommand):
action='store_true',
dest='testing',
default=False,
help="Run in testing mode, don't send emails",
)
help="Run in testing mode, don't send emails", )
def handle(self, *args, **options):
if 'testing' in options:
@@ -38,7 +37,8 @@ class Command(BaseCommand):
else:
testing = False
todaysalerts = Alert.objects.filter(next_run__lt = datetime.date.today(),emailalert=True)
todaysalerts = Alert.objects.filter(
next_run__lt=datetime.date.today(), emailalert=True)
for alert in todaysalerts:
stats = alerts.alert_get_stats(alert)
@@ -47,14 +47,14 @@ class Command(BaseCommand):
othertexts = [alert.description()]
# send email
job = myqueue(queue,handle_send_email_alert,
alert.manager.email,
alert.manager.first_name,
alert.manager.last_name,
alert.rower.user.first_name,
alert.name,
stats,debug=True,
othertexts=othertexts)
_ = myqueue(queue, handle_send_email_alert,
alert.manager.email,
alert.manager.first_name,
alert.manager.last_name,
alert.rower.user.first_name,
alert.name,
stats, debug=True,
othertexts=othertexts)
# advance next_run
if not testing:
@@ -62,7 +62,7 @@ class Command(BaseCommand):
alert.save()
if testing:
print('{nr} alerts found'.format(nr = len(todaysalerts)))
print('{nr} alerts found'.format(nr=len(todaysalerts)))
self.stdout.write(self.style.SUCCESS(
'Successfully processed alerts'))

View File

@@ -1,24 +1,27 @@
#!/srv/venv/bin/python
import sys
import os
# If you find a solution that does not need the two paths, please comment!
sys.path.append('$path_to_root_of_project$')
sys.path.append('$path_to_root_of_project$/$project_name$')
os.environ['DJANGO_SETTINGS_MODULE'] = '$project_name$.settings'
from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
#from rowers.mailprocessing import processattachments
import time
from django.conf import settings
from rowers.models import Workout, User, Rower, WorkoutForm,RowerForm,GraphImage,AdvancedWorkoutForm
from rowers.models import (
Workout, User, Rower, WorkoutForm,
RowerForm, GraphImage, AdvancedWorkoutForm)
from django.core.files.base import ContentFile
from rowsandall_app.settings import BASE_DIR
from rowers.dataprep import *
# If you find a solution that does not need the two paths, please comment!
sys.path.append('$path_to_root_of_project$')
sys.path.append('$path_to_root_of_project$/$project_name$')
os.environ['DJANGO_SETTINGS_MODULE'] = '$project_name$.settings'
class Command(BaseCommand):
def handle(self, *args, **options):
repair_data(verbose=True)

View File

@@ -1,4 +1,4 @@
[flake8]
ignore = F405, F403, E722, E226, W504, F401, W605
max-line-length = 120
exclude = .git, rowers/migrations
exclude = .git, rowers/migrations, rowers/tests