Skip to content

Instantly share code, notes, and snippets.

@fgiobergia
Created August 12, 2016 18:47
Show Gist options
  • Save fgiobergia/effe1082dd5772cc330c1f69ac1e9e4d to your computer and use it in GitHub Desktop.
Save fgiobergia/effe1082dd5772cc330c1f69ac1e9e4d to your computer and use it in GitHub Desktop.
from lxml import html
import requests
import numpy
page = requests.get('https://cloud.google.com/compute/pricing')
tree = html.fromstring(page.content)
lowest = tree.xpath('//table/tbody/tr/th[text()="Preemptible price"]/../../tr/td[5]/text()')[:18]
lowest_preempt = tree.xpath('//table/tbody/tr/th[text()="Preemptible price"]/../../tr/td[8]/text()')[:18]
lwst = [ float(x[1:]) for x in lowest ]
lwst_pr = [ float(x[1:]) for x in lowest_preempt ]
v = [ 100 * lwst_pr[i] / lwst[i] for i in range(0,len(lwst)) ]
# considering all cases
print "Considering all cases: "
print "Mean:",numpy.mean(v)
print "Std:",numpy.std(v)
# excluding shared-core machines
v = v[0:5] + v[8:]
print "Excluding shared-core machines"
print "Mean:",numpy.mean(v)
print "Std:",numpy.std(v)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment