def gen_saturdays(start="2017-9-2", weeks=13, include_january=False): """ include_january: date of last game """ args = list(map(lambda x: int(x), start.split("-"))) start = date(*args) delta = timedelta(days=7) weeks = int(weeks) curr = start saturdays = [] for i in range(weeks + 1): saturdays.append(curr) curr += delta weeks = [] for num, saturday in enumerate(saturdays): weeks.append(Week(date=saturday, num=num + 1)) if include_january: weeks.append(Week(date=include_january, num=num + 1)) session.add_all(weeks) session.commit() return weeks
def home(): season, num_week = get_season_week() games = Game.query.filter_by(week=num_week) if games is None: week = Week(num_week) week.add_games(num_week) games = Game.query.filter_by(week=num_week) update_scores()
def resolve_week_ranking(self, info, weeknum, year): # num = args.get('weeknum') # year = args.get('year') if not weeknum: j = WeekModel.current_week_rankings() else: j = WeekModel.week_rankings(weeknum, year) return WeeklyRanking(rankings=j)
def iterate_week(): iterate = IterateWeekForm() if iterate.submit.data and iterate.validate_on_submit(): Week.iterate() week = Week.query.all() week_number = [x.week_number for x in week][0] PlayerActive.iterate(week_number) print("iterated") return redirect('/index')
def reset_draft(): settings = Settings.query.all() is_active = [x.active for x in settings][0] reset = ResetForm() if reset.submit.data and reset.validate_on_submit() and is_active == 1: print("reset validated") PlayerStatus.reset() Settings.reset() PlayerWeeklyStats.reset() Week.reset() return redirect('/index')
def reset_all(): settings = Settings.query.all() is_active = [x.active for x in settings][0] reset_all = ResetAllForm() if reset_all.submit.data and reset_all.validate_on_submit( ) and is_active == 1: print("resetall validated") PlayerStatus.reset() Settings.reset() PlayerWeeklyStats.reset() User.delete_users() Week.reset() return redirect('/index')
def index(): user = current_user week = get_season_week()[1] games = Game.query.filter_by(week=week) if games is None: week = Week(week) week.add_games(num_week) games = Game.query.filter_by(week=num_week) update_scores() if current_user.is_authenticated: if current_user.confirmed: return render_template('index.html', user=user, title='Home') else: return redirect(url_for('auth.unconfirmed')) return render_template('index.html', user=user, title='Home')
def new_week(): teacher = Teacher.query.filter_by(id=current_user.id).first() blocks = teacher.blocks form = WeekForm() form.block.choices = [( block.id, f'{block.subject.title} {block.title}', ) for block in teacher.blocks] if form.validate_on_submit(): week = Week( block_id=int(form.block.data), week_number=form.week_number.data, start_date=form.start_date.data, end_date=form.end_date.data, ) try: db.session.add(week) db.session.commit() except exc.SQLAlchemyError: flash( f'Week {form.week_number.data} for this class already exists', 'warning', ) return redirect(url_for('weeks')) return render_template('weeks/new_week.html', blocks=blocks, form=form)
def get_submission(user): # submission = SubmissionModel.query.filter(UserModel.name == user.name).first() # current_week = WeekModel.query.order_by(WeekModel.date.desc()).first() # print("current week is " + str(WeekModel.current_week().num)) current_week = WeekModel.current_week() submission = SubmissionModel.query.join(WeekModel).filter( WeekModel.id == current_week.id).join(UserModel).filter( UserModel.name == user.name).first() print("Getting submission %s for user %s" % (str(submission), user.name)) return submission
def gen_week(d=date.today()): year = d.year if d.month == 1: year = year - 1 w = Week.query.filter(func.extract('year', Week.date) == year).order_by( Week.date.desc()).first() if d.month == 1: new_week = Week(date=d, num=0) else: if w: new_week = Week(date=d, num=w.num + 1) else: new_week = Week(date=d, num=1) if bool(Week.query.filter(Week.date == new_week.date).first()): return None session.add(new_week) session.commit() return new_week
def scrap_weeks(): weeks = {} year = Year.query.all() for item in year: url = 'http://wildstat.com/{}'.format(item.url) if url: weeks[item.id] = Crawler.get_week(url) time.sleep(0.1) for item in weeks: for week in weeks[item]: w = Week(year_id=item, name=week, url=weeks[item][week]) db.session.add(w) db.session.commit() return jsonify(weeks)
def get_program_from_dom(dom: str) -> ProgramSchema: soup = BeautifulSoup(dom, 'html.parser') all_dom_weeks = soup.select('.card') weeks = [] title = soup.find('h3').string for dom_week in all_dom_weeks: weeks.append( Week( workouts=[ 'https://thenx.com' + workout.attrs['href'] for workout in dom_week.find_all('a') ], title=dom_week.find('h5').string, )) return Program(title=title, weeks=weeks)
def resolve_current_week(self, info): # return WeekModel.query.order_by(WeekModel.date.desc()).first() return WeekModel.current_week()