From 4153aab96e2ec561bf12b8579be1fdb4cd3a1dc9 Mon Sep 17 00:00:00 2001 From: t0xic0der Date: May 15 2020 14:13:44 +0000 Subject: Made code snips comply to Python 3 --- diff --git a/README.rst b/README.rst index 0d7ca91..ca5a830 100644 --- a/README.rst +++ b/README.rst @@ -14,22 +14,22 @@ It's dangerous to go alone! Take this! .. code:: bash - sudo yum install fedmsg - sudo yum install python-fedmsg-meta-fedora-infrastructure - sudo yum install python-fabulous - sudo yum install tweepy + sudo dnf install fedmsg + sudo dnf install python-fedmsg-meta-fedora-infrastructure + sudo dnf install python-fabulous + sudo dnf install tweepy ---- Your first fedmsg script ~~~~~~~~~~~~~~~~~~~~~~~~ -.. code:: python +.. code:: python3 import fedmsg import pprint - print "Posting up to listen on the fedmsg bus. Waiting for a message..." + print("Posting up to listen on the fedmsg bus. Waiting for a message...") for name, endpoint, topic, msg in fedmsg.tail_messages(): pprint.pprint(msg) @@ -40,10 +40,10 @@ Give it a run. It's like a million voices cried out and then were silent ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. code:: python +.. code:: python3 - #topic_filter = 'fedbadges' # We really want this, but its rare - topic_filter = 'fedoratagger' # This is much easier to test with + #topic_filter = "fedbadges" # We really want this, but its rare + topic_filter = "fedoratagger" # This is much easier to test with for name, endpoint, topic, msg in fedmsg.tail_messages(): if topic_filter not in topic: @@ -59,7 +59,7 @@ See http://fedmsg.com/en/latest/topics for more Some config at the top ~~~~~~~~~~~~~~~~~~~~~~ -.. code:: python +.. code:: python3 import fedmsg.config import logging.config @@ -75,7 +75,7 @@ Some config at the top So meta ~~~~~~~ -.. code:: python +.. code:: python3 import fedmsg.meta @@ -93,14 +93,14 @@ So meta # Use it to make nice text and other things # See also: msg2icon, msg2link, msg2usernames, msg2packages... subtitle = fedmsg.meta.msg2subtitle(msg, **config) - print subtitle + print(subtitle) ---- A picture is worth a thousand words ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. code:: python +.. code:: python3 import tempfile import urllib @@ -113,12 +113,12 @@ A picture is worth a thousand words icon = fedmsg.meta.msg2icon(msg, **config) _, filename = tempfile.mkstemp(suffix='.png') - print "Downloading", icon, "to", filename + print("Downloading", icon, "to", filename) urllib.urlretrieve(icon, filename) - print fabulous.image.Image(filename) + print(fabulous.image.Image(filename)) - print "Cleaning up %r" % filename + print("Cleaning up %r" % filename) os.remove(filename) @@ -152,7 +152,7 @@ First, add a directory called ``fedmsg.d/`` to your current working directory. In it, put a file called ``fedmsg.d/twitter-secrets.py`` that looks like this: -.. code:: python +.. code:: python3 config = dict( consumer_key = "your api key goes here", @@ -174,7 +174,7 @@ Using those secrets Go back to ``yourwordcloudbot.py`` and add the following: -.. code:: python +.. code:: python3 import tweepy @@ -192,7 +192,7 @@ Go back to ``yourwordcloudbot.py`` and add the following: And further down ~~~~~~~~~~~~~~~~ -.. code:: python +.. code:: python3 for name, endpoint, topic, msg in fedmsg.tail_messages(): @@ -201,16 +201,16 @@ And further down icon = fedmsg.meta.msg2icon(msg, **config) _, filename = tempfile.mkstemp(suffix='.png') - print "Downloading", icon, "to", filename + print("Downloading", icon, "to", filename) urllib.urlretrieve(icon, filename) # Construct and post our tweet. - #print fabulous.image.Image(filename) + #print(fabulous.image.Image(filename)) content = subtitle + " " + link - print "Tweeting %r" % content + print("Tweeting %r" % content) twitter_api.update_with_media(filename, content) - print "Cleaning up %r" % filename + print("Cleaning up %r" % filename) os.remove(filename) ---- @@ -390,7 +390,7 @@ if you want to consume fedmsg-tail --really-pretty -.. code:: python +.. code:: python3 { "i": 1, @@ -413,12 +413,12 @@ if you want to consume consuming messages from python ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. code:: python +.. code:: python3 import fedmsg for name, endpoint, topic, msg in fedmsg.tail_messages(): - print topic, msg + print(topic, msg) consuming messages with a daemon @@ -429,7 +429,7 @@ long-running consumers simpler. There are `docs on fedmsg.com `_ for writing plugins, but they look like this: -.. code:: python +.. code:: python3 import pprint import fedmsg.consumers