def get(self): self._current_user = self.require_login() if not self._current_user: self.response.out.write(json.dumps({"error": "please log in"})) return newhacker = Hacker(first_name = self.request.get("first_name"), last_name = self.request.get("last_name"), user = self._current_user.id, catchphrase = self.request.get("catchphrase"), imageset = self.request.get("image"), level = 1, base_energy = int(self.request.get("energy")), base_productivity = int(self.request.get("productivity")), base_teamwork = int(self.request.get("teamwork"))) if self.request.get("clss"): newhacker.talents = [self.request.get("clss")] newhacker.put() self.response.out.write(json.dumps({"success": "new hacker created"}))
def create_or_update_hacker(strategy, details, response, user, *args, **kwargs): if hasattr(user, 'hacker'): # If there's a hacker already, this is an existing user, and we'll # update the hacker. hacker = user.hacker else: # If there's no hacker, that means this is a new user. Let's make the # hacker. hacker = Hacker(user=user) changed = False for name, value in details.items(): if name in HACKER_ATTRIBUTES: setattr(hacker, name, value) changed = True if changed: hacker.save()
def post(self): # grab argument to know what operation we want operation = request.args.get('operation') try: amount = int(request.args.get('amount')) except: return { 'status': 'error', 'message': 'amount arg needs to be an int' }, 400 if not (amount or operation): return { 'status': 'error', 'message': 'no operation or amount argument given' }, 400 if operation == 'delete all': Team.query.delete() Submission.query.delete() Hacker.query.delete() Grade.query.delete() db.session.commit() return {'status': 'success'}, 200 if operation == 'single full build': for index in range(amount): # create team team = Team('Team number {}'.format(index)) submission = Submission('this is a description', 'this is a devpost link', 'this is a youtube link') team.submission = submission # create hacker hacker = Hacker('hacker name {}'.format(index), 'email{}@gmail.com'.format(index)) team.team_members.append(hacker) # add new objects to db db.session.add(team) db.session.commit() return {'status': 'success'}, 200 if operation == 'multi full build': # grab second amount try: second_amount = int(request.args.get('second_amount')) except: return { 'status': 'error', 'message': 'second_amount arg needs to be an int' }, 400 if not second_amount: return { 'status': 'error', 'message': 'no second_amount argument given for multi operation' }, 400 for index in range(amount): # create team team = Team('Team number {}'.format(index)) submission = Submission('this is a description', 'this is a devpost link', 'this is a youtube link') team.submission = submission # create hacker for num in range(second_amount): hacker = Hacker('hacker name {} - {}'.format(index, num), 'email{}_{}@gmail.com'.format(index, num)) team.team_members.append(hacker) # add new objects to db db.session.add(team) db.session.commit() return {'status': 'success'}, 200
import random import operator from models import Bank, Hacker, Muscle, Locker_Picker if __name__ == "__main__": print('Python Heist') rolodex = [] garrett = Muscle("garrett", 75, 10) william = Hacker("william", 75, 10) asia = Locker_Picker("asia", 100, 25) rolodex.append(garrett) rolodex.append(william) rolodex.append(asia) print(f'The rolodex currently has {len(rolodex)} heisters to select!') # build crew while True: user_Input_Name = input( 'Please add a new crew member. Or press enter to choose your team ' ) if user_Input_Name == "": break while True: user_Input_Specialty = input( f'What is {user_Input_Name}\'s specialty: hacker, muscle or lock picker?? ' ) if user_Input_Specialty.lower() == 'muscle': user_Input_skill = input('What is their skill level? ') user_Input_Cut = input('What is their take on this score ') new_Muscle = Muscle(user_Input_Name, int(user_Input_skill), int(user_Input_Cut))