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()

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()

Fix for the new cloudly APi.
Fix for the new cloudly APi.

  from cloudly.pubsub import Pusher
- from cloudly.tweets import Tweets
+ from cloudly.tweets import Tweets, StreamManager, keep
- from cloudly.twitterstream import Streamer
  
  from webapp import config
  
+ pubsub = Pusher.open(config.pubsub_channel)
- 
- 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):
+ def processor(tweets):
-     return True
+     pubsub.publish(keep(['coordinates'], tweets), "tweets")
+     return len(tweets)
  
  
  def start():
+     streamer = StreamManager('locate', processor, is_queuing=False)
-     # 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()
  
Fix for the new cloudly APi.
## Code 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()

## Instruction:
Fix for the new cloudly APi.
## Code 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()
