<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>betting &#8211; Scott Mcintyre</title>
	<atom:link href="https://scott.cm/category/betting/feed/" rel="self" type="application/rss+xml" />
	<link>https://scott.cm</link>
	<description>Web Operations Engineer,  Linux Systems Administrator,  mySQL DBA,  MongoDB DBA,  Python+PHP Developer,  Performance Engineer</description>
	<lastBuildDate>Sat, 19 Jan 2013 07:00:16 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.4</generator>
	<item>
		<title>python load betfair data to mysql</title>
		<link>https://scott.cm/python-load-betfair-data-to-mysql/</link>
					<comments>https://scott.cm/python-load-betfair-data-to-mysql/#comments</comments>
		
		<dc:creator><![CDATA[Scott Mcintyre]]></dc:creator>
		<pubDate>Tue, 15 Jan 2013 03:32:27 +0000</pubDate>
				<category><![CDATA[betting]]></category>
		<category><![CDATA[Python]]></category>
		<guid isPermaLink="false">https://scott.cm/?p=200</guid>

					<description><![CDATA[The script below will import the betfair data from data.betfair.com into a mySQL table.  First create the table, CREATE TABLE history ( sports_id int(11) DEFAULT NULL, event_id int(11) DEFAULT NULL, country varchar(10) DEFAULT NULL, scheduled_off varchar(30) DEFAULT NULL, actual_off varchar(30) DEFAULT NULL, full_description varchar(150) DEFAULT NULL, odds double DEFAULT NULL,]]></description>
										<content:encoded><![CDATA[<p>The script below will import the betfair data from data.betfair.com into a mySQL table.  First create the table,</p>
<blockquote><p>CREATE TABLE <code>history</code> (<br />
<code>sports_id</code> int(11) DEFAULT NULL,<br />
<code>event_id</code> int(11) DEFAULT NULL,<br />
<code>country</code> varchar(10) DEFAULT NULL,<br />
<code>scheduled_off</code> varchar(30) DEFAULT NULL,<br />
<code>actual_off</code> varchar(30) DEFAULT NULL,<br />
<code>full_description</code> varchar(150) DEFAULT NULL,<br />
<code>odds</code> double DEFAULT NULL,<br />
<code>settled_date</code> varchar(30) DEFAULT NULL,<br />
<code>first_taken</code> varchar(30) DEFAULT NULL,<br />
<code>latest_taken</code> varchar(30) DEFAULT NULL,<br />
<code>course</code> varchar(150) DEFAULT NULL,<br />
<code>volume_matched</code> double DEFAULT NULL,<br />
<code>number_bets</code> double DEFAULT NULL,<br />
<code>event</code> varchar(50) DEFAULT NULL,<br />
<code>in_play</code> varchar(2) DEFAULT NULL,<br />
<code>selection</code> varchar(50) DEFAULT NULL,<br />
<code>selection_id</code> int(11) DEFAULT NULL,<br />
<code>win_flag</code> varchar(1) DEFAULT NULL,<br />
KEY <code>sports_id</code> (<code>sports_id</code>),<br />
KEY <code>event_id</code> (<code>event_id</code>),<br />
KEY <code>odds</code> (<code>odds</code>),<br />
KEY <code>win_flag</code> (<code>win_flag</code>),<br />
KEY <code>descr</code> (<code>full_description</code>)<br />
) ENGINE=InnoDB DEFAULT</p></blockquote>
<p>Then use the following script,</p>
<blockquote><p>#!/usr/bin/python<br />
import csv<br />
import MySQLdb<br />
import re<br />
import os</p>
<p>path=&#8221;/path/to/files&#8221;</p>
<p>db = MySQLdb.connect(host=&#8217;localhost&#8217;,<br />
    user=&#8217;user&#8217;,<br />
    passwd=&#8217;pass&#8217;,<br />
    db=&#8217;betfair&#8217;)</p>
<p>cursor = db.cursor()<br />
files = os.listdir(path)</p>
<p>for filename in files:<br />
 csv_data = csv.reader(file(path+&#8221;/&#8221;+filename))<br />
 for row in csv_data:<br />
  cursor.execute(&#8220;INSERT into history(sports_id, event_id, settled_date, country, full_description, course, scheduled_off, event, actual_off, selection_id, selection, odds, number_bets, volume_matched, latest_taken, first_taken, win_flag, in_play) values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)&#8221;, row)</p>
<p>db.commit()<br />
cursor.close()</p></blockquote>
<p>Adjust the path at the to to the location of the raw csv(uncompressed) files that you would like loaded into mySQL.<br />
Edit the database information<br />
Run the script</p>
<p>You can also add filters,  for example when processing horse racing data I wanted only the following,</p>
<p>&#8211; UK races<br />
&#8211; Bets placed before the event (IE not in running)<br />
&#8211; Exclude hurdles</p>
<p>This is what I used</p>
<blockquote><p> for row in csv_data:<br />
  if row[1] != &#8220;EVENT_ID&#8221; and row[3] == &#8220;GB&#8221; and row[17] == &#8220;PE&#8221; and &#8220;PLACED&#8221; not in row[7] and &#8220;Hrd&#8221; not in row[7]:<br />
   if re.search(&#8216;[0-9]f&#8217;, row[7]):<br />
    cursor.execute(&#8220;INSERT into history(sports_id, event_id, settled_date, country, full_description, course, scheduled_off, event, actual_off, selection_id, selection, odds, number_bets, volume_matched, latest_taken, first_taken, win_flag, in_play) values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)&#8221;, row)</p></blockquote>
]]></content:encoded>
					
					<wfw:commentRss>https://scott.cm/python-load-betfair-data-to-mysql/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>python attheraces.com data scraping</title>
		<link>https://scott.cm/python-attheraces-com-data-scraping/</link>
					<comments>https://scott.cm/python-attheraces-com-data-scraping/#respond</comments>
		
		<dc:creator><![CDATA[Scott Mcintyre]]></dc:creator>
		<pubDate>Tue, 15 Jan 2013 03:24:51 +0000</pubDate>
				<category><![CDATA[betting]]></category>
		<category><![CDATA[Python]]></category>
		<guid isPermaLink="false">https://scott.cm/?p=194</guid>

					<description><![CDATA[I have been working on scraping the data from attheraces.com for a project I am working on which combines this and betfair data for some statistical analysis. In case this is useful to anyone here is the regex I have written, meetings = re.findall(&#8220;&#60;h5 id=\&#8221;fastfixhead(\d+)\&#8221;.*\&#8221;&#62;(\w+)&#60;\/a&#62;&#60;\/h5&#62;&#8221;, info) for meeting in meetings:]]></description>
										<content:encoded><![CDATA[<p>I have been working on scraping the data from attheraces.com for a project I am working on which combines this and betfair data for some statistical analysis.</p>
<p>In case this is useful to anyone here is the regex I have written,</p>
<blockquote><p>
meetings = re.findall(&#8220;&lt;h5 id=\&#8221;fastfixhead(\d+)\&#8221;.*\&#8221;&gt;(\w+)&lt;\/a&gt;&lt;\/h5&gt;&#8221;, info)<br />
for meeting in meetings:<br />
times = re.findall(&#8220;&lt;li class=\&#8221; \&#8221;&gt;&lt;a href=\&#8221;/card.aspx\?raceid=(\d+)&amp;amp;meetingid=(&#8220;+meeting[0]+&#8221;)&amp;amp;date=([0-9]{4}-[0-9]{2}-[0-9]{2})&amp;amp.*&lt;strong&gt;([0-9]{2}:[0-9]{2})&lt;\/strong&gt; &#8211; ([0-9+][f|m].*)\((\d+) run&#8221;, info)
</p></blockquote>
<p>This gathers the course name, raceid, meetingid, date, race time, distance and number of runners. It only gathers UK data (by only matching alphanumeric and underscores it strips non UK codes) so replace &#8220;\w+&#8221; with &#8220;.*&#8221; for the meetings match to include other countries.</p>
<p>Sample output,</p>
<blockquote><p>
Wolverhampton</p>
<p>RaceID: 741858<br />
Date: 57674,<br />
Race Time: 2013-01-14<br />
Distance: 13:50,<br />
Number of runners: 7f 32y<br />
RaceID: 741859<br />
Date: 57674,<br />
Race Time: 2013-01-14<br />
Distance: 14:20,<br />
Number of runners: 5f 216y<br />
RaceID: 741860<br />
Date: 57674,<br />
Race Time: 2013-01-14<br />
Distance: 14:50,<br />
Number of runners: 1m 4f 50y<br />
RaceID: 741861<br />
Date: 57674,<br />
Race Time: 2013-01-14<br />
Distance: 15:20,<br />
Number of runners: 1m 141y<br />
RaceID: 741862<br />
Date: 57674,<br />
Race Time: 2013-01-14<br />
Distance: 15:50,<br />
Number of runners: 1m 141y<br />
RaceID: 741863<br />
Date: 57674,<br />
Race Time: 2013-01-14<br />
Distance: 16:20,<br />
Number of runners: 1m 1f 103y<br />
RaceID: 741864<br />
Date: 57674,<br />
Race Time: 2013-01-14<br />
Distance: 16:50,<br />
Number of runners: 1m 1f 103y
</p></blockquote>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://scott.cm/python-attheraces-com-data-scraping/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
