Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 0.66 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/usr/bin/python
  2. import urllib
  3. from lxml import html
  4. raw_html = urllib.urlopen("http://mining.bitcoin.cz/stats/").read()
  5. parsed_html=html.fromstring(raw_html)
  6. #all TRs from the second table, without the header TR
  7. data_rows = parsed_html.xpath('//table')[1].xpath('.//tr')[1:]
  8. sum_seconds=0
  9. for d in data_rows:
  10.  #the second column contains the calculation time
  11.  hr,min,sec=d.xpath('.//td')[2].text_content().split(':')
  12.  sum_seconds+=int(hr)*3600+int(sec)*60+int(min)
  13.  
  14. tmp_avg = sum_seconds/len(data_rows)
  15. print tmp_avg
  16.  
  17. avg_sec=tmp_avg%60
  18. tmp_avg-=avg_sec
  19.  
  20. avg_min=(tmp_avg%3600)/60
  21. tmp_avg-=60*avg_min
  22.  
  23. avg_hr=tmp_avg/3600
  24.  
  25. print "%02d:%02d:%02d" % (avg_hr, avg_min, avg_sec )