def createCaseCreators(case_creator_names, case): """ Takes in an array of strings which are names Takes in a case, which is a Case object It finds the ParliamentMember who has that name and creates a CaseCreator object from the ParliamentMember and the inputted Case. If the ParliamentMember is not found, we log to Sentry as then a new one has to be created in the database """ for case_creator_name in case_creator_names: try: parliament_member = ParliamentMember.objects.get( name=case_creator_name) except ParliamentMember.DoesNotExist: parliament_member = ParliamentMember.objects.create( name=case_creator_name) SentryLogger.warning('Parliament member created: ' + case_creator_name) # Add parliament member to parliament case.parliament_session.parliament.parliament_members.add( parliament_member) CaseCreator.objects.create(case=case, parliament_member=parliament_member)
def do(self): ''' Executes the cron job ''' try: SentryLogger.warning('Starting bill and promise connection') promise_services.find_connected_bills_and_promises() SentryLogger.warning('Completed bill and promise connection') except BaseException: SentryLogger.error(traceback.format_exc()) raise
def do(self): try: SentryLogger.warning('Starting votes gather') parliament_sessions = ParliamentServices.get_parliament_sessions_to_look_at() for parliament_session in parliament_sessions: VoteServices.get_votes_by_parliament_session( parliament_session) SentryLogger.warning('Votes gather done') except BaseException: SentryLogger.error(traceback.format_exc()) raise
def do(self): try: SentryLogger.warning('Starting case gather') parliament_sessions = ParliamentServices.get_parliament_sessions_to_look_at( ) for parliament_session in parliament_sessions: print(parliament_session.session_number) CaseGatheringService.update_cases_by_session_number( parliament_session) SentryLogger.warning('Case gather done') except BaseException: SentryLogger.error(traceback.format_exc()) raise
def save_votes(vote_record, parliament_session): ''' We take in the newly create vote record and look at its details page. There we can find each individual vote made by each parliament member, if a vote has taken place. We then create a new vote or update the existing one. ''' try: vote_details_soup = soupUtils.getSoupFromLink( details_link + str(vote_record.althingi_id)) votes = get_parliament_member_votes(vote_details_soup) for vote in votes: parliament_member_name = get_parliament_member_name_from_vote(vote) try: parliament_member = ParliamentMember.objects.get( name=parliament_member_name) except ParliamentMember.DoesNotExist: parliament_member = ParliamentMember.objects.create( name=parliament_member_name) SentryLogger.warning('Parliament member created: ' + parliament_member_name) parliament_session.parliament.parliament_members.add( parliament_member) vote_result = get_parliament_member_result_from_vote(vote) vote = Vote.objects.filter(parliament_member=parliament_member, vote_record=vote_record) if vote.exists(): # Update the result if the vote exists vote.update(althingi_result=vote_result, ) else: # Create new vote if it does not exist Vote.objects.create(parliament_member=parliament_member, althingi_result=vote_result, vote_record=vote_record) except: print('Saving votes failed')