def handle(number, message, mtype='sms'): cmd_str = message.split() if cmd_str[0] == "create": return db.create_player(number) elif cmd_str[0] == "round": round_id = db.create_round(number) db.join_round(number, round_id) return "round id %s" % round_id elif cmd_str[0] == "join" and len(cmd_str) == 2: return db.join_round(number, cmd_str[1]) elif cmd_str[0] == "score" and len(cmd_str) == 2: # need the round id, current hole, and total score to send to the new # score command return db.new_add_score(number, db.get_current_round(number), db.get_current_hole(number), cmd_str[1], int(db.get_score(number)) + int(cmd_str[1])) elif cmd_str[0] == "score" and len(cmd_str) == 1: return db.get_score(number) elif cmd_str[0] == "name" and len(cmd_str) == 2: return db.add_name(number, cmd_str[1]) elif cmd_str[0] == "name" and len(cmd_str) == 1: return db.get_name(number) elif cmd_str[0] == 'combine' and len(cmd_str) == 3: return db.combine(cmd_str[1], cmd_str[2]) elif cmd_str[0] == 'compare' and len(cmd_str) == 3: res = db.compare(cmd_str[1], cmd_str[2]) if res.player1 < res.player2: return "%s wins by %s" % (cmd_str[1], abs(res.player1 - res.player2)) elif res.player2 < res.player1: return "%s wins by %s" % (cmd_str[2], abs(res.player2 - res.player1)) else: return "Tie" elif cmd_str[0] == 'match' and len(cmd_str) == 5: for player in cmd_str[1:]: if not check_player_name(player): return "Player %s not in system" % player team1 = combine(cmd_str[1], cmd_str[2]).split() team2 = combine(cmd_str[3], cmd_str[4]).split() if team1[1] < team2[1]: return "%s and %s win" % (cmd_str[1], cmd_str[2]) elif team2[1] < team1[1]: return "%s and %s win" % (cmd_str[3], cmd_str[4]) else: return "Tie" elif cmd_str[0] == 'scores' and len(cmd_str) == 1: scores = db.scores(number) return ''.join('%s:%s, ' % (str(score.hole), str(score.score)) for score in scores) elif cmd_str[0] == 'front' and len(cmd_str) == 1: return db.front_nine(number) elif cmd_str[0] == 'back' and len(cmd_str) == 1: return db.back_nine(number) else: return "invalid command"
def moodtracker(): conn = db.connect() moods = db.get_moods(conn) zen = get_zen_message() if moods == []: return render_template("index.html", rating=0, pos_reasons=[['null'], ['null'], ['null'], ['null'], ['null']], neg_reasons=[['null'], ['null'], ['null'], ['null'], ['null']], recent_note='null', calendar=None, lineplot=None, zen=zen) calendar = graphs.calendar.plot(moods) lineplot = graphs.lineplot.plot(moods) rating = db.get_score(conn) recent_note = db.get_most_recent_note(conn) pos_reasons = db.get_top_positive_reasons(conn) neg_reasons = db.get_top_negative_reasons(conn) return render_template("index.html", rating=rating, pos_reasons=pos_reasons, neg_reasons=neg_reasons, recent_note=recent_note, calendar=calendar, lineplot=lineplot, zen=zen)
def show_contest(contest_name): contest = db.get_contest(contest_name) if contest: problems = db.get_contest_problems(contest_name) if g.user: user_solved = {p.name: db.get_score(g.user, p.name) for p in problems} else: user_solved = {} end_time = contest.start_time + contest.duration return my_render_template( "contest.html", contest=contest, problems=[(i + 1, p) for i, p in enumerate(problems)], user_solved=user_solved, end_time=end_time, ) else: return page_not_found()
def show_contest(contest_name): contest = db.get_contest(contest_name) if contest: problems = db.get_contest_problems(contest_name) if g.user: user_solved = { p.name: db.get_score(g.user, p.name) for p in problems } else: user_solved = {} end_time = contest.start_time + contest.duration return my_render_template('contest.html', contest=contest, problems=[(i + 1, p) for i, p in enumerate(problems)], user_solved=user_solved, end_time=end_time) else: return page_not_found()
def find_info(bar_code): r = requests.get( 'http://www.goodsmatrix.ru/goods/d/{}.html'.format(bar_code)) s = r.content.decode("windows-1251") soup = BeautifulSoup(s, 'lxml') title = soup.title.string if title.strip() == u'Гудс Матрикс': return None, None, None mark = soup.find('span', id="ctl00_ContentPH_Mark_MarkL") reviews_score = db.get_score(bar_code) print(reviews_score) if mark is not None and reviews_score is not None: mark = (float(mark.string.split()[0].replace(',', '.')) / 2 + float(reviews_score)) / 2 elif reviews_score is not None: mark = float(reviews_score) elif mark is not None: mark = float(mark.string.split()[0].replace(',', '.')) / 2 mark_num = soup.find('span', id="ctl00_ContentPH_Mark_MarkNum") if mark_num is not None: mark_num = mark_num.string return title, mark, mark_num