rmore autopep
This commit is contained in:
@@ -7,20 +7,22 @@ import arrow
|
|||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
from rowers.models import Rower,Workout
|
from rowers.models import Rower, Workout
|
||||||
import re
|
import re
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from rowers.dataprep import join_workouts
|
from rowers.dataprep import join_workouts
|
||||||
|
|
||||||
|
|
||||||
def name_short(name):
|
def name_short(name):
|
||||||
expr = '(.*)\s.*\(\d+\)'
|
expr = '(.*)\s.*\(\d+\)'
|
||||||
match = re.findall(expr,name)
|
match = re.findall(expr, name)
|
||||||
|
|
||||||
if match:
|
if match:
|
||||||
return match[0]
|
return match[0]
|
||||||
|
|
||||||
return name
|
return name
|
||||||
|
|
||||||
|
|
||||||
def get_duplicates(a):
|
def get_duplicates(a):
|
||||||
seen = {}
|
seen = {}
|
||||||
dupes = []
|
dupes = []
|
||||||
@@ -38,28 +40,25 @@ def get_duplicates(a):
|
|||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
rs = (r for r in Rower.objects.all() if r.ispaid and r.autojoin)
|
rs = (r for r in Rower.objects.all() if r.ispaid and r.autojoin)
|
||||||
now = timezone.now()
|
|
||||||
|
|
||||||
for r in rs:
|
for r in rs:
|
||||||
workouts = Workout.objects.filter(user=r,
|
workouts = Workout.objects.filter(user=r,
|
||||||
duplicate=False,
|
duplicate=False,
|
||||||
startdatetime__gte=timezone.now()-datetime.timedelta(days=2))
|
startdatetime__gte=timezone.now()-datetime.timedelta(days=2))
|
||||||
|
|
||||||
|
|
||||||
duplicates = get_duplicates(name_short(w.name) for w in workouts)
|
duplicates = get_duplicates(name_short(w.name) for w in workouts)
|
||||||
|
|
||||||
for name, count in duplicates.items():
|
for name, count in duplicates.items():
|
||||||
if count > 1:
|
if count > 1:
|
||||||
workouts2 = workouts.filter(
|
workouts2 = workouts.filter(
|
||||||
Q(name__contains=name)
|
Q(name__contains=name))
|
||||||
)
|
|
||||||
|
|
||||||
duplicates2 = get_duplicates(w.date for w in workouts)
|
duplicates2 = get_duplicates(w.date for w in workouts)
|
||||||
for dd, count in duplicates2.items():
|
for dd, count in duplicates2.items():
|
||||||
if count > 1:
|
if count > 1:
|
||||||
workouts3 = workouts2.filter(date=dd)
|
workouts3 = workouts2.filter(date=dd)
|
||||||
ids = [w.id for w in workouts3]
|
ids = [w.id for w in workouts3]
|
||||||
id, message = join_workouts(r,ids,title=name,
|
id, message = join_workouts(r, ids, title=name,
|
||||||
parent=workouts3[0],
|
parent=workouts3[0],
|
||||||
killparents=True)
|
killparents=True)
|
||||||
|
|||||||
@@ -1,15 +1,9 @@
|
|||||||
#!/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 *
|
from rowers.models import *
|
||||||
@@ -17,6 +11,12 @@ from rowsandall_app.settings import BASE_DIR
|
|||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|
||||||
|
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 getemails():
|
def getemails():
|
||||||
rs = Rower.objects.all()
|
rs = Rower.objects.all()
|
||||||
firstnames = [r.user.first_name for r in rs]
|
firstnames = [r.user.first_name for r in rs]
|
||||||
@@ -24,20 +24,18 @@ def getemails():
|
|||||||
emails = [r.user.email for r in rs]
|
emails = [r.user.email for r in rs]
|
||||||
is_actives = [r.user.is_active for r in rs]
|
is_actives = [r.user.is_active for r in rs]
|
||||||
df = pd.DataFrame({
|
df = pd.DataFrame({
|
||||||
'first_name':firstnames,
|
'first_name': firstnames,
|
||||||
'last_name':lastnames,
|
'last_name': lastnames,
|
||||||
'email':emails,
|
'email': emails,
|
||||||
'is_active':is_actives
|
'is_active': is_actives})
|
||||||
})
|
|
||||||
|
|
||||||
return df
|
return df
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
email_list = getemails()
|
email_list = getemails()
|
||||||
email_list.to_csv('email_list.csv',encoding='utf-8')
|
email_list.to_csv('email_list.csv', encoding='utf-8')
|
||||||
|
|
||||||
fullemail = 'roosendaalsander@gmail.com'
|
fullemail = 'roosendaalsander@gmail.com'
|
||||||
subject = "Rowsandall users list"
|
subject = "Rowsandall users list"
|
||||||
@@ -45,12 +43,13 @@ class Command(BaseCommand):
|
|||||||
message += "Best Regards, the Rowsandall Team"
|
message += "Best Regards, the Rowsandall Team"
|
||||||
message += "Users list attached \n\n"
|
message += "Users list attached \n\n"
|
||||||
|
|
||||||
email = EmailMessage(subject, message,
|
email = EmailMessage(
|
||||||
'Rowsandall <info@rowsandall.com>',
|
subject, message,
|
||||||
[fullemail])
|
'Rowsandall <info@rowsandall.com>',
|
||||||
|
[fullemail])
|
||||||
|
|
||||||
email.attach_file('email_list.csv')
|
email.attach_file('email_list.csv')
|
||||||
|
|
||||||
os.remove('email_list.csv')
|
os.remove('email_list.csv')
|
||||||
|
|
||||||
res = email.send()
|
_ = email.send()
|
||||||
|
|||||||
@@ -16,16 +16,16 @@ 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):
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
#!/srv/venv/bin/python
|
|
||||||
|
|
||||||
""" Process emails """
|
""" Process emails """
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
PY3K = sys.version_info >= (3, 0)
|
|
||||||
|
|
||||||
import zipfile
|
import zipfile
|
||||||
from zipfile import BadZipFile
|
from zipfile import BadZipFile
|
||||||
@@ -18,12 +15,12 @@ import json
|
|||||||
import io
|
import io
|
||||||
|
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
#from django_mailbox.models import Message, MessageAttachment,Mailbox
|
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from rowers.models import Workout, Rower
|
from rowers.models import User, Workout, Rower
|
||||||
|
|
||||||
from rowingdata import rower as rrower
|
from rowingdata import rower as rrower
|
||||||
from rowingdata import rowingdata as rrdata
|
from rowingdata import rowingdata as rrdata
|
||||||
@@ -37,7 +34,6 @@ import rowers.stravastuff as stravastuff
|
|||||||
import rowers.nkstuff as nkstuff
|
import rowers.nkstuff as nkstuff
|
||||||
from rowers.opaque import encoder
|
from rowers.opaque import encoder
|
||||||
|
|
||||||
from rowers.models import User,Workout
|
|
||||||
from rowers.rower_rules import user_is_not_basic
|
from rowers.rower_rules import user_is_not_basic
|
||||||
from rowers.utils import dologging
|
from rowers.utils import dologging
|
||||||
|
|
||||||
@@ -47,10 +43,14 @@ sys.path.append('$path_to_root_of_project$/$project_name$')
|
|||||||
|
|
||||||
os.environ['DJANGO_SETTINGS_MODULE'] = '$project_name$.settings'
|
os.environ['DJANGO_SETTINGS_MODULE'] = '$project_name$.settings'
|
||||||
|
|
||||||
if not getattr(__builtins__, "WindowsError", None):
|
PY3K = sys.version_info >= (3, 0)
|
||||||
class WindowsError(OSError): pass
|
|
||||||
|
|
||||||
def rdata(file_obj, rower=rrower()): # pragma: no cover
|
if not getattr(__builtins__, "WindowsError", None):
|
||||||
|
class WindowsError(OSError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def rdata(file_obj, rower=rrower()): # pragma: no cover
|
||||||
""" Read rowing data file and return 0 if file doesn't exist"""
|
""" Read rowing data file and return 0 if file doesn't exist"""
|
||||||
try:
|
try:
|
||||||
result = rrdata(file_obj, rower=rower)
|
result = rrdata(file_obj, rower=rower)
|
||||||
@@ -60,7 +60,6 @@ def rdata(file_obj, rower=rrower()): # pragma: no cover
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
def add_arguments(self, parser):
|
def add_arguments(self, parser):
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
@@ -68,71 +67,57 @@ 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", )
|
||||||
)
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--mailbox',
|
'--mailbox',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
dest='mailbox',
|
dest='mailbox',
|
||||||
default='workouts',
|
default='workouts',
|
||||||
help="Changing mailbox name",
|
help="Changing mailbox name", )
|
||||||
)
|
|
||||||
|
|
||||||
"""Run the Email processing command """
|
"""Run the Email processing command """
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
if 'testing' in options:
|
|
||||||
testing = options['testing']
|
|
||||||
else: # pragma: no cover
|
|
||||||
testing = False
|
|
||||||
|
|
||||||
# Polar
|
# Polar
|
||||||
try:
|
try:
|
||||||
polar_available = polarstuff.get_polar_notifications()
|
polar_available = polarstuff.get_polar_notifications()
|
||||||
res = polarstuff.get_all_new_workouts(polar_available)
|
_ = polarstuff.get_all_new_workouts(polar_available)
|
||||||
except: # pragma: no cover
|
except: # pragma: no cover
|
||||||
exc_type, exc_value, exc_traceback = sys.exc_info()
|
exc_type, exc_value, exc_traceback = sys.exc_info()
|
||||||
lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
|
lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
|
||||||
dologging('processemail.log',''.join('!! ' + line for line in lines))
|
dologging('processemail.log', ''.join('!! ' + line for line in lines))
|
||||||
|
|
||||||
# Concept2
|
# Concept2
|
||||||
try:
|
try:
|
||||||
rowers = Rower.objects.filter(c2_auto_import=True)
|
rowers = Rower.objects.filter(c2_auto_import=True)
|
||||||
for r in rowers: # pragma: no cover
|
for r in rowers: # pragma: no cover
|
||||||
if user_is_not_basic(r.user):
|
if user_is_not_basic(r.user):
|
||||||
c2stuff.get_c2_workouts(r)
|
c2stuff.get_c2_workouts(r)
|
||||||
except: # pragma: no cover
|
except: # pragma: no cover
|
||||||
exc_type, exc_value, exc_traceback = sys.exc_info()
|
exc_type, exc_value, exc_traceback = sys.exc_info()
|
||||||
lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
|
lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
|
||||||
dologging('processemail.log',''.join('!! ' + line for line in lines))
|
dologging('processemail.log', ''.join('!! ' + line for line in lines))
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
rowers = Rower.objects.filter(rp3_auto_import=True)
|
rowers = Rower.objects.filter(rp3_auto_import=True)
|
||||||
for r in rowers: # pragma: no cover
|
for r in rowers: # pragma: no cover
|
||||||
if user_is_not_basic(r.user):
|
if user_is_not_basic(r.user):
|
||||||
res = rp3stuff.get_rp3_workouts(r)
|
_ = rp3stuff.get_rp3_workouts(r)
|
||||||
except: # pragma: no cover
|
except: # pragma: no cover
|
||||||
exc_type, exc_value, exc_traceback = sys.exc_info()
|
exc_type, exc_value, exc_traceback = sys.exc_info()
|
||||||
lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
|
lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
|
||||||
dologging('processemail.log',''.join('!! ' + line for line in lines))
|
dologging('processemail.log', ''.join('!! ' + line for line in lines))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
rowers = Rower.objects.filter(nk_auto_import=True)
|
rowers = Rower.objects.filter(nk_auto_import=True)
|
||||||
for r in rowers: # pragma: no cover
|
for r in rowers: # pragma: no cover
|
||||||
if user_is_not_basic(r.user):
|
if user_is_not_basic(r.user):
|
||||||
s = 'Starting NK Auto Import for user {id}'.format(id=r.user.id)
|
s = 'Starting NK Auto Import for user {id}'.format(id=r.user.id)
|
||||||
dologging('nklog.log',s)
|
dologging('nklog.log', s)
|
||||||
res = nkstuff.get_nk_workouts(r)
|
_ = nkstuff.get_nk_workouts(r)
|
||||||
except: # pragma: no cover
|
except: # pragma: no cover
|
||||||
exc_type, exc_value, exc_traceback = sys.exc_info()
|
exc_type, exc_value, exc_traceback = sys.exc_info()
|
||||||
lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
|
lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
|
||||||
dologging('processemail.log',''.join('!! ' + line for line in lines))
|
dologging('processemail.log', ''.join('!! ' + line for line in lines))
|
||||||
|
|
||||||
# Strava
|
|
||||||
#rowers = Rower.objects.filter(strava_auto_import=True)
|
|
||||||
#for r in rowers:
|
|
||||||
# if user_is_not_basic(r.user): # pragma: no cover
|
|
||||||
# stravastuff.get_strava_workouts(r)
|
|
||||||
|
|
||||||
self.stdout.write(self.style.SUCCESS(
|
self.stdout.write(self.style.SUCCESS(
|
||||||
'Successfully processed email attachments'))
|
'Successfully processed email attachments'))
|
||||||
|
|||||||
Reference in New Issue
Block a user