本文整理汇总了Python中models.Match.create方法的典型用法代码示例。如果您正苦于以下问题:Python Match.create方法的具体用法?Python Match.create怎么用?Python Match.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Match
的用法示例。
在下文中一共展示了Match.create方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: entry
# 需要导入模块: from models import Match [as 别名]
# 或者: from models.Match import create [as 别名]
def entry():
if not session.get('user'):
return redirect(url_for('index'))
user = session.get('user')
u = User.select().where(User.username == user)[0]
already_entered = Crush.select().where(Crush.user == u)
if request.method == 'POST':
entries = filter(None, request.form.getlist("entry"))
if len(entries) > 5:
return redirect('entry')
captcha = request.form.get('g-recaptcha-response')
captcha_r = requests.post('https://www.google.com/recaptcha/api/siteverify',
data={'secret': '6Lcd-gcTAAAAANlxsT-ptOTxsgRiJKTGTut2VgLk',
'response': captcha,
'remoteip': request.remote_addr})
if not captcha_r.json()['success']:
return render_template('entry.html', user=user, entries=entries,
already_entered=already_entered,
already_entered_count=already_entered.count())
if not any(entries):
return redirect('entry')
suggestions = map(lookup, entries)
for i, entry in enumerate(entries):
if entry not in suggestions[i]:
return render_template('entry.html', user=user,
entries=entries,
suggestions=suggestions,
already_entered=already_entered,
already_entered_count=already_entered.count())
for entry in entries:
exists = Crush.select().where(Crush.user == u, Crush.crush == entry).count()
if not exists:
Crush.create(user=u, crush=entry)
crush_user_exists = User.select().where(User.username == entry).count()
if crush_user_exists:
crush_user = User.select().where(User.username == entry)[0]
crush_user_crushes = map(lambda m: m.crush, Crush.select().where(Crush.user == crush_user))
if crush_user and u.username in crush_user_crushes:
Match.create(user_1 = u, user_2 = crush_user)
return redirect('/matches')
return render_template('entry.html', user=user,
already_entered=already_entered,
already_entered_count=already_entered.count())
示例2: syncMatchTable
# 需要导入模块: from models import Match [as 别名]
# 或者: from models.Match import create [as 别名]
def syncMatchTable(self):
self.connection.request("GET", "/sync/match")
response = self.connection.getresponse()
data = response.read()
data = json.loads(data)
print response.read()
print data
if not data.has_key('up-to-date'):
for match in data['name']:
try:
Match.create(iid=match['iid'],homeTeam=match['homeTeam'], awayTeam=match["awayTeam"], startTime=match['startTime'],
league=match['league'])
except Exception, e:
print str(e) + "- Match"
示例3: winner
# 需要导入模块: from models import Match [as 别名]
# 或者: from models.Match import create [as 别名]
def winner(self, message):
# 0: space, 1: winning verb, 2: loser_id, 3: first score, 4: second score
# then 0 or more of...
# 5: 2nd game hyphenated score, 6: 2nd game first score, 7: 2nd game second score
msg = message['text']
values = re.split(WINNER_REGEX, msg)
if not values or len(values) < 5:
return
loser_id = values[2]
# csv game list starts after the end of the slack username
games_csv = msg[(msg.index('>') + 1):]
games = games_csv.replace(' ', '').split(',')
for game in games:
scores = game.split('-')
if len(scores) != 2:
continue
first_score = int(scores[0])
second_score = int(scores[1])
try:
match = Match.create(winner=message['user'], winner_score=first_score, loser=loser_id, loser_score=second_score)
self.talk('<@' + loser_id + '>: Please type "Confirm ' + str(match.id) + '" to confirm the above match or ignore it if it is incorrect')
except Exception as e:
self.talk('Unable to save match. ' + str(e))
示例4: create_test_data
# 需要导入模块: from models import Match [as 别名]
# 或者: from models.Match import create [as 别名]
def create_test_data(self):
user = User.get_or_create(123)
User.get_or_create(12345)
db.session.commit()
team1 = Team.create(user, 'EnvyUs', 'fr', 'nv', ['76561198053858673'])
team2 = Team.create(user, 'Fnatic', 'se', 'fntc',
['76561198053858673'])
server = GameServer.create(user, '127.0.0.1', '27015', 'password')
server.in_use = True
GameServer.create(user, '127.0.0.1', '27016', 'password')
db.session.commit()
Match.create(user, team1.id, team2.id, 1, False,
'Map {MAPNUMBER}', ['de_dust2', 'de_cache', 'de_mirage'], server.id)
db.session.commit()
示例5: winner
# 需要导入模块: from models import Match [as 别名]
# 或者: from models.Match import create [as 别名]
def winner(self, message):
values = re.split(WINNER_REGEX, message['text'])
#0: blank, 1: loser_id, 2: first score, 3: second score, 4: blank
if not values or len(values) != 5:
return
try:
match = Match.create(winner=message['user'], winner_score=values[2], loser=values[1], loser_score=values[3])
self.talk('<@' + values[1] + '>: Please type "Confirm ' + str(match.id) + '" to confirm the above match or ignore it if it is incorrect')
except Exception as e:
self.talk('Unable to save match. ' + str(e))
示例6: add_match
# 需要导入模块: from models import Match [as 别名]
# 或者: from models.Match import create [as 别名]
def add_match(match_id):
"""Queries a match from the Steam API and adds it to the database.
Returns True if it succeeds or if match already exists, or False if it fails.
"""
match = api.get_match_details(match_id)["result"]
if "error" in match:
return False
try:
new_match = Match.create(**match)
except IntegrityError:
return True
except PyDotaError:
return False
player_list = [dict(match_id=new_match.match_id, **player) for player in match["players"]]
with db.atomic():
MatchPlayer.insert_many(player_list).execute()
return True
示例7: match_create
# 需要导入模块: from models import Match [as 别名]
# 或者: from models.Match import create [as 别名]
def match_create():
if not g.user:
return redirect('/login')
form = MatchForm(request.form)
form.add_teams(g.user)
form.add_servers(g.user)
if request.method == 'POST':
num_matches = g.user.matches.count()
max_matches = config_setting('USER_MAX_MATCHES')
if max_matches >= 0 and num_matches >= max_matches and not g.user.admin:
flash('You already have the maximum number of matches ({}) created'.format(
num_matches))
if form.validate():
mock = config_setting('TESTING')
server = GameServer.query.get_or_404(form.data['server_id'])
match_on_server = g.user.matches.filter_by(
server_id=server.id, end_time=None, cancelled=False).first()
server_avaliable = False
json_reply = None
if g.user.id != server.user_id and not server.public_server:
server_avaliable = False
message = 'This is not your server!'
elif match_on_server is not None:
server_avaliable = False
message = 'Match {} is already using this server'.format(
match_on_server.id)
elif mock:
server_avaliable = True
message = 'Success'
else:
json_reply, message = util.check_server_avaliability(
server)
server_avaliable = (json_reply is not None)
if server_avaliable:
skip_veto = 'preset' in form.data['series_type']
try:
max_maps = int(form.data['series_type'][2])
except ValueError:
max_maps = 1
match = Match.create(
g.user, form.data['team1_id'], form.data['team2_id'],
form.data['team1_string'], form.data['team2_string'],
max_maps, skip_veto, form.data['match_title'],
form.data['veto_mappool'], form.data['server_id'])
# Save plugin version data if we have it
if json_reply and 'plugin_version' in json_reply:
match.plugin_version = json_reply['plugin_version']
else:
match.plugin_version = 'unknown'
server.in_use = True
db.session.commit()
app.logger.info('User {} created match {}, assigned to server {}'
.format(g.user.id, match.id, server.id))
if mock or match.send_to_server():
return redirect('/mymatches')
else:
flash('Failed to load match configs on server')
else:
flash(message)
else:
get5.flash_errors(form)
return render_template(
'match_create.html', form=form, user=g.user, teams=g.user.teams,
match_text_option=config_setting('CREATE_MATCH_TITLE_TEXT'))