I'm going to set out how I imagine this could work below :P
You have a website (Let's call it www.example.com).
You want to extract some data from that website, so you initialise it in your algorithm using:
context.example_website = url(http://www.example.com)
What that does is fetch the source code of that url, which might look like below (a very basic illustrative example):
<html>
<head>
<title>Example Website</title>
<meta name="description" content="A description of the website."/>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="header"><h1 class="logo">Example.com</h1></div>
<div id="horizontal_navigation"><ul><li><a href="#">Home</li></a><a href="contact.html"><li>Contact</li></a></ul></div>
<div id="content">
<h2>Content Title.</h2>
<p>Some random article text saying something possibly of interest. Oh and here comes a table!</p>
<table>
<tr>
<th>Header 1. | Stock 1.</th>
<th>Header 2. | Stock 2.</th>
<th>Header 3. | Stock 3.</th>
<th>Header 4. | Stock 4.</th>
</tr>
<tr>
<td>row 1, cell 1. | Sell.</td>
<td>row 1, cell 2. | Sell.</td>
<td>row 1, cell 3. | Sell.</td>
<td>row 1, cell 4. | Sell.</td>
</tr>
<tr>
<td>row 2, cell 1. | Sell.</td>
<td>row 2, cell 2. | Sell.</td>
<td>row 2, cell 3. | Buy.</td>
<td>row 2, cell 4. | Sell.</td>
</tr>
</table>
</div>
<div id="footer">Copyright © 2013 - Example.com.</div>
</body>
</html>
Now, you will want to define only the data from this page that you are interested in.
The code will do this by analyzing the above html code, and creating lists of the data in the of the website code, seperated by both their tag type (such as a list of all strings contained between
tags) and their containing div (so only
tags contained within the div of id = "content").
** Note Made While Editing: Some things might need to be stored a bit more creatively (such as tables and such)... I'm too tired atm to work it out ;) **
So you are now going to call data from the table in the content div.
def handle_data(context, data):
table_1 = data[context.example_website].body.div_id(content).table[0]
You will want to now also specify variables for reaching the data in that table.
table_1_row = data[context.example_website].body.div_id(content).table[0].table_row
table_1_cell = data[context.example_website].body.div_id(content).table[0].table_cell
So now let's make an algorithm that checks each row of a column (Stock 3's Column) for the word "buy" or "Buy" in the column of Stock 3.
def initialize(context):
context.example_website = url(http://www.example.com)
context.cell_to_check = 3
context.row_to_check = [1, 2]
def handle_data(context, data):
table_1 = data[context.example_website].body.div_id(content).table[0]
table_1_row = data[context.example_website].body.div_id(content).table[0].table_row # Row Number
table_1_cell = data[context.example_website].body.div_id(content).table[0].table_cell # Column Number
currently_selected_cell_content = data[context.example_website].body.div_id(content).table[0].table_cell_content #Content of currently selected cell
row_cell_cache = None
For table_1_row in context.row_to_check and table_1_cell in context.cell_to_check:
row_cell_cache = currently_selected_cell_content
if row_cell_cache == "Buy" or row_cell_cache == "buy":
order(sid[24],+1)
Ok, so my codes getting sloppier near the end - long post and I'm new to python lol - but I think the gist what I'm suggesting is just about clear lol (and if not I'm sorry for subjecting you to a long post)... N.B. I think tables will be one of the harder parts of this idea to find a workable solution for ;)