Skip to content

Instantly share code, notes, and snippets.

@devStepsize
devStepsize / yahoo_get_historical_stock_price.py
Created May 7, 2016
Using the yahoo finance module (pip install it), get the historical price of a stock
View yahoo_get_historical_stock_price.py
from yahoo_finance import Share
def get_stock_price_history(share_code, start_date, end_date):
"""
start_date/end_date are of format: YYYY-MM-DD
"""
stock = Share(share_code)
sopen = stock.get_open()
if not sopen:
print "Wrong stock code"
@devStepsize
devStepsize / radar_plot.py
Last active Nov 14, 2016
Chart a radar plot with matplotlib
View radar_plot.py
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.path import Path
from matplotlib.spines import Spine
from matplotlib.projections.polar import PolarAxes
from matplotlib.projections import register_projection
def radar_factory(num_vars, frame='circle'):
@devStepsize
devStepsize / alchemy_api_topic_identification_text.py
Created May 6, 2016
Get the topics for a given text using the Alchemy API
View alchemy_api_topic_identification_text.py
endpoint = "http://gateway-a.watsonplatform.net/calls/text/TextGetRankedTaxonomy"
def get_topics(text):
data = {
'apikey': API_KEY,
'outputMode': 'json',
'text': text
}
headers = {'content-type': 'application/x-www-form-urlencoded'}
r = requests.post(endpoint, data=data, headers=headers)
@devStepsize
devStepsize / spotify_get_tracks.py
Created May 6, 2016
Get all tracks for a given album_id
View spotify_get_tracks.py
import requests
spotify_endpoint = "https://api.spotify.com/v1/"
def get_tracks(album_id):
tracks = []
url = spotify_endpoint + 'albums/%s/tracks' % album_id
while url:
@devStepsize
devStepsize / spotify_get_albums.py
Created May 6, 2016
Get all the albums for a given artist_id
View spotify_get_albums.py
import requests
spotify_endpoint = "https://api.spotify.com/v1/"
def get_albums(artist_id):
albums = []
params = {'album_type': 'album'}
url = spotify_endpoint + 'artists/%s/albums' % artist_id
@devStepsize
devStepsize / spotify_get_artist_id.py
Last active May 6, 2016
"I'm feeling lucky" type retrieval of an artist id given a search term
View spotify_get_artist_id.py
import requests
spotify_endpoint = "https://api.spotify.com/v1/"
def get_artist_id(search_term):
"""
I'm feeling lucky search for artist_id
"""
params = {
@devStepsize
devStepsize / ibm_watson_tone_analyser.py
Last active May 7, 2016
Analyse the tone / emotion of a text with this beta IBM Watson service
View ibm_watson_tone_analyser.py
import requests
creds = {
"url": "https://gateway.watsonplatform.net/tone-analyzer-beta/api",
"password": "your_password",
"username": "your_username"
}
def get_tone(text):
endpoint = "https://gateway.watsonplatform.net/tone-analyzer-beta/api/v3/tone"
@devStepsize
devStepsize / azure_face_local_image.py
Created May 5, 2016
Detect faces in a local image using the Azure Face API in Python
View azure_face_local_image.py
import json
import urllib
import requests
from pprint import pprint
from os.path import expanduser
headers = {
'Content-Type': 'application/octet-stream',
'Ocp-Apim-Subscription-Key': 'your-api-key',
@devStepsize
devStepsize / azure_face_public_image.py
Last active May 5, 2016
Detect faces in a public image using the Azure Face API in Python
View azure_face_public_image.py
import json
import urllib
import requests
from pprint import pprint
headers = {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': 'your-api-key',
}
@devStepsize
devStepsize / alchemy_api_topic_identification_url.py
Created May 5, 2016
Get the topics of a webpage using the AlchemyAPI
View alchemy_api_topic_identification_url.py
import requests
endpoint = "http://gateway-a.watsonplatform.net/calls/url/URLGetRankedTaxonomy"
parameters = {
'apikey': API_KEY,
'outputMode': 'json',
'url': 'https://blog.vellumatlanta.com/2016/05/04/apple-stole-my-music-no-seriously/'
}
r = requests.get(endpoint, params=parameters)
You can’t perform that action at this time.