How to use on_get method in localstack

Best Python code snippet using localstack_python

server.py

Source:server.py Github

copy

Full Screen

...450class RootHandler(object):451 def on_options(self, req, resp):452 respondXML(resp, falcon.HTTP_204, xmlSuccess())453class AddStudent(RootHandler):454 def on_get(self, req, resp):455 with session_scope() as session:456 user = auth(session, req, resp)457 course = Course.fromRequest(session, req)458 if user not in course.teachers:459 raise NotAuthorized()460 student = User.fromRequest(session, req)461 course.students.append(student)462 respondXML(resp, falcon.HTTP_200, xmlSuccess())463class AddTeacher(RootHandler):464 def on_get(self, req, resp):465 with session_scope() as session:466 user = auth(session, req, resp)467 userName = forceParam(req, 'userName')468 course = Course.fromRequest(session, req)469 if user not in course.teachers:470 raise NotAuthorized()471 teacher = User.fromRequest(session, req)472 course.teachers.append(teacher)473 respondXML(resp, falcon.HTTP_200, xmlSuccess())474class ChangePassword(RootHandler):475 def on_get(self, req, resp):476 with session_scope() as session:477 user = auth(session, req)478 new_password = forceParam('newPassword')479 user.password = hash_password(user.userName, new_password)480 session.add(user)481 respondXML(resp, falcon.HTTP_200, xmlSuccess())482class CreateAssignment(RootHandler):483 def on_get(self, req, resp):484 with session_scope() as session:485 course = Course.fromRequest(session, req)486 name = forceParam(req, 'name')487 if user not in course.teachers:488 raise NotAuthorized()489 assignId = generateAssignmentId()490 assignment = Assignment(assignId=assignId, courseId=courseId,491 name=name)492 success = Elt('success', {'assignId': assignId})493 respondXML(resp, falcon.HTTP_200, formatXML(success))494class CreateCourse(RootHandler):495 def on_get(self, req, resp):496 with session_scope() as session:497 user = auth(session, req, resp)498 name = req.get_param('name')499 courseId = generateCourseId()500 course = Course(courseId=courseId, name=name, teachers=[user])501 session.add(course)502 el = Elt('success', {'courseId': courseId})503 respondXML(resp, falcon.HTTP_200, formatXML(el))504class CreateProject(RootHandler):505 def on_get(self, req, resp):506 with session_scope() as session:507 user = auth(session, req, resp)508 projId = generateProjId()509 proj = Project(projId=projId, owners=[user])510 proj.members.append(user)511 session.add(proj)512 el = Elt('success', {'projId': projId})513 respondXML(resp, falcon.HTTP_200, formatXML(el))514class CreateUser(RootHandler):515 def on_get(self, req, resp):516 username = req.get_param('userName')517 password = req.get_param('password')518 email = req.get_param('email')519 send_email = False520 if not validUsername(username):521 return sendError(resp,522 '{0} is not a valid username.'.format(username))523 if userExists(username):524 return sendError(resp, '{0} is already in use.'.format(username))525 if password is None and email is not None:526 password = generate_password()527 send_email = True528 with session_scope() as session:529 user = User(userName=username,530 password=hash_password(username, password),531 email=email)532 session.add(user)533 res = Elt('success')534 res.appendChild(Elt('user', {535 'userName': username,536 'password': password,537 'email': email538 }))539 respondXML(resp, falcon.HTTP_200, formatXML(res))540 if send_email:541 send_initial_email(user, password)542class Login(RootHandler):543 def on_get(self, req, resp):544 with session_scope() as session:545 user = auth(session, req, resp)546 res = Elt('success')547 res.appendChild(Elt('user', {548 'userName': user.userName,549 }))550 respondXML(resp, falcon.HTTP_200, formatXML(res))551class Logout(RootHandler):552 def on_get(self, req, resp):553 with session_scope() as session:554 username, password = removeUserPass(req, resp)555 respondXML(resp, falcon.HTTP_200, formatXML(Elt('success')))556class Enroll(RootHandler):557 def on_get(self, req, resp):558 with session_scope() as session:559 user = auth(session, req, resp)560 course = Course.fromRequest(session, req)561 course.students.append(user)562 respondXML(resp, falcon.HTTP_200, xmlSuccess())563class GetProjectByName(RootHandler):564 def on_get(self, req, resp):565 with session_scope() as session:566 user = User.fromRequest(session, req)567 projectName = forceParam(req, 'projectName')568 projects = session.query(Project) \569 .filter(Project.members.contains(user)) \570 .filter(Project.sharedName == projectName) \571 .all()572 success = Elt('success')573 for proj in projects:574 success.appendChild(proj.toXML(req))575 respondXML(resp, falcon.HTTP_200, formatXML(success))576class GetRevision(RootHandler):577 def on_get(self, req, resp):578 with session_scope() as session:579 user = auth(session, req, resp)580 revision = Revision.fromRequest(session, req)581 success = Elt('success')582 success.appendChild(revision.toXML())583 respondXML(resp, falcon.HTTP_200, formatXML(success))584class ListAssignments(RootHandler):585 def on_get(self, req, resp):586 with session_scope() as session:587 course = Course.fromRequest(session, req)588 assigns = session.query(Assignment) \589 .filter(Assignment.course == course) \590 .all()591 success = Elt('success')592 for assign in assigns:593 success.appendChild(assign.toXMLId())594 respondXML(resp, falcon.HTTP_200, formatXML(success))595class ListCoursesEnrolled(RootHandler):596 def on_get(self, req, resp):597 with session_scope() as session:598 user = auth(session, req, resp)599 success = Elt('success')600 for course in user.coursesTaking:601 success.appendChild(course.toXMLId())602 respondXML(resp, falcon.HTTP_200, formatXML(success))603class ListCoursesTeaching(RootHandler):604 def on_get(self, req, resp):605 with session_scope() as session:606 teacher = User.fromRequest(session, req)607 success = Elt('success')608 for course in teacher.coursesTeaching:609 success.appendChild(course.toXMLId())610 respondXML(resp, falcon.HTTP_200, formatXML(success))611class ListMembers(RootHandler):612 def on_get(self, req, resp):613 with session_scope() as session:614 user = auth(session, req, resp)615 project = Project.fromRequest(session, req)616 if user not in project.members:617 raise NotAuthorized()618 success = Elt('success')619 for member in project.members:620 success.appendChild(member.toXMLName())621 respondXML(resp, falcon.HTTP_200, formatXML(success))622class ListProjects(RootHandler):623 def on_get(self, req, resp):624 with session_scope() as session:625 user = auth(session, req, resp)626 projects = session.query(Project) \627 .filter(Project.members.contains(user)) \628 .all()629 success = Elt('success')630 for proj in projects:631 success.appendChild(proj.toXML(req))632 respondXML(resp, falcon.HTTP_200, formatXML(success))633class ListStudents(RootHandler):634 def on_get(self, req, resp):635 with session_scope() as session:636 user = auth(session, req, resp)637 course = Course.fromRequest(session, req)638 if user not in course.teachers:639 raise NotAuthorized()640 success = Elt('success')641 for student in course.students:642 success.appendChild(student.toXMLName())643 respondXML(resp, falcon.HTTP_200, xmlSuccess())644class ListSubmissions(RootHandler):645 def on_get(self, req, resp):646 with session_scope() as session:647 user = auth(session, req, resp)648 assignment = Assignment.fromRequest(session, req)649 if user not in assignment.course.teachers:650 raise NotAuthorized()651 success = Elt('success')652 for submission in assignment.submissions:653 success.appendChild(submission.toShortXML())654 respondXML(resp, falcon.HTTP_200, formatXML(success))655class ListTeachers(RootHandler):656 def on_get(self, req, resp):657 with session_scope() as session:658 course = Course.fromRequest(session, req)659 success = Elt('success')660 for teacher in course.teachers:661 success.appendChild(teacher.toXMLName())662 respondXML(resp, falcon.HTTP_200, formatXML(success))663class LoadProject(RootHandler):664 def on_get(self, req, resp):665 with session_scope() as session:666 user = auth(session, req, resp)667 project = Project.fromRequest(session, req)668 if user not in project.members:669 raise NotAuthorized()670 success = Elt('success')671 success.appendChild(project.toXML(req))672 respondXML(resp, falcon.HTTP_200, formatXML(success))673class MakePublic(RootHandler):674 def on_get(self, req, resp):675 with session_scope() as session:676 user = auth(session, req, resp)677 project = Project.fromRequest(session, req)678 if user not in project.members:679 raise NotAuthorized()680 project.public = True681 respondXML(resp, falcon.HTTP_200, xmlSuccess())682class RemoveStudent(RootHandler):683 def on_get(self, req, resp):684 with session_scope() as session:685 user = auth(session, req, resp)686 course = Course.fromRequest(session, req)687 if user not in course.teachers:688 raise NotAuthorized()689 student = User.fromRequest(session, req)690 try:691 course.students.remove(student)692 except ValueError:693 raise UserLogicError('User is not taking this course.')694 respondXML(resp, falcon.HTTP_200, xmlSuccess())695class RemoveTeacher(RootHandler):696 def on_get(self, req, resp):697 with session_scope() as session:698 user = auth(session, req, resp)699 course = Course.fromRequest(session, req)700 teacher = User.fromRequest(session, req)701 if user not in course.teachers:702 raise NotAuthorized()703 if len(course.teachers) == 1:704 raise NotPermitted()705 try:706 course.teachers.remove(teacher)707 except ValueError:708 raise UserLogicError('User is not teaching this course.')709 respondXML(resp, falcon.HTTP_200, xmlSuccess())710class ResetPassword(RootHandler):711 def on_get(self, req, resp):712 with session_scope() as session:713 user = User.fromRequest(session, req)714 if user.email is None:715 raise UserLogicError('Cannot reset password without email.')716 password = generate_password()717 user.password = hash_password(username, password)718 session.add(user)719 respondXML(resp, falcon.HTTP_200, xmlSuccess())720 send_reset_email(user, password)721class SaveProject(RootHandler):722 def on_post(self, req, resp):723 with session_scope() as session:724 user = auth(session, req, resp)725 project = Project.fromRequest(session, req)726 if user not in project.members:727 raise NotAuthorized()728 contents = req.stream.read()729 prevId = formatHash(0)730 sharedName = req.get_param('sharedName')731 if sharedName is not None:732 project.sharedName = sharedName733 if project.head is not None:734 prevId = project.head.revId735 sha1 = hashlib.sha1()736 sha1.update(prevId)737 sha1.update(contents)738 revId = sha1.hexdigest()739 revision, created = get_or_create(session, Revision, revId=revId,740 prevId=prevId)741 project.head = revision742 session.add(project)743 session.add(revision)744 respondXML(resp, falcon.HTTP_200, xmlSuccess({'revId': revId}))745 if created:746 revision.save(contents)747class ShareProject(RootHandler):748 def on_get(self, req, resp):749 with session_scope() as session:750 user = auth(session, req, resp)751 project = Project.fromRequest(session, req)752 if user not in project.members:753 raise NotAuthorized()754 newMember = User.fromRequest(session, req)755 project.members.append(newMember)756 respondXML(resp, falcon.HTTP_200, xmlSuccess())757class ShareProjectWithStudents(RootHandler):758 def on_get(self, req, resp):759 with session_scope() as session:760 user = auth(session, req, resp)761 project = Project.fromRequest(session, req)762 if user not in project.members:763 raise NotAuthorized()764 course = Course.fromRequest(session, req)765 if user not in course.teachers:766 raise NotAuthorized()767 project.course_shared_with_students.append(course)768 respondXML(resp, falcon.HTTP_200, xmlSuccess())769class ShareProjectWithTeachers(RootHandler):770 def on_get(self, req, resp):771 with session_scope() as session:772 user = auth(session, req, resp)773 project = Project.fromRequest(session, req)774 if user not in project.members:775 raise NotAuthorized()776 course = Course.fromRequest(session, req)777 if user not in course.students and user not in course.teachers:778 raise NotAuthorized()779 project.course_shared_with_teachers.append(course)780 respondXML(resp, falcon.HTTP_200, xmlSuccess())781class SubmitProject(RootHandler):782 def on_get(self, req, resp):783 with session_scope() as session:784 user = auth(session, req, resp)785 assignment = Assignment.fromRequest(session, req)786 project = Project.fromRequest(session, req)787 if user not in project.members:788 raise NotAuthorized()789 if user not in assignment.course.students:790 raise UserLogicError('User not enrolled in '791 'the class for this assignment')792 submission = Submission()793 submission.submitId = generateSubmissionId()794 submission.assignment = assignment795 submission.revision = project.head796 submission.project = project797 submission.members = project.members798 submission.submitter = user799 submission.time = datetime.datetime.utcnow()800 session.add(submission)801 respondXML(resp, falcon.HTTP_200, xmlSuccess())802class UnCreateAssignment(RootHandler):803 def on_get(self, req, resp):804 with session_scope() as session:805 assignment = Assigment.fromRequest(session, req)806 if user not in assignment.course.teachers:807 raise NotAuthorized()808 session.delete(assignment)809 respondXML(resp, falcon.HTTP_200, xmlSuccess())810class UnCreateProject(RootHandler):811 def on_get(self, req, resp):812 with session_scope() as session:813 user = auth(session, req, resp)814 project = Project.fromRequest(session, req)815 if user not in project.owners:816 raise NotAuthorized()817 session.delete(project)818 respondXML(resp, falcon.HTTP_200, xmlSuccess())819class UnEnroll(RootHandler):820 def on_get(self, req, resp):821 with session_scope() as session:822 user = auth(session, req, resp)823 course = Course.fromRequest(session, req)824 try:825 course.students.remove(user)826 except ValueError:827 raise UserLogicError('User is not taking this course.')828 respondXML(resp, falcon.HTTP_200, xmlSuccess())829class UnMakePublic(RootHandler):830 def on_get(self, req, resp):831 with session_scope() as session:832 user = auth(session, req, resp)833 project = Project.fromRequest(session, req)834 if user not in project.members:835 raise NotAuthorized()836 project.public = False837 respondXML(resp, falcon.HTTP_200, xmlSuccess())838class UnShareProject(RootHandler):839 def on_get(self, req, resp):840 with session_scope() as session:841 user = auth(session, req, resp)842 project = Project.fromRequest(session, req)843 if user not in project.members:844 raise NotAuthorized()845 toRemove = User.fromRequest(session, req)846 if toRemove in project.owners:847 raise NotAuthorized()848 project.members.remove(toRemove)849 respondXML(resp, falcon.HTTP_200, xmlSuccess())850class UnShareProjectWithStudents(RootHandler):851 def on_get(self, req, resp):852 with session_scope() as session:853 user = auth(session, req, resp)854 project = Project.fromRequest(session, req)855 if user not in project.members and user not in project.teachers:856 raise NotAuthorized()857 course = Course.fromRequest(session, req)858 if course not in project.course_shared_with_students:859 raise UserLogicError('Project not shared with students in '860 'this couse.')861 project.course_shared_with_students.remove(course)862 respondXML(resp, falcon.HTTP_200, xmlSuccess())863class UnShareProjectWithTeachers(RootHandler):864 def on_get(self, req, resp):865 with session_scope() as session:866 user = auth(session, req, resp)867 project = Project.fromRequest(session, req)868 if user not in project.members:869 raise NotAuthorized()870 course = Course.fromRequest(session, req)871 if course not in project.course_shared_with_teachers:872 raise UserLogicError('Project not shared with teachers in '873 'this couse.')874 project.course_shared_with_teachers.remove(course)875 respondXML(resp, falcon.HTTP_200, xmlSuccess())876class NoMethod(RootHandler):877 def on_get(self, req, resp):878 respondXML(resp, falcon.HTTP_400, xmlError('No method in url.'))879class UnknownMethod(RootHandler):880 def on_get(self, req, resp, method):881 respondXML(resp,882 falcon.HTTP_400,883 xmlError('Unknown method {0!r} in url.'.format(method)))884def raise_unknown_url(req, resp):885 raise UnknownURL()886def set_access_control(req, resp, params):887 resp.set_header('Access-Control-Allow-Origin', '*')888 resp.set_header('Access-Control-Allow-Headers',889 'Snap-Server-Authorization, Authorization')890 resp.set_header('Access-Control-Allow-Methods', 'GET, POST')891 resp.set_header('Allow', 'GET, POST')892sql_engine = sqlengine.create_engine('sqlite:///snap.sqlite', echo=False)893sql_connection = sql_engine.connect()894Session = sessionmaker(bind=sql_engine)...

