From 6b45e4f0194d3eec6b175bf0f93a11e1d44b7992 Mon Sep 17 00:00:00 2001 From: t0xic0der Date: May 15 2020 13:25:03 +0000 Subject: [PATCH 1/6] Updated package versions in requirements.txt --- diff --git a/requirements.txt b/requirements.txt index c13ea77..dffa8d3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,35 +1,50 @@ +arrow==0.15.6 +attrs==19.3.0 +Automat==20.2.0 beautifulsoup4==4.3.2 -Cython==0.22 +certifi==2020.4.5.1 +chardet==3.0.4 +constantly==15.1.0 +cycler==0.10.0 +Cython==0.29.17 decorator==3.4.2 Django==1.8 -fedmsg==0.13.1 +fedmsg==1.1.1 fedmsg-meta-fedora-infrastructure==0.5.2 +hyperlink==19.0.0 +idna==2.9 image==1.3.9 +incremental==17.5.0 kitchen==1.2.1 -matplotlib==1.4.3 +kiwisolver==1.2.0 +lockfile==0.12.2 +matplotlib==3.2.1 mock==1.0.1 moksha.common==1.2.3 -moksha.hub==1.4.4 +moksha.hub==1.5.17 munch==2.0.2 nose==1.3.6 -numpy==1.9.2 +numpy==1.18.4 oauthlib==0.7.2 -Pillow==2.8.1 -psutil==2.2.1 -Pygments==2.0.2 -pyparsing==2.0.3 -python-dateutil==2.4.2 -python-fedora==0.4.0 -pytz==2015.2 -pyzmq==14.6.0 -requests==2.6.2 -requests-oauthlib==0.4.2 -scipy==0.15.1 -six==1.9.0 -tweepy==3.3.0 -Twisted==15.1.0 +openidc-client==0.6.0 +Pillow==7.1.2 +psutil==5.7.0 +Pygments==2.6.1 +PyHamcrest==2.0.2 +pyparsing==2.4.7 +PySocks==1.7.1 +python-dateutil==2.8.1 +python-fedora==1.0.0 +pytz==2020.1 +pyzmq==19.0.1 +requests==2.23.0 +requests-oauthlib==1.3.0 +scipy==1.4.1 +six==1.14.0 +tweepy==3.8.0 +Twisted==20.3.0 txWS==0.9.1 -txZMQ==0.7.4 -urllib3==1.10.3 -wordcloud==1.0.0 -zope.interface==4.1.2 +txZMQ==0.8.2 +urllib3==1.25.9 +wordcloud==1.7.0 +zope.interface==5.1.0 From 4cb5beb80115a8ce073acdeb61249f9c63d9566a Mon Sep 17 00:00:00 2001 From: t0xic0der Date: May 15 2020 13:25:25 +0000 Subject: [PATCH 2/6] Reworked wordcloudbot.py for Python 3 compliance --- diff --git a/wordcloudbot.py b/wordcloudbot.py index 90c8e15..cbb9729 100755 --- a/wordcloudbot.py +++ b/wordcloudbot.py @@ -1,10 +1,7 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import os import site -site.addsitedir(os.path.dirname(__file__)) -site.addsitedir('/home/decause/.virtualenvs/word_cloud/lib/python2.7/site-packages/') - import fedmsg.config import fedmsg.meta @@ -13,6 +10,9 @@ import logging.config import tweepy from gencloud import generate_word_cloud, scrub_logs, get_meeting_log +site.addsitedir(os.path.dirname(__file__)) +site.addsitedir('/home/decause/.virtualenvs/word_cloud/lib/python2.7/site-packages/') + # first load the fedmsg config from fedmsg.d config = fedmsg.config.load_config() @@ -33,7 +33,7 @@ twitter_api = tweepy.API(auth_handler) fedmsg.init(active=True) -print "STARTING UP. Listening for fedmsg messages." +print("STARTING UP. Listening for fedmsg messages.") for name, endpoint, topic, msg in fedmsg.tail_messages(): if topic_filter not in topic: continue @@ -45,7 +45,7 @@ for name, endpoint, topic, msg in fedmsg.tail_messages(): content = subtitle + " " + link + " " + "#fedora" - print "Working with url", url + print("Working with url " + str(url)) # get the meeting log text = get_meeting_log(url) @@ -56,15 +56,14 @@ for name, endpoint, topic, msg in fedmsg.tail_messages(): # generate the word_cloud word_cloud = generate_word_cloud(text, mask) - - print "Tweeting %r" % content + print("Tweeting " + str(content)) twitter_api.update_with_media(word_cloud, content) try: os.remove(word_cloud) except Exception as e: - print "broked!", str(e) + print("broked! " + str(e)) fedmsg.publish(topic="log", modname="logger", msg=dict(msg="Tweeted, lol")) - print "Done." + print("Done.") From 3a92aec1e5a67f482de48ece72d510bd43fdd764 Mon Sep 17 00:00:00 2001 From: t0xic0der Date: May 15 2020 13:25:40 +0000 Subject: [PATCH 3/6] Reworked gencloud.py for Python 3 compliance --- diff --git a/gencloud.py b/gencloud.py index 20acbff..f4549ae 100644 --- a/gencloud.py +++ b/gencloud.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 """ Using custom colors ==================== @@ -37,13 +37,10 @@ def scrub_logs(text): def test_scrub_logs(): - scrubbed_logs = scrub_logs(""" - there once was a guy who was cool - blahblahblah this is the shit. - 1234567890 * pingou lol - """) - - print scrubbed_logs + scrubbed_logs = scrub_logs("there once was a guy who was cool" + \ + "blahblahblah this is the shit." + \ + "1234567890 * pingou lol") + print(scrubbed_logs) def grey_color_func(word, font_size, position, orientation, random_state=None): @@ -65,7 +62,7 @@ def generate_word_cloud(text, mask_filename): wc.recolor(color_func=grey_color_func, random_state=3) - _, tmpfilename = tempfile.mkstemp('-wordcloud.png') + _, tmpfilename = tempfile.mkstemp("-wordcloud.png") wc.to_file(tmpfilename) return tmpfilename @@ -79,6 +76,6 @@ def test_generate_word_cloud(): text = "\n".join(lines) scrubbed = scrub_logs(text) fname = generate_word_cloud(scrubbed, "Fedora_logo_simple.png") - print fname + print(fname) test_generate_word_cloud() From 5ec13c0bed96c57b43c789cc675bf27d49bd34c4 Mon Sep 17 00:00:00 2001 From: t0xic0der Date: May 15 2020 14:13:18 +0000 Subject: [PATCH 4/6] Picked imread from matplotlib --- diff --git a/gencloud.py b/gencloud.py index f4549ae..8f217c4 100644 --- a/gencloud.py +++ b/gencloud.py @@ -6,7 +6,14 @@ Using the recolor method and custom coloring functions. """ from os import path -from scipy.misc import imread + +# imread is deprecated after version 1.2.0. +# from scipy.misc import imread + +# Rather use, imread from matplotlib.pyplot +# Best for Python 3 compliance +from matplotlib.pyplot import imread + import matplotlib.pyplot as plt import random import tempfile From 4153aab96e2ec561bf12b8579be1fdb4cd3a1dc9 Mon Sep 17 00:00:00 2001 From: t0xic0der Date: May 15 2020 14:13:44 +0000 Subject: [PATCH 5/6] 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 From b8be79519e40ed9fb00466f0913c8ceec2ba0b90 Mon Sep 17 00:00:00 2001 From: t0xic0der Date: May 19 2020 04:08:37 +0000 Subject: [PATCH 6/6] Replaced old RPM packages to PIP ones --- diff --git a/README.rst b/README.rst index ca5a830..7a7f1d4 100644 --- a/README.rst +++ b/README.rst @@ -16,8 +16,9 @@ It's dangerous to go alone! Take this! sudo dnf install fedmsg sudo dnf install python-fedmsg-meta-fedora-infrastructure - sudo dnf install python-fabulous - sudo dnf install tweepy + sudo dnf install python3-pip + pip3 install fabulous --user + pip3 install tweepy --user ----