more pep
This commit is contained in:
@@ -1,5 +1,3 @@
|
|||||||
#!/srv/venv/bin/python
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
@@ -10,11 +8,12 @@ import json
|
|||||||
|
|
||||||
from simplejson.errors import JSONDecodeError
|
from simplejson.errors import JSONDecodeError
|
||||||
|
|
||||||
PY3K = sys.version_info >= (3,0)
|
|
||||||
|
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
from rowers.models import BlogPost
|
from rowers.models import BlogPost
|
||||||
|
|
||||||
|
PY3K = sys.version_info >= (3, 0)
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
blogs_json = []
|
blogs_json = []
|
||||||
@@ -24,7 +23,7 @@ class Command(BaseCommand):
|
|||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
try:
|
try:
|
||||||
blogs_json = response.json()
|
blogs_json = response.json()
|
||||||
except JSONDecodeError:
|
except JSONDecodeError:
|
||||||
try:
|
try:
|
||||||
blogs_json = json.loads(response.text)
|
blogs_json = json.loads(response.text)
|
||||||
except JSONDecodeError:
|
except JSONDecodeError:
|
||||||
@@ -35,16 +34,13 @@ class Command(BaseCommand):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
if blogs_json:
|
if blogs_json:
|
||||||
result = BlogPost.objects.all().delete()
|
_ = BlogPost.objects.all().delete()
|
||||||
|
|
||||||
for postdata in blogs_json[0:3]:
|
for postdata in blogs_json[0:3]:
|
||||||
title = postdata['title']['rendered']
|
title = postdata['title']['rendered']
|
||||||
link = postdata['link']
|
link = postdata['link']
|
||||||
datetime = postdata['date']
|
|
||||||
datetime = arrow.get(datetime).datetime
|
|
||||||
date = datetime.date()
|
date = datetime.date()
|
||||||
|
|
||||||
|
|
||||||
blogpost = BlogPost(
|
blogpost = BlogPost(
|
||||||
link=link,
|
link=link,
|
||||||
date=date,
|
date=date,
|
||||||
|
|||||||
@@ -1,52 +1,51 @@
|
|||||||
#!/srv/venv/bin/python
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
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.core.management.base import BaseCommand, CommandError
|
||||||
from django.conf import settings
|
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
|
import datetime
|
||||||
from rowers.models import Rower
|
from rowers.models import Rower
|
||||||
from rowsandall_app.settings import BASE_DIR
|
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():
|
def getexpired():
|
||||||
rs = Rower.objects.all()
|
rs = Rower.objects.all()
|
||||||
lijst = []
|
lijst = []
|
||||||
for r in rs:
|
for r in rs:
|
||||||
if r.planexpires < datetime.datetime.now().date():
|
if r.planexpires < datetime.datetime.now().date():
|
||||||
if r.rowerplan == 'pro' or r.rowerplan == 'coach' or r.rowerplan == 'plan':
|
if r.rowerplan == 'pro' or r.rowerplan == 'coach' or r.rowerplan == 'plan':
|
||||||
lijst.append(r)
|
lijst.append(r)
|
||||||
if r.teamplanexpires < datetime.datetime.now().date():
|
if r.teamplanexpires < datetime.datetime.now().date():
|
||||||
if r.rowerplan == 'pro' or r.rowerplan == 'coach' or r.rowerplan == 'plan':
|
if r.rowerplan == 'pro' or r.rowerplan == 'coach' or r.rowerplan == 'plan':
|
||||||
lijst.append(r)
|
lijst.append(r)
|
||||||
return lijst
|
return lijst
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
expiredrowers = getexpired()
|
expiredrowers = getexpired()
|
||||||
|
|
||||||
if len(expiredrowers) > 0:
|
if len(expiredrowers) > 0:
|
||||||
fullemail = 'roosendaalsander@gmail.com'
|
fullemail = 'roosendaalsander@gmail.com'
|
||||||
subject = "Expired rowers report"
|
subject = "Expired rowers report"
|
||||||
message = "Dear Sander,\n\n"
|
message = "Dear Sander,\n\n"
|
||||||
message += "Best Regards, the Rowsandall Team"
|
message += "Best Regards, the Rowsandall Team"
|
||||||
message += "Expired rowers report\n\n"
|
message += "Expired rowers report\n\n"
|
||||||
|
|
||||||
for r in expiredrowers:
|
for r in expiredrowers:
|
||||||
message += r.user.first_name+" "+r.user.last_name+" "+r.user.username
|
message += r.user.first_name+" "+r.user.last_name+" "+r.user.username
|
||||||
message += "\n"
|
message += "\n"
|
||||||
|
|
||||||
email = EmailMessage(subject, message,
|
|
||||||
'Rowsandall <info@rowsandall.com>',
|
|
||||||
[fullemail])
|
|
||||||
|
|
||||||
|
|
||||||
|
email = EmailMessage(
|
||||||
res = email.send()
|
subject, message,
|
||||||
|
'Rowsandall <info@rowsandall.com>',
|
||||||
|
[fullemail])
|
||||||
|
|
||||||
|
_ = email.send()
|
||||||
|
|||||||
@@ -3,8 +3,6 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
PY3K = sys.version_info >= (3,0)
|
|
||||||
|
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
from rowers.models import Alert, Condition, User
|
from rowers.models import Alert, Condition, User
|
||||||
from rowers.tasks import handle_send_email_alert
|
from rowers.tasks import handle_send_email_alert
|
||||||
@@ -13,15 +11,17 @@ from rowers import alerts
|
|||||||
|
|
||||||
from rowers.utils import myqueue
|
from rowers.utils import myqueue
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
|
||||||
import django_rq
|
import django_rq
|
||||||
|
|
||||||
|
PY3K = sys.version_info >= (3, 0)
|
||||||
|
|
||||||
queue = django_rq.get_queue('default')
|
queue = django_rq.get_queue('default')
|
||||||
queuelow = django_rq.get_queue('low')
|
queuelow = django_rq.get_queue('low')
|
||||||
queuehigh = django_rq.get_queue('low')
|
queuehigh = django_rq.get_queue('low')
|
||||||
|
|
||||||
|
|
||||||
import datetime
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
def add_arguments(self, parser):
|
def add_arguments(self, parser):
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
@@ -29,8 +29,7 @@ class Command(BaseCommand):
|
|||||||
action='store_true',
|
action='store_true',
|
||||||
dest='testing',
|
dest='testing',
|
||||||
default=False,
|
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):
|
def handle(self, *args, **options):
|
||||||
if 'testing' in options:
|
if 'testing' in options:
|
||||||
@@ -38,7 +37,8 @@ class Command(BaseCommand):
|
|||||||
else:
|
else:
|
||||||
testing = False
|
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:
|
for alert in todaysalerts:
|
||||||
stats = alerts.alert_get_stats(alert)
|
stats = alerts.alert_get_stats(alert)
|
||||||
@@ -47,14 +47,14 @@ class Command(BaseCommand):
|
|||||||
othertexts = [alert.description()]
|
othertexts = [alert.description()]
|
||||||
|
|
||||||
# send email
|
# send email
|
||||||
job = myqueue(queue,handle_send_email_alert,
|
_ = myqueue(queue, handle_send_email_alert,
|
||||||
alert.manager.email,
|
alert.manager.email,
|
||||||
alert.manager.first_name,
|
alert.manager.first_name,
|
||||||
alert.manager.last_name,
|
alert.manager.last_name,
|
||||||
alert.rower.user.first_name,
|
alert.rower.user.first_name,
|
||||||
alert.name,
|
alert.name,
|
||||||
stats,debug=True,
|
stats, debug=True,
|
||||||
othertexts=othertexts)
|
othertexts=othertexts)
|
||||||
|
|
||||||
# advance next_run
|
# advance next_run
|
||||||
if not testing:
|
if not testing:
|
||||||
@@ -62,7 +62,7 @@ class Command(BaseCommand):
|
|||||||
alert.save()
|
alert.save()
|
||||||
|
|
||||||
if testing:
|
if testing:
|
||||||
print('{nr} alerts found'.format(nr = len(todaysalerts)))
|
print('{nr} alerts found'.format(nr=len(todaysalerts)))
|
||||||
|
|
||||||
self.stdout.write(self.style.SUCCESS(
|
self.stdout.write(self.style.SUCCESS(
|
||||||
'Successfully processed alerts'))
|
'Successfully processed alerts'))
|
||||||
|
|||||||
@@ -1,24 +1,27 @@
|
|||||||
#!/srv/venv/bin/python
|
#!/srv/venv/bin/python
|
||||||
import sys
|
import sys
|
||||||
import os
|
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.core.management.base import BaseCommand, CommandError
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
#from rowers.mailprocessing import processattachments
|
|
||||||
import time
|
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 django.core.files.base import ContentFile
|
||||||
|
|
||||||
from rowsandall_app.settings import BASE_DIR
|
from rowsandall_app.settings import BASE_DIR
|
||||||
|
|
||||||
from rowers.dataprep import *
|
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):
|
class Command(BaseCommand):
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
repair_data(verbose=True)
|
repair_data(verbose=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user