Full Screen

Full Screen

restfuls.py

Source:restfuls.py Github

copy

Full Screen

...63 resp.body = dump_json(getattr(resource, relAttr), self.typeString)64class PlayerResource(Resource):65 def __init__(self):66 super(PlayerResource, self).__init__('player', Player)67 def on_get(self, req, resp, playerId):68 self.get_one(req, resp, playerId)69 def on_patch(self, req, resp, playerId):70 player = self.update_one(req, resp, playerId)71 if player.avatarUrl is None and player.email is not None:72 player.avatarUrl = gen_gravatar_url(player.email)73 resp.body = dump_json(player, self.typeString)74 def on_delete(self, req, resp, playerId):75 self.delete_one(req, resp, playerId)76class PlayerCollection(Resource):77 def __init__(self):78 super(PlayerCollection, self).__init__('player', Player)79 def on_get(self, req, resp):80 self.list_all(req, resp)81 def on_post(self, req, resp):82 newPlayer = self.create_one(req, resp)83 if newPlayer.avatarUrl is None and newPlayer.email is not None:84 newPlayer.avatarUrl = gen_gravatar_url(newPlayer.email)85 resp.body = dump_json(newPlayer, self.typeString)86class PlayersForGameResource(OneToManyResource):87 def __init__(self):88 super(PlayersForGameResource, self).__init__('player', Game)89 def on_get(self, req, resp, gameId):90 self.get_many_for_one(req, resp, gameId, 'players')91class GameResource(Resource):92 def __init__(self):93 super(GameResource, self).__init__('game', Game)94 def on_get(self, req, resp, gameId):95 self.get_one(req, resp, gameId)96 def on_patch(self, req, resp, gameId):97 resource = self.update_one(req, resp, gameId)98 resp.body = dump_json(resource, self.typeString)99 def on_delete(self, req, resp, gameId):100 self.delete_one(req, resp, gameId)101class GameCollection(Resource):102 def __init__(self):103 super(GameCollection, self).__init__('game', Game)104 def on_get(self, req, resp):105 self.list_all(req, resp)106 def on_post(self, req, resp):107 newGame = self.create_one(req, resp)108 resp.body = dump_json(newGame, self.typeString)109class GamesForPlayerResource(OneToManyResource):110 def __init__(self):111 super(GamesForPlayerResource, self).__init__('game', Player)112 def on_get(self, req, resp, playerId):113 self.get_many_for_one(req, resp, playerId, 'games')114class GameEventResource(Resource):115 def __init__(self):116 super(GameEventResource, self).__init__('event', GameEvent)117 def on_get(self, req, resp, eventId):118 self.get_one(req, resp, eventId)119 # No PATCH or DELETE for events. 120class GameEventCollection(Resource):121 def __init__(self):122 super(GameEventCollection, self).__init__('event', GameEvent)123 def on_get(self, req, resp):124 self.list_all(req, resp)125 def on_post(self, req, resp):126 newEvent = None127 try:128 attrs = GameEvent.parse_json_payload(req.stream.read(), self.typeString)129 try:130 game = Game.get(attrs['gameID'])131 except KeyError:132 raise ValueError("Missing 'game-id' attribute")133 if not game.active:134 raise ValueError('Events cannot be created for an inactive game')135 newEvent = GameEvent(**attrs)136 except ValueError as ex:137 raise falcon.HTTPBadRequest('Bad Request', ex.message)138 except formencode.api.Invalid as ex:139 raise falcon.HTTPBadRequest('Bad Request', str(ex))140 # Mark when a player joins a game. Everyone who ever joined the game is141 # part of the game's players, even if they leave.142 if newEvent.eventType == 'joined':143 game = newEvent.game144 player = newEvent.player145 if player not in game.players:146 game.addPlayer(player)147class EventsForPlayerResource(OneToManyResource):148 def __init__(self):149 super(EventsForPlayerResource, self).__init__('event', Player)150 def on_get(self, req, resp, playerId):151 self.get_many_for_one(req, resp, playerId, 'events')152class EventsForGameResource(OneToManyResource):153 def __init__(self):154 super(EventsForGameResource, self).__init__('event', Game)155 def on_get(self, req, resp, gameId):156 self.get_many_for_one(req, resp, gameId, 'events')157class AchievementTypeResource(Resource):158 def __init__(self):159 super(AchievementTypeResource, self).__init__('achievement-type', AchievementType)160 def on_get(self, req, resp, achievementTypeId):161 self.get_one(req, resp, playerId)162 def on_patch(self, req, resp, achievementTypeId):163 achievementType = self.update_one(req, resp, playerId)164 resp.body = dump_json(achievementType, self.typeString)165 def on_delete(self, req, resp, achievementTypeId):166 self.delete_one(req, resp, achievementTypeId)167class AchievementTypeCollection(Resource):168 def __init__(self):169 super(AchievementTypeCollection, self).__init__('achievement-type', AchievementType)170 def on_get(self, req, resp):171 self.list_all(req, resp)172 def on_post(self, req, resp):173 newAchievementType = self.create_one(req, resp)174 resp.body = dump_json(newAchievementType, self.typeString)175class AchievementResource(Resource):176 def __init__(self):177 super(AchievementResource, self).__init__('achievement', Achievement)178 def on_get(self, req, resp, achievementId):179 self.get_one(req, resp, playerId)180 def on_patch(self, req, resp, achievementId):181 achievement = self.update_one(req, resp, playerId)182 resp.body = dump_json(achievement, self.typeString)183 def on_delete(self, req, resp, achievementId):184 self.delete_one(req, resp, achievementId)185class AchievementCollection(Resource):186 def __init__(self):187 super(AchievementCollection, self).__init__('achievement-type', Achievement)188 def on_get(self, req, resp):189 self.list_all(req, resp)190 def on_post(self, req, resp):191 newAchievement = self.create_one(req, resp)192 resp.body = dump_json(newAchievement, self.typeString)193class AchievementsForPlayerResource(OneToManyResource):194 195 def __init__(self):196 super(AchievementsForPlayerResource, self).__init__('achievement', Player)197 def on_get(self, req, resp, playerId):198 self.get_many_for_one(req, resp, playerId, 'achievements')199class AchievementsForGameResource(OneToManyResource):200 201 def __init__(self):202 super(AchievementsForGameResource, self).__init__('achievement', Game)203 def on_get(self, req, resp, playerId):204 self.get_many_for_one(req, resp, gameId, 'achievements')205def gen_gravatar_url(email):206 email = email.strip().lower()...

