%matplotlib inline
import frontmatter # Parse YAML front matter on Jekyll pages
import urllib2 # Make HTTP requests
import json # Parse JSON for data example
from matplotlib import pyplot as plt # Plotting tools for proof
research-pages
¶research-pages
provides a blog-static approach to science. The posts contain YAML front-matter; effectively providing user defined headers.
This notebook illustrates how post data can be parsed and reused in python.
A Javascript Stack for Science is a unique interpretation on how the modern the web can be used to facilitate and enhance science.
At the top of the page, is a shortened link .../_posts/2014-11-20-LDA-tester.html
to the raw Github file.
urllib2
to make the HTTP request.frontmatter
is used to parsed the structured metadata data['metadata']
and unstructured metadata data['content']
as python variables.json
file is requested from the host repository. It's name lives in the front-matter.# URL to raw data that was copied from the post header
url ="https://raw.githubusercontent.com/Materials-Informatics-Lab/research-pages/gh-pages/_posts/2014-11-20-LDA-tester.html"
# Request the raw data and parse the front matter
page = urllib2.urlopen( url )
data = frontmatter.load( page )
page.close()
# Create a URL from the structured front-matter
parent_url = 'http://materials-informatics-lab.github.io'
data_url = parent_url + data['file'];
print data_url
http://materials-informatics-lab.github.io/research-pages/assets/data/embedding.json
# Request the new url
data_page = urllib2.urlopen( data_url )
external_data = json.load( data_page )
data_page.close()
# Plot an example
plt.scatter( x = external_data['embed']['X'],
y = external_data['embed']['Y'],
c = external_data['embed']['C']
);