Skip to content

Instantly share code, notes, and snippets.

@devStepsize
devStepsize / yahoo_get_historical_stock_price.py
Created May 7, 2016 18:51
Using the yahoo finance module (pip install it), get the historical price of a stock
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 August 3, 2021 22:00
Chart a radar plot with matplotlib
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 23:47
Get the topics for a given text using the Alchemy API
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 21:32
Get all tracks for a given album_id
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 21:31
Get all the albums for a given artist_id
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 21:32
"I'm feeling lucky" type retrieval of an artist id given a search term
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 13:52
Analyse the tone / emotion of a text with this beta IBM Watson service
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 19:07
Detect faces in a local image using the Azure Face API in Python
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 19:07
Detect faces in a public image using the Azure Face API in Python
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 18:34
Get the topics of a webpage using the AlchemyAPI
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)