jenkins-bot has submitted this change and it was merged.

Change subject: Enable logging to Twitter via Twitter API v1.1
......................................................................


Enable logging to Twitter via Twitter API v1.1

Twitter disabled v1.0 of their API on 12 June 2013, at which point identi.ca's
cross-posting functionality ceased to work. identi.ca is migrating to a new
platform called 'pump.io' and their plans for re-enabling the Twitter bridge
are vague. On that date, #wikimedia-operation's morebots (which utilizes this
package) ceased to post updates to Twitter.

This patch allows adminlogbot to log directly to Twitter via the new API. It
does so using python-twitter v1+, which Faidon backported to Ubuntu Precise per
RT 5356. The patch adds detailed instructions for generating the requisite
access tokens to config.py.

I tested this change.

I am not a fan of the conditional import pattern or of the configuration file
being a Python module, but am following existing conventions in the interest of
seeing a fix through.

Someone in TechOps should follow up with another patch updating the metadata in
debian/ to declare the dependency on python-twitter and to bump the package
version.

Bug: 49476
RT: 5356
Change-Id: I18c836dea5d39aff4811780abdedd24a7865d3d7
---
M README
M adminlog.py
M config.py
3 files changed, 28 insertions(+), 3 deletions(-)

Approvals:
  Faidon: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/README b/README
index b872168..e3d2a1a 100644
--- a/README
+++ b/README
@@ -3,3 +3,6 @@
        irclib: 
http://downloads.sourceforge.net/python-irclib/python-irclib-0.4.6.tar.gz?modtime=1135442433&big_mirror=0
        simplejson: http://pypi.python.org/pypi/simplejson/
 
+Optional dependencies:
+        python-twitter (v1+): https://launchpad.net/python-twitter
+
diff --git a/adminlog.py b/adminlog.py
index 4e16cf6..93e5727 100644
--- a/adminlog.py
+++ b/adminlog.py
@@ -56,10 +56,15 @@
                                        config.wiki_category + ']]</noinclude>')
        page.save('\n'.join(lines), "%s (%s)" % (message, author))
 
+       micro_update = ("%s: %s" % (author, message))[:140]
+
        if config.enable_identica:
                snapi = statusnet.StatusNet({'user': config.identica_username,
                        'passwd': config.identica_password,
                        'api': 'https://identi.ca/api'})
-               snupdate = "%s: %s" % (author, message)
-               snupdate = snupdate[:140]  # Trim message
-               snapi.update(snupdate)
+               snapi.update(micro_update)
+
+       if config.enable_twitter:
+               import twitter
+               twitter_api = twitter.Api(**config.twitter_api_params)
+               twitter_api.PostUpdate(micro_update)
diff --git a/config.py b/config.py
index 685ed5d..ca3369b 100644
--- a/config.py
+++ b/config.py
@@ -8,6 +8,23 @@
 # Log messages to identica
 enable_identica = False
 
+# Log messages to Twitter
+enable_twitter = False
+
+# OAuth settings and access tokens for the Twitter API
+# To obtain these tokens, go to <https://dev.twitter.com/apps> and sign in.
+# Click 'Create a new application' and fill out the form. Leave 'Callback URL'
+# unspecified. When you've created your application, click 'Settings',
+# change 'Application Type' to 'Read and Write', and click 'Update this Twitter
+# application's settings'. Finally, go back to the 'Details' tab and click
+# 'Create my access token'.
+twitter_api_params = {
+       'access_token_key': 
'NNNNNNNNNN-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
+       'access_token_secret': 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
+       'consumer_key': 'XXXXXXXXXXXXXXXXXXXXX',
+       'consumer_secret': 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
+}
+
 # Channels to join
 targets = ("", "")
 

-- 
To view, visit https://gerrit.wikimedia.org/r/70032
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I18c836dea5d39aff4811780abdedd24a7865d3d7
Gerrit-PatchSet: 3
Gerrit-Project: operations/debs/adminbot
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <o...@wikimedia.org>
Gerrit-Reviewer: Andrew Bogott <abog...@wikimedia.org>
Gerrit-Reviewer: Faidon <fai...@wikimedia.org>
Gerrit-Reviewer: Ryan Lane <rl...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to