Skip to content

Instantly share code, notes, and snippets.

@devStepsize
devStepsize / flask_minimal_app.py
Last active April 22, 2016 20:01
Minimal hello world flask server
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World!'
if __name__ == '__main__':
app.run()
@devStepsize
devStepsize / alchemy_api_sentiment_analysis.py
Last active May 6, 2016 23:40
Basic sentiment analysis using the AlchemyAPI.
import requests
endpoint = "http://gateway-a.watsonplatform.net/calls/text/TextGetTextSentiment"
def get_text_sentiment(text):
data = {
'apikey': API_KEY,
'outputMode': 'json',
'text': text
}
@devStepsize
devStepsize / alchemy_api_targeted_sentiment.py
Last active May 6, 2016 23:43
Sample code to analyse the sentiment of a web-page on given entities (target).
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'
@devStepsize
devStepsize / slack_client_api.py
Last active April 22, 2016 14:00
Call the Slack Web API using python-slackclient
# 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:",
@devStepsize
devStepsize / slack_rtm_client.py
Last active July 9, 2018 15:14
Use Slack's Real Time Messaging API with Python and python-slackclient
'''
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.
@devStepsize
devStepsize / twitter_node_client_set_up.js
Last active April 22, 2016 17:35
Setup your Twitter API client with your credentials
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
@devStepsize
devStepsize / twitter_followers_list.js
Last active April 22, 2016 17:09
Retrieve the followers of a specific Twitter account using the Node.js client
client.get('followers/list', {screen_name: 'justinbieber'}, function(error, tweets, response){
console.log(tweets);
});
@devStepsize
devStepsize / twitter_update_status.js
Last active April 22, 2016 17:20
A sample POST request to create a new tweet using the Twitter API
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.
});
@devStepsize
devStepsize / twitter_stream.js
Last active April 22, 2016 17:15
Connect to the Twitter stream and get notified of tweets matching a filter
client.stream('statuses/filter', {track: 'funny'}, function(stream) {
stream.on('data', function(tweet) {
console.log(tweet.text);
});
stream.on('error', function(error) {
throw error;
});
});
@devStepsize
devStepsize / emoji_meh_unicode.py
Created April 22, 2016 17:25
Unicode for meh unicode
u'\U0001f610'