Ori.livneh has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/70032


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, 25 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/debs/adminbot 
refs/changes/32/70032/1

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..71592bf 100644
--- a/adminlog.py
+++ b/adminlog.py
@@ -63,3 +63,8 @@
                snupdate = "%s: %s" % (author, message)
                snupdate = snupdate[:140]  # Trim message
                snapi.update(snupdate)
+
+       if config.enable_twitter:
+               import twitter
+               twitter_api = twitter.Api(**config.twitter_api_params)
+               twitter_api.PostUpdate('%s: %s' % (author, message))
diff --git a/config.py b/config.py
index 685ed5d..60a6969 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: newchange
Gerrit-Change-Id: I18c836dea5d39aff4811780abdedd24a7865d3d7
Gerrit-PatchSet: 1
Gerrit-Project: operations/debs/adminbot
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to