Exemplo n.º 1
0
def function1(line):
    dist = Distributer()
    tweet_text = naturalLanguage.setTweet(line)
    if dist.isAboutElection(tweet_text,query_list):
        dist.extractToElection(tweet_text)
    else:
        dist.extractToAll(tweet_text)
    return list(set(dist.passElection() )) 
Exemplo n.º 2
0
def function1(line,queue,counter,tenth):
    dist = Distributer()
    tweet_text = naturalLanguage.setTweet(line)
    if dist.isAboutElection(tweet_text,query_list):
        dist.extractToElection(tweet_text)
    else:
        dist.extractToAll(tweet_text)
    progress(counter,tenth)
    queue.put(list(set(dist.passElection() )) )
Exemplo n.º 3
0
def function1(line):
    dist = Distributer()
    tweet_text = setTweet(line)
    if dist.isAboutElection(tweet_text, query_list):
        dist.extractToElection(tweet_text)
    else:
        dist.extractToAll(tweet_text)
    progress()
    # if dist.passElection() != []:
    #    print ",".join(dist.passElection())
    return dist.passElection()
Exemplo n.º 4
0
    def create_pdf(self, data):
        """Build, interpret, and distribute PDF award

        Arguments: 
            self
            data:   dictionary. POST request data, as well as data from the result of the post request
                    keys = award_id, authorizing_user_id, receiving_user_id, awarded_datetime, type
        Returns: 
            True if email was POST to database successful. False if unsuccessful.
            Does NOT Return the result of following handling of PDF. 
            This is designed so that an admin could manually generate award & send out if there was an issue with PDF creation -- 
            the user isn't prevented from creating the award if there IS a problem.
        """
        # Set up instances of helper classes
        builder = Builder(self.connection_data, data['type'])
        interpreter = Interpreter()
        distributer = Distributer(data['award_id'])

        # Build the Award Contents
        logging.info('AwardDriver.create_pdf(): building award contents')
        award_data = builder.query_database_for_data(data)
        modified_award_tex = builder.generate_award_tex(award_data)
        image = builder.query_bucket_for_image(award_data['SignaturePath'])

        # Initialize boolean success/failure variables to None
        pdf, write_successful = (None, None)
        email_successful, deletion_successful, distributed_updated = (False,
                                                                      False,
                                                                      False)

        # Build PDF from TEX + JPG if building award contents was successful
        if image is not None and modified_award_tex is not None:
            logging.info('AwardDriver.create_pdf(): building PDF')
            pdf = interpreter.interpret(award_data['SignaturePath'],
                                        modified_award_tex, image)

        # Send email if we have a PDF generated, or just say we did if email_on is False (for testing)
        if pdf is not None:
            # Technically don't NEED to additionally write to storage bucket, but it allows for
            # us to not lose award PDF if something goes wrong in this function
            # Writing to storage bucket instead of a SQL database because
            #   1) this is transient / temporary data
            #   2) it is not best practice to store files in a SQL database.
            logging.info(
                'AwardDriver.create_pdf(): saving PDF to storage bucket')
            write_successful = interpreter.write_award_to_bucket(
                data['award_id'], pdf)
            if self.email_on is True:
                logging.info('AwardDriver.create_pdf(): distributing email')
                email_successful = distributer.email_receiving_user(
                    pdf, award_data['email_address'], data['type'])
            else:
                email_successful = True

            # Show we sent email in database -- even if we're using no-email
            if email_successful is True:
                logging.info(
                    'AwardDriver.create_pdf(): updating distributed in database'
                )
                distributed_updated = distributer.update_distributed_in_database(
                    self.connection_data)

        # Clean-up PDF from storage bucket
        if email_successful is True and write_successful is True:
            logging.info(
                'AwardDriver.create_pdf(): deleting PDF from storage bucket')
            deletion_successful = distributer.delete_award_from_bucket()

        # Only returns true if email sent
        logging.info(
            'AwardDriver.create_pdf(): returning {}'.format(email_successful))
        return email_successful