This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from flask import Flask | |
| app = Flask(__name__) | |
| @app.route('/') | |
| def hello_world(): | |
| return 'Hello World!' | |
| if __name__ == '__main__': | |
| app.run() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| endpoint = "http://gateway-a.watsonplatform.net/calls/text/TextGetTextSentiment" | |
| def get_text_sentiment(text): | |
| data = { | |
| 'apikey': API_KEY, | |
| 'outputMode': 'json', | |
| 'text': text | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| endpoint = "http://gateway-a.watsonplatform.net/calls/url/URLGetTargetedSentiment" | |
| data = { | |
| 'apikey': API_KEY, | |
| 'outputMode': 'json', | |
| 'targets': 'Apple|Microsoft', # seperate entities with a | | |
| 'sourceText': 'raw', | |
| 'url': 'http://www.techradar.com/news/world-of-tech/apple-versus-microsoft-who-had-the-better-2015--1310681' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # From https://github.com/slackhq/python-slackclient#basic-api-methods | |
| # The full list of API methods can be found here https://api.slack.com/methods | |
| from slackclient import SlackClient | |
| token = "xoxp-28192348123947234198234" # found at https://api.slack.com/web#authentication | |
| sc = SlackClient(token) | |
| print sc.api_call("api.test") | |
| print sc.api_call("channels.info", channel="1234567890") | |
| print sc.api_call( | |
| "chat.postMessage", channel="#general", text="Hello from Python! :tada:", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| This is an example of how to use the Slack Real Time Messaging API using | |
| Python and the python-slackclient. | |
| The example below originates from the python-slackclient documentation. | |
| See https://github.com/slackhq/python-slackclient#real-time-messaging | |
| This is everything you can do with the client: | |
| Connect to a Slack RTM websocket. This is a persistent connection from which you can read events. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Twitter = require('twitter'); | |
| var client = new Twitter({ | |
| consumer_key: '', | |
| consumer_secret: '', | |
| access_token_key: '', | |
| access_token_secret: '' | |
| }); | |
| // The better way of doing it: set up environment variables, and then use |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| client.get('followers/list', {screen_name: 'justinbieber'}, function(error, tweets, response){ | |
| console.log(tweets); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| client.post('statuses/update', {status: 'I Love Twitter'}, function(error, tweet, response){ | |
| if(error) throw error; | |
| console.log(tweet); // Tweet body. | |
| console.log(response); // Raw response object. | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| client.stream('statuses/filter', {track: 'funny'}, function(stream) { | |
| stream.on('data', function(tweet) { | |
| console.log(tweet.text); | |
| }); | |
| stream.on('error', function(error) { | |
| throw error; | |
| }); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| u'\U0001f610' |