From b67799cb6e4b2382769b0d80e8ddfa5e420ef51d Mon Sep 17 00:00:00 2001 From: Mogar Date: Wed, 19 Oct 2016 17:48:05 -0700 Subject: [PATCH 1/9] adding new xmpp wikibot example --- appengine/standard/xmpp_wikibot/README.md | 62 ++++++ .../standard/xmpp_wikibot/requirements.txt | 3 + appengine/standard/xmpp_wikibot/wikibot.py | 207 ++++++++++++++++++ 3 files changed, 272 insertions(+) create mode 100644 appengine/standard/xmpp_wikibot/README.md create mode 100644 appengine/standard/xmpp_wikibot/requirements.txt create mode 100644 appengine/standard/xmpp_wikibot/wikibot.py diff --git a/appengine/standard/xmpp_wikibot/README.md b/appengine/standard/xmpp_wikibot/README.md new file mode 100644 index 00000000000..43302e9ec03 --- /dev/null +++ b/appengine/standard/xmpp_wikibot/README.md @@ -0,0 +1,62 @@ +# Wikibot example that can be run on Google Compute Engine + +This sample shows how to use the [SleekXMPP](http://sleekxmpp.com/index.html) +client and [Flask](http://flask.pocoo.org/) to build a simple chatbot that can +be run on [Google Compute Engine](https://cloud.google.com/compute/). The +chatbot does two things: + 1. Sends messages to XMPP users via http get: + The server is running on port 5000 + if running on virtual machine use: + http://:5000/send_message?recipient=&message= + + If running locally use: + http://localhost:5000/send_message?recipient=&message= + + 2. Responds to incoming messages with a wikipedia page on the topic: + Send a message with a topic (e.g., 'Hawaii') to the XMPP account the server is using + It should respond with a Wikipedia page (when one exists) + +## Setup + +Follow the intstructions at the +[Compute Engine Quickstart Guide](https://cloud.google.com/compute/docs/quickstart-linux) +on how to create a project, create a virtual machine, and connect to your +instance via SSH. Once you have done this, you may jump to 'Installing files +and dependencies' + +You should also download the [Google Cloud SDK](https://cloud.google.com/sdk/). +It will allow you to access many of the features of Google Compute Engine via +your local machine. + + +### Installing files and dependencies + +First, install the wikibot.py and requirements.txt files onto your remote +instance. See the guide on +[Transferring Files](https://cloud.google.com/compute/docs/instances/transfer-files) +for more information on how to do this using the Mac file browser, scp, or +the Google Cloud SDK. + +Before running or deploying this application, you must install the dependencies +using [pip](http://pip.readthedocs.io/en/stable/): + + pip install -r requirements.txt + + +## Running the sample + +You'll need to have an XMPP account prior to actually running the sample. +If you do not have one, you can easily create an account at one of the many +XMPP servers such as [Jabber.at](https://jabber.at/account/register/). +Once you have an account, run the following command: + + python wikibot.py + +Then add the username (e.g., 'bob@jabber.at') and password for the account that +you'd like to use for your chatbot. + + +### Running on your local machine + +You may also run the sample locally by simply copying wikibot.py to a project +directory and installing all python dependencies there. \ No newline at end of file diff --git a/appengine/standard/xmpp_wikibot/requirements.txt b/appengine/standard/xmpp_wikibot/requirements.txt new file mode 100644 index 00000000000..6ffa9e0ddf8 --- /dev/null +++ b/appengine/standard/xmpp_wikibot/requirements.txt @@ -0,0 +1,3 @@ +Flask==0.11.1 +requests==2.11.1 +sleekxmpp==1.3.1 diff --git a/appengine/standard/xmpp_wikibot/wikibot.py b/appengine/standard/xmpp_wikibot/wikibot.py new file mode 100644 index 00000000000..ad2f725f3d7 --- /dev/null +++ b/appengine/standard/xmpp_wikibot/wikibot.py @@ -0,0 +1,207 @@ +# Copyright 2016 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Wikibot server example using SleekXMPP client library""" + +import sys +import logging +import getpass +from optparse import OptionParser +from flask import Flask, request +import requests +import threading +import urllib +import json + +import sleekxmpp + +# Python versions before 3.0 do not use UTF-8 encoding +# by default. To ensure that Unicode is handled properly +# throughout SleekXMPP, we will set the default encoding +# ourselves to UTF-8. +if sys.version_info < (3, 0): + from sleekxmpp.util.misc_ops import setdefaultencoding + setdefaultencoding('utf8') +else: + raw_input = input + +app = Flask(__name__) + +chat_client = None #this will be initialized when the wikibot is constructed + +@app.route('/send_message', methods=['GET']) +def send_message(): + try: + recipient = request.args.get('recipient') + message = request.args.get('message') + except KeyError as e: + logging.info("key error: {0}".format(e)) + + if chat_client and recipient and message: + chat_client.send_message(mto=recipient, mbody=message) + return "message sent to:" + recipient + " with body:" + message + else: + logging.info("chat client or recipient or message does not exist!") + return "message failed to send" + +def run_server(): + app.run(threaded=False, use_reloader=False) + +class WikiBot(sleekxmpp.ClientXMPP): + + """ + A simple SleekXMPP bot that will take messages, look up their content + on wikipedia and provide a link to the page if it exists + """ + + def __init__(self, jid, password): + sleekxmpp.ClientXMPP.__init__(self, jid, password) + + # The session_start event will be triggered when + # the bot establishes its connection with the server + # and the XML streams are ready for use. We want to + # listen for this event so that we we can initialize + # our roster. + self.add_event_handler("session_start", self.start) + + # The message event is triggered whenever a message + # stanza is received. Be aware that that includes + # MUC messages and error messages. + self.add_event_handler("message", self.message) + + def start(self, event): + """ + Process the session_start event. + Typical actions for the session_start event are + requesting the roster and broadcasting an initial + presence stanza. + Arguments: + event -- An empty dictionary. The session_start + event does not provide any additional + data. + """ + self.send_presence() + self.get_roster() + + def message(self, msg): + """ + Process incoming message stanzas. Be aware that this also + includes MUC messages and error messages. It is usually + a good idea to check the messages's type before processing + or sending replies. If the message is the appropriate type, + then the bot checks wikipedia to see if the message string + exists as a page on the site. If so, it sends this link back + to the sender in the reply. + Arguments: + msg -- The received message stanza. See the SleekXMPP documentation + for stanza objects and the Message stanza to see + how it may be used. + """ + if msg['type'] in ('chat', 'normal'): + msg_body = "%(body)s" % msg + logging.info("Message sent was: " + msg_body) + encoded_body = urllib.quote_plus(msg_body) + svrResponse = requests.get("https://en.wikipedia.org/w/api.php?action=parse&prop=sections&format=json&page=" + encoded_body) + doc = json.loads(svrResponse.content) + try: + page_id = str(doc['parse']['pageid']) + defn_url = 'https://en.wikipedia.org/?curid=' + page_id + msg.reply("find out more about: '" + msg_body + "' here: " + defn_url).send() + except KeyError as e: + logging.info("key error: {0}".format(e)) + msg.reply("I wasn't able to locate info on: '" + msg_body + "' Sorry").send() + + + + +if __name__ == '__main__': + # Setup the command line arguments. + optp = OptionParser() + + # Output verbosity options. + optp.add_option('-q', '--quiet', help='set logging to ERROR', + action='store_const', dest='loglevel', + const=logging.ERROR, default=logging.INFO) + optp.add_option('-d', '--debug', help='set logging to DEBUG', + action='store_const', dest='loglevel', + const=logging.DEBUG, default=logging.INFO) + optp.add_option('-v', '--verbose', help='set logging to COMM', + action='store_const', dest='loglevel', + const=5, default=logging.INFO) + + # JID and password options. + optp.add_option("-j", "--jid", dest="jid", + help="JID to use") + optp.add_option("-p", "--password", dest="password", + help="password to use") + + opts, args = optp.parse_args() + + # Setup logging. + logging.basicConfig(level=opts.loglevel, + format='%(levelname)-8s %(message)s') + + if opts.jid is None: + opts.jid = raw_input("Username: ") + if opts.password is None: + opts.password = getpass.getpass("Password: ") + + + # Setup the WikiBot and register plugins. Note that while plugins may + # have interdependencies, the order in which you register them does + # not matter. + xmpp = WikiBot(opts.jid, opts.password) + xmpp.register_plugin('xep_0030') # Service Discovery + xmpp.register_plugin('xep_0004') # Data Forms + xmpp.register_plugin('xep_0060') # PubSub + xmpp.register_plugin('xep_0199') # XMPP Ping + + chat_client = xmpp # set the global variable + + # If you are connecting to Facebook and wish to use the + # X-FACEBOOK-PLATFORM authentication mechanism, you will need + # your API key and an access token. Then you'll set: + # xmpp.credentials['api_key'] = 'THE_API_KEY' + # xmpp.credentials['access_token'] = 'THE_ACCESS_TOKEN' + + # If you are connecting to MSN, then you will need an + # access token, and it does not matter what JID you + # specify other than that the domain is 'messenger.live.com', + # so '_@messenger.live.com' will work. You can specify + # the access token as so: + # xmpp.credentials['access_token'] = 'THE_ACCESS_TOKEN' + + # If you are working with an OpenFire server, you may need + # to adjust the SSL version used: + # xmpp.ssl_version = ssl.PROTOCOL_SSLv3 + + # If you want to verify the SSL certificates offered by a server: + # xmpp.ca_certs = "path/to/ca/cert" + + # start the app server and run it as a thread so that the XMPP server may also start + threading.Thread(target=run_server).start() + + # Connect to the XMPP server and start processing XMPP stanzas. + if xmpp.connect(): + # If you do not have the dnspython library installed, you will need + # to manually specify the name of the server if it does not match + # the one in the JID. For example, to use Google Talk you would + # need to use: + # + # if xmpp.connect(('talk.google.com', 5222)): + # ... + xmpp.process(block=True) + print("Done") + else: + print("Unable to connect.") \ No newline at end of file From f83d61058f090dd1dadd01875c9b3320a02fecff Mon Sep 17 00:00:00 2001 From: Mogar Date: Tue, 25 Oct 2016 14:06:52 -0700 Subject: [PATCH 2/9] address merge comments --- appengine/standard/xmpp_wikibot/README.md | 44 +++++++++++++--------- appengine/standard/xmpp_wikibot/wikibot.py | 39 ++++++++----------- 2 files changed, 42 insertions(+), 41 deletions(-) diff --git a/appengine/standard/xmpp_wikibot/README.md b/appengine/standard/xmpp_wikibot/README.md index 43302e9ec03..a890654989f 100644 --- a/appengine/standard/xmpp_wikibot/README.md +++ b/appengine/standard/xmpp_wikibot/README.md @@ -4,25 +4,31 @@ This sample shows how to use the [SleekXMPP](http://sleekxmpp.com/index.html) client and [Flask](http://flask.pocoo.org/) to build a simple chatbot that can be run on [Google Compute Engine](https://cloud.google.com/compute/). The chatbot does two things: - 1. Sends messages to XMPP users via http get: - The server is running on port 5000 - if running on virtual machine use: - http://:5000/send_message?recipient=&message= +1. Sends messages to XMPP users via http get: - If running locally use: - http://localhost:5000/send_message?recipient=&message= +The server is running on port 5000 - 2. Responds to incoming messages with a wikipedia page on the topic: - Send a message with a topic (e.g., 'Hawaii') to the XMPP account the server is using - It should respond with a Wikipedia page (when one exists) +if running on virtual machine use: + +http://:5000/send_message?recipient=&message= + +If running locally use: + +http://localhost:5000/send_message?recipient=&message= + +2. Responds to incoming messages with a Wikipedia page on the topic: + +Send a message with a topic (e.g., 'Hawaii') to the XMPP account the server is using + +It should respond with a Wikipedia page (when one exists) ## Setup -Follow the intstructions at the +Follow the instructions at the [Compute Engine Quickstart Guide](https://cloud.google.com/compute/docs/quickstart-linux) on how to create a project, create a virtual machine, and connect to your -instance via SSH. Once you have done this, you may jump to 'Installing files -and dependencies' +instance via SSH. Once you have done this, you may jump to +[Installing files and dependencies](#installing-files-and-dependencies). You should also download the [Google Cloud SDK](https://cloud.google.com/sdk/). It will allow you to access many of the features of Google Compute Engine via @@ -31,10 +37,10 @@ your local machine. ### Installing files and dependencies -First, install the wikibot.py and requirements.txt files onto your remote +First, install the `wikibot.py` and `requirements.txt` files onto your remote instance. See the guide on [Transferring Files](https://cloud.google.com/compute/docs/instances/transfer-files) -for more information on how to do this using the Mac file browser, scp, or +for more information on how to do this using the Mac file browser, `scp`, or the Google Cloud SDK. Before running or deploying this application, you must install the dependencies @@ -50,13 +56,15 @@ If you do not have one, you can easily create an account at one of the many XMPP servers such as [Jabber.at](https://jabber.at/account/register/). Once you have an account, run the following command: - python wikibot.py + python wikibot.py -j '' -p '' + +Where the username (e.g., 'bob@jabber.at') and password for the account that +you'd like to use for your chatbot are passed in as arguments. -Then add the username (e.g., 'bob@jabber.at') and password for the account that -you'd like to use for your chatbot. +Enter control-Z to stop the server ### Running on your local machine -You may also run the sample locally by simply copying wikibot.py to a project +You may also run the sample locally by simply copying `wikibot.py` to a project directory and installing all python dependencies there. \ No newline at end of file diff --git a/appengine/standard/xmpp_wikibot/wikibot.py b/appengine/standard/xmpp_wikibot/wikibot.py index ad2f725f3d7..4f5afeecdec 100644 --- a/appengine/standard/xmpp_wikibot/wikibot.py +++ b/appengine/standard/xmpp_wikibot/wikibot.py @@ -14,16 +14,15 @@ """Wikibot server example using SleekXMPP client library""" -import sys +import json import logging -import getpass from optparse import OptionParser -from flask import Flask, request -import requests +import sys import threading import urllib -import json +from flask import Flask, request +import requests import sleekxmpp # Python versions before 3.0 do not use UTF-8 encoding @@ -46,14 +45,14 @@ def send_message(): recipient = request.args.get('recipient') message = request.args.get('message') except KeyError as e: - logging.info("key error: {0}".format(e)) + logging.info('key error: {0}'.format(e)) if chat_client and recipient and message: chat_client.send_message(mto=recipient, mbody=message) - return "message sent to:" + recipient + " with body:" + message + return 'message sent to:' + recipient + ' with body:' + message else: - logging.info("chat client or recipient or message does not exist!") - return "message failed to send" + logging.info('chat client or recipient or message does not exist!') + return 'message failed to send' def run_server(): app.run(threaded=False, use_reloader=False) @@ -73,12 +72,12 @@ def __init__(self, jid, password): # and the XML streams are ready for use. We want to # listen for this event so that we we can initialize # our roster. - self.add_event_handler("session_start", self.start) + self.add_event_handler('session_start', self.start) # The message event is triggered whenever a message # stanza is received. Be aware that that includes # MUC messages and error messages. - self.add_event_handler("message", self.message) + self.add_event_handler('message', self.message) def start(self, event): """ @@ -109,17 +108,17 @@ def message(self, msg): how it may be used. """ if msg['type'] in ('chat', 'normal'): - msg_body = "%(body)s" % msg - logging.info("Message sent was: " + msg_body) + msg_body = '%(body)s' % msg + logging.info('Message sent was: ' + msg_body) encoded_body = urllib.quote_plus(msg_body) - svrResponse = requests.get("https://en.wikipedia.org/w/api.php?action=parse&prop=sections&format=json&page=" + encoded_body) + svrResponse = requests.get('https://en.wikipedia.org/w/api.php?action=parse&prop=sections&format=json&page=' + encoded_body) doc = json.loads(svrResponse.content) try: page_id = str(doc['parse']['pageid']) defn_url = 'https://en.wikipedia.org/?curid=' + page_id msg.reply("find out more about: '" + msg_body + "' here: " + defn_url).send() except KeyError as e: - logging.info("key error: {0}".format(e)) + logging.info('key error: {0}'.format(e)) msg.reply("I wasn't able to locate info on: '" + msg_body + "' Sorry").send() @@ -152,11 +151,6 @@ def message(self, msg): logging.basicConfig(level=opts.loglevel, format='%(levelname)-8s %(message)s') - if opts.jid is None: - opts.jid = raw_input("Username: ") - if opts.password is None: - opts.password = getpass.getpass("Password: ") - # Setup the WikiBot and register plugins. Note that while plugins may # have interdependencies, the order in which you register them does @@ -196,10 +190,9 @@ def message(self, msg): if xmpp.connect(): # If you do not have the dnspython library installed, you will need # to manually specify the name of the server if it does not match - # the one in the JID. For example, to use Google Talk you would - # need to use: + # the one in the JID. For example: # - # if xmpp.connect(('talk.google.com', 5222)): + # if xmpp.connect(('.com', 5222)): # ... xmpp.process(block=True) print("Done") From a8adbaf630070b4054c94a33dcf63da9e9403921 Mon Sep 17 00:00:00 2001 From: Mogar Date: Tue, 25 Oct 2016 14:12:57 -0700 Subject: [PATCH 3/9] updated readme formatting --- appengine/standard/xmpp_wikibot/README.md | 24 +++++++++-------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/appengine/standard/xmpp_wikibot/README.md b/appengine/standard/xmpp_wikibot/README.md index a890654989f..2295c61ac7e 100644 --- a/appengine/standard/xmpp_wikibot/README.md +++ b/appengine/standard/xmpp_wikibot/README.md @@ -4,23 +4,17 @@ This sample shows how to use the [SleekXMPP](http://sleekxmpp.com/index.html) client and [Flask](http://flask.pocoo.org/) to build a simple chatbot that can be run on [Google Compute Engine](https://cloud.google.com/compute/). The chatbot does two things: -1. Sends messages to XMPP users via http get: + 1. Sends messages to XMPP users via http get: + The server is running on port 5000 + if running on virtual machine use: + http://:5000/send_message?recipient=&message= -The server is running on port 5000 + If running locally use: + http://localhost:5000/send_message?recipient=&message= -if running on virtual machine use: - -http://:5000/send_message?recipient=&message= - -If running locally use: - -http://localhost:5000/send_message?recipient=&message= - -2. Responds to incoming messages with a Wikipedia page on the topic: - -Send a message with a topic (e.g., 'Hawaii') to the XMPP account the server is using - -It should respond with a Wikipedia page (when one exists) + 2. Responds to incoming messages with a Wikipedia page on the topic: + Send a message with a topic (e.g., 'Hawaii') to the XMPP account the server is using + It should respond with a Wikipedia page (when one exists) ## Setup From 0508f7f980708cdd221ab178be90b6c9420d8cf5 Mon Sep 17 00:00:00 2001 From: Mogar Date: Tue, 25 Oct 2016 14:17:03 -0700 Subject: [PATCH 4/9] updated readme formatting again --- appengine/standard/xmpp_wikibot/README.md | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/appengine/standard/xmpp_wikibot/README.md b/appengine/standard/xmpp_wikibot/README.md index 2295c61ac7e..d1ffc46b01c 100644 --- a/appengine/standard/xmpp_wikibot/README.md +++ b/appengine/standard/xmpp_wikibot/README.md @@ -4,17 +4,15 @@ This sample shows how to use the [SleekXMPP](http://sleekxmpp.com/index.html) client and [Flask](http://flask.pocoo.org/) to build a simple chatbot that can be run on [Google Compute Engine](https://cloud.google.com/compute/). The chatbot does two things: - 1. Sends messages to XMPP users via http get: - The server is running on port 5000 - if running on virtual machine use: - http://:5000/send_message?recipient=&message= - - If running locally use: - http://localhost:5000/send_message?recipient=&message= - - 2. Responds to incoming messages with a Wikipedia page on the topic: - Send a message with a topic (e.g., 'Hawaii') to the XMPP account the server is using - It should respond with a Wikipedia page (when one exists) + +1. Sends messages to XMPP users via http get: + * The server is running on port 5000 + * if running on virtual machine use: http://:5000/send_message?recipient=&message= + * If running locally use: http://localhost:5000/send_message?recipient=&message= + +2. Responds to incoming messages with a Wikipedia page on the topic: + * Send a message with a topic (e.g., 'Hawaii') to the XMPP account the server is using + * It should respond with a Wikipedia page (when one exists) ## Setup From bad4349c40e1e282a5e55fc7085005a72848b705 Mon Sep 17 00:00:00 2001 From: Mogar Date: Tue, 25 Oct 2016 15:34:50 -0700 Subject: [PATCH 5/9] server now runs on port 80 --- appengine/standard/xmpp_wikibot/wikibot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appengine/standard/xmpp_wikibot/wikibot.py b/appengine/standard/xmpp_wikibot/wikibot.py index 4f5afeecdec..4a22caa22fc 100644 --- a/appengine/standard/xmpp_wikibot/wikibot.py +++ b/appengine/standard/xmpp_wikibot/wikibot.py @@ -55,7 +55,7 @@ def send_message(): return 'message failed to send' def run_server(): - app.run(threaded=False, use_reloader=False) + app.run(threaded=False, use_reloader=False, host='0.0.0.0', port=80) class WikiBot(sleekxmpp.ClientXMPP): From 3f7b457a9f7d70f3afbe584ffef32307eaa831db Mon Sep 17 00:00:00 2001 From: Mogar Date: Tue, 25 Oct 2016 21:22:49 -0700 Subject: [PATCH 6/9] back to running server on port 5000 --- appengine/standard/xmpp_wikibot/wikibot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appengine/standard/xmpp_wikibot/wikibot.py b/appengine/standard/xmpp_wikibot/wikibot.py index 4a22caa22fc..4f5afeecdec 100644 --- a/appengine/standard/xmpp_wikibot/wikibot.py +++ b/appengine/standard/xmpp_wikibot/wikibot.py @@ -55,7 +55,7 @@ def send_message(): return 'message failed to send' def run_server(): - app.run(threaded=False, use_reloader=False, host='0.0.0.0', port=80) + app.run(threaded=False, use_reloader=False) class WikiBot(sleekxmpp.ClientXMPP): From 85c25d3f992b9763828c44c3514a0acc47b77639 Mon Sep 17 00:00:00 2001 From: Mogar Date: Tue, 25 Oct 2016 23:28:24 -0700 Subject: [PATCH 7/9] udated README with firewall setup instructions --- appengine/standard/xmpp_wikibot/README.md | 9 +++++++++ appengine/standard/xmpp_wikibot/wikibot.py | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/appengine/standard/xmpp_wikibot/README.md b/appengine/standard/xmpp_wikibot/README.md index d1ffc46b01c..04994943688 100644 --- a/appengine/standard/xmpp_wikibot/README.md +++ b/appengine/standard/xmpp_wikibot/README.md @@ -26,6 +26,15 @@ You should also download the [Google Cloud SDK](https://cloud.google.com/sdk/). It will allow you to access many of the features of Google Compute Engine via your local machine. +**IMPORTANT** You must enable tcp traffic on port 5000 to send messages to the +XMPP server. This can be done by running the following SDK commands: + gcloud config set project + + gcloud compute firewall-rules create wikibot-server-rule --allow tcp:5000 --source-ranges=0.0.0.0/0 + +Or you can create a new firewall rule via the UI in the +[Networks](https://console.cloud.google.com/networking/networks/list) section of +the Google Cloud Console. ### Installing files and dependencies diff --git a/appengine/standard/xmpp_wikibot/wikibot.py b/appengine/standard/xmpp_wikibot/wikibot.py index 4f5afeecdec..592f91f2ccf 100644 --- a/appengine/standard/xmpp_wikibot/wikibot.py +++ b/appengine/standard/xmpp_wikibot/wikibot.py @@ -55,7 +55,7 @@ def send_message(): return 'message failed to send' def run_server(): - app.run(threaded=False, use_reloader=False) + app.run(threaded=False, use_reloader=False, host='0.0.0.0') class WikiBot(sleekxmpp.ClientXMPP): From 82633a4b32e881e42f649f5ad27c28886215da13 Mon Sep 17 00:00:00 2001 From: Mogar Date: Tue, 25 Oct 2016 23:30:06 -0700 Subject: [PATCH 8/9] udated README with firewall setup instructions 2 --- appengine/standard/xmpp_wikibot/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/appengine/standard/xmpp_wikibot/README.md b/appengine/standard/xmpp_wikibot/README.md index 04994943688..98d50d007df 100644 --- a/appengine/standard/xmpp_wikibot/README.md +++ b/appengine/standard/xmpp_wikibot/README.md @@ -28,6 +28,7 @@ your local machine. **IMPORTANT** You must enable tcp traffic on port 5000 to send messages to the XMPP server. This can be done by running the following SDK commands: + gcloud config set project gcloud compute firewall-rules create wikibot-server-rule --allow tcp:5000 --source-ranges=0.0.0.0/0 From 49a7b53307e95f9fad63f2997141bc471fca16e0 Mon Sep 17 00:00:00 2001 From: Mogar Date: Tue, 25 Oct 2016 23:35:27 -0700 Subject: [PATCH 9/9] minor cosmetic changes --- appengine/standard/xmpp_wikibot/wikibot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/appengine/standard/xmpp_wikibot/wikibot.py b/appengine/standard/xmpp_wikibot/wikibot.py index 592f91f2ccf..f9568fdfb5a 100644 --- a/appengine/standard/xmpp_wikibot/wikibot.py +++ b/appengine/standard/xmpp_wikibot/wikibot.py @@ -111,8 +111,8 @@ def message(self, msg): msg_body = '%(body)s' % msg logging.info('Message sent was: ' + msg_body) encoded_body = urllib.quote_plus(msg_body) - svrResponse = requests.get('https://en.wikipedia.org/w/api.php?action=parse&prop=sections&format=json&page=' + encoded_body) - doc = json.loads(svrResponse.content) + svr_response = requests.get('https://en.wikipedia.org/w/api.php?action=parse&prop=sections&format=json&page=' + encoded_body) + doc = json.loads(svr_response.content) try: page_id = str(doc['parse']['pageid']) defn_url = 'https://en.wikipedia.org/?curid=' + page_id