Full Screen

Full Screen

handlers.py

Source:handlers.py Github

copy

Full Screen

...32 "descricao": h.description,33 "como_usar": h.usage,34 "rota": h.route35 }36 def on_get(self, req, resp):37 resp.media = self.instances38class Subestacoes(Handler):39 description = "Lista subestações, códigos e suas subestacoes."40 usage = "GET retorna a lista."41 route = "/subestacoes"42 def on_get(self, req, resp):43 resp.media = rows2dicts(self.db.subestacoes());44class Equipamentos(Handler):45 description = "Obtém informações gerais de equipamentos."46 usage = "GET retorna lista com informações básicas."47 route = "/equipamentos/{cod_subestacao}"48 def on_get(self, req, resp, cod_subestacao):49 resultados = self.db.equipamentos(cod_subestacao)50 if resultados:51 resp.media = rows2dicts(resultados)52 else:53 resp.status = falcon.HTTP_40454class Equipamento(Handler):55 description = "Retorna dados detalhados sobre um equipamento"56 usage = "GET retorna lista com vários dados"57 route = "/equipamento/{cod_equipamento}"58 def on_get(self, req, resp, cod_equipamento):59 resultados = self.db.equipamento(cod_equipamento)60 if resultados:61 resp.media = dict(resultados)62 else:63 resp.status = falcon.HTTP_40464class Ocorrencias(Handler):65 description = "Retorna todas as ocorrências numa subestacao e ano"66 usage = "GET com código de subestacao e ano retorna a lista"67 route = "/ocorrencias/{cod_subestacao}/{ano}"68 def on_get(self, req, resp, cod_subestacao, ano):69 resultados = self.db.ocorrencias(cod_subestacao, ano)70 if resultados:71 resp.media = rows2dicts(resultados)72 else:73 resp.status = falcon.HTTP_40474class Unidades(Handler):75 description = "Listar os as siglas, nome e subtipos das unidades do sistema."76 usage = "GET retorna a lista."77 route = "/unidades"78 def on_get(self, req, resp):79 resp.media = rows2dicts(self.db.unidades())80class PreverTempo(Handler):81 description = "Obter a previsão do tempo para uma subestacao."82 usage = "GET com código de subestacao retorna os dados de previsão."83 route = "/forecast/{cod_subestacao}"84 def on_get(self, req, resp, cod_subestacao):85 subestacao = self.db.subestacao(cod_subestacao)86 if not subestacao:87 resp.status = falcon.HTTP_40488 else:89 resp.media = hg.get_previsao(subestacao["cidade"])90class RiscoClimatologico(Handler):91 description = ("Obter a relação de risco climatológico dos equipamentos numa "92 "subestacao por código.")93 usage = "GET com código de subestacao retorna os dados."94 route = "/risco_climatologico/{cod_subestacao}"95 def on_get(self, req, resp, cod_subestacao):96 subestacao = self.db.subestacao(cod_subestacao)97 if not subestacao:98 resp.status = falcon.HTTP_40499 else:100 resp.media = self.db.relacao_rc(cod_subestacao)101class PreverRiscos(Handler):102 description = ("Obter a lista de equipamentos numa subestacao que podem estar "103 "sujeitos a falha de origem climatológica nos próximos dias.")104 usage = "GET com código de subestacao retorna os dados."105 route = "/prever_risco/{cod_subestacao}"106 def on_get(self, req, resp, cod_subestacao):107 subestacao = self.db.subestacao(cod_subestacao)108 if not subestacao:109 resp.status = falcon.HTTP_404110 return111 prev = hg.get_previsao(subestacao["cidade"])112 rc = self.db.relacao_rc(cod_subestacao)113 dias = {}114 forecast = prev["results"]["forecast"]115 for f in forecast:116 dia = f["date"]117 tempo = f["condition"]118 riscos = {}119 if tempo == "rain":120 rates = cs.RATES_BAD...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful