예제 #1
0
    def process(self, tweet):
        stored_tweet = Repository.create(tweet)

        if stored_tweet is None:
            return None

        username = tweet.user.username
        sorted_scores = self.get_potential_places(tweet)
        actual_places = self.places[username]
        actual_communes = self.communes[username]

        # Iterate over all the potential places by score to find commune
        for potential_place, score in sorted_scores:
            potential_commune = potential_place

            # If the place is a commune, restrict all places to be inside that commune
            if potential_commune in actual_communes:
                actual_places = actual_communes[potential_place]

                # We found a commune, do not look for any more
                break

        # Iterate over all the potential places by score
        for potential_place, score in sorted_scores:

            # Check if the potential place is in the actual places
            if potential_place in actual_places:
                actual_place = actual_places[potential_place]

                # Create a relation between the tweet and the place
                position = self.link_tweet_to_place(tweet, actual_place)

                # We found a place, so lets move on to the next weet
                break

        return Repository.read(tweet.id)
 def test_processor_creates_a_tweet_in_the_database(self):
     processor = Processor()
     processor.process(self.tweet)
     stored_tweet = Repository.read('6969')
     assert stored_tweet.id == '6969'