Wednesday, January 11, 2017

Python BeautifulSoup Example

#!/usr/bin/python

from urllib import urlopen
from bs4 import BeautifulSoup

url = 'https://www.theice.com/marketdata/reports/icefutureseurope/BrentMarkers.shtml'

html = urlopen(url)

bsObj = BeautifulSoup(html.read())

# The markers are in a table, there are several tables on the page
# The Afternoon markers are in the table that follows a paragraph with
# the text ICE BRENT AFTERNOON MARKERS

# Find all the tables in the document
tables = bsObj.findAll('table', {'class':'table table-responsive table-data table-align-left'})

table_body = None

# Iterate over the tables looking at the previous paragraph
for table in tables:

   p = table.find_previous('p')

   # Check for the afternoon markers text
   if p.get_text() == 'ICE BRENT AFTERNOON MARKERS':

      print(p.get_text())

      # Extract that table  
      table_body = table.find('tbody')

      break

if table_body <> None:

   # Get all the rows
   rows = table_body.find_all('tr')

   # Print each row
   for row in rows:

      cols = row.find_all('td')

      print('%s %s %s' % (cols[0].text.strip(), cols[1].text.strip(), cols[2].text.strip()))

else:

   print('No markers!')

raw_input('Press Enter to continue ...')

##END##


Monday, August 22, 2016

Wednesday, June 29, 2016

The Enigma Machine

Yesterday, June 28, 2016 I finally understood the Enigma Machine!


Thursday, June 16, 2016

Web scraping with Java


https://www.amazon.com/Instant-Scraping-Java-Ryan-Mitchell-ebook/dp/B00ESX1AS6

Another one from the same author, Ryan Mitchell. This time the language is Java.

Web scraping and BeautifulSoup


https://www.amazon.com/Web-Scraping-Python-Collecting-Modern/dp/1491910291/

Reading about web scraping and BeautifulSoup these days.

Friday, May 13, 2016

Always test, test, test ...

Thiokol and Marshall evaluated the SRM and its case joints in structural, pressure, and static firing tests beginning in 1976. Because tests of the large solid rocket were more expensive than liquid engines, engineers ran fewer tests.
 Taken from The Challenger Accident http://history.msfc.nasa.gov/book/chptnine.pdf

Wednesday, March 2, 2016

Implementing equals in Java

public class Employee {
   protected long employeeId;
   protected String firstName;
   protected String lastName;
}


public boolean equals(Object o) {

   boolean result = false;
 
   if (o instanceof Employee) {

      Employee other = (Employee) o;

      if (this.employeeId == other.employeeId
         && this.firstName.equals(other.firstName)
         && this.lastName.equals(other.lastName))
      {
         result = true;
      }
   }
 
   return result;
}

The following program should print All good!:

package test;


/**
 *
 * @author janeiros@j4neiros.us
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        
        Equals e = new Equals(3, "jjjj", "eee");
        if (e.equals(null)) {
            System.out.println("Not good!");
        } else {
            System.out.println("All good!");
        }
    }
    
}