<commit_before>from cloudly.pubsub import Pusher
from cloudly.tweets import Tweets
from cloudly.twitterstream import Streamer

from webapp import config


class Publisher(Pusher):
    def publish(self, tweets, event):
        """Keep only relevant fields from the given tweets."""
        stripped = []
        for tweet in tweets:
            stripped.append({
                'coordinates': tweet['coordinates'],
            })
        super(Publisher, self).publish(stripped, event)


def processor(tweet):
    return True


def start():
    # This trick of importing the current module is for RQ workers to
    # correctly unpickle the `processor` function.
    from webapp import publish

    pubsub = publish.Publisher.open(config.pubsub_channel)
    streamer = Streamer(publish.processor, pubsub=pubsub, is_queuing=True,
                        cache_length=100)

    tweets = Tweets()
    streamer.run(tweets.with_coordinates())


if __name__ == "__main__":
    start()
<commit_msg>Fix for the new cloudly APi.<commit_after>from cloudly.pubsub import Pusher
from cloudly.tweets import Tweets, StreamManager, keep

from webapp import config

pubsub = Pusher.open(config.pubsub_channel)


def processor(tweets):
    pubsub.publish(keep(['coordinates'], tweets), "tweets")
    return len(tweets)


def start():
    streamer = StreamManager('locate', processor, is_queuing=False)
    tweets = Tweets()
    streamer.run(tweets.with_coordinates())


if __name__ == "__main__":
    start()

{'fraction_non_alphanumeric': 0.09792085848423876, 'fraction_numerical': 0.002012072434607646, 'mean_word_length': 3.427299703264095, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6135726', 'n_tokens_mistral': 463, 'n_tokens_neox': 448, 'n_words': 123}