<?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>Python &#8211; Scott Mcintyre</title>
	<atom:link href="https://scott.cm/category/python-2/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>Tue, 18 Jul 2017 08:57:08 +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>Error: unsupported locale setting</title>
		<link>https://scott.cm/error-unsupported-locale-setting/</link>
					<comments>https://scott.cm/error-unsupported-locale-setting/#respond</comments>
		
		<dc:creator><![CDATA[Scott Mcintyre]]></dc:creator>
		<pubDate>Wed, 16 Jan 2013 07:44:14 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[dpkg-reconfigure locales]]></category>
		<category><![CDATA[Error: unsupported locale setting]]></category>
		<category><![CDATA[locale en_gb.UTF8]]></category>
		<category><![CDATA[locale-gen]]></category>
		<category><![CDATA[python trac]]></category>
		<category><![CDATA[trac locale error]]></category>
		<category><![CDATA[trac wont start]]></category>
		<guid isPermaLink="false">https://scott.cm/?p=206</guid>

					<description><![CDATA[While installing and configuring trac on my development VM it wouldn&#8217;t load over HTTP (500 error). Stracing the process returned the issue, Error: unsupported locale setting So it looks like it doesn&#8217;t have the locale installed (In my case EN_GB) this is easily fixed by running, sudo dpkg-reconfigure locales Then]]></description>
										<content:encoded><![CDATA[<p>While installing and configuring trac on my development VM it wouldn&#8217;t load over HTTP (500 error).   Stracing the process returned the issue,</p>
<blockquote><p><strong>Error: unsupported locale setting</strong></p></blockquote>
<p>So it looks like it doesn&#8217;t have the locale installed (In my case EN_GB) this is easily fixed by running,</p>
<blockquote><p>sudo dpkg-reconfigure locales</p></blockquote>
<p>Then selecting the necessary locale,  you&#8217;ll most likely want to default to UTF8.</p>
<p><a href="https://scott.cm/wp-content/uploads/2013/01/locale.png" title="Screenshot reconfigure locales"><img decoding="async" src="https://scott.cm/wp-content/uploads/2013/01/locale-thumb.png" alt="reconfigure locale to en_gb.UTF8"/></a></p>
<p>You should then be able to run trac and have it accessible,  in my case</p>
<blockquote><p>
sudo -u trac tracd -s -p 8000 &#8211;pidfile ~trac/dev/tracd.pid -d &#8211;basic-auth=&#8221;*,/home/trac/dev/htpasswd,dev&#8221; ~trac/dev<br />
curl -I localhost:8000<br />
<em>HTTP/1.0 200 OK<br />
Server: tracd/0.11.7 Python/2.6.6<br />
Date: Wed, 16 Jan 2013 07:38:32 GMT<br />
Cache-Control: must-revalidate<br />
Content-Type: text/html;charset=utf-8<br />
Content-Length: 6184<br />
Set-Cookie: trac_form_token=a83b66948209b4197936bd1a; Path=/<br />
Set-Cookie: trac_session=d2dad341a8e80e6fd2f76551; expires=Tue, 16-Apr-2013 07:38:32 GMT; Path=/</em>
</p></blockquote>
]]></content:encoded>
					
					<wfw:commentRss>https://scott.cm/error-unsupported-locale-setting/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<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>
		<item>
		<title>Twitter Mass Unfollow With Python</title>
		<link>https://scott.cm/twitter-mass-unfollow-with-python/</link>
					<comments>https://scott.cm/twitter-mass-unfollow-with-python/#respond</comments>
		
		<dc:creator><![CDATA[Scott Mcintyre]]></dc:creator>
		<pubDate>Mon, 16 Apr 2012 21:43:19 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<guid isPermaLink="false">https://scott.cm/?p=125</guid>

					<description><![CDATA[I decided to revive my old twitter account and wanted to unfollow all my old friends list,  the majority were gained from an auto-follow script a few years ago and are nothing but spam.   Given I want to start using twitter I only want to follow people I am]]></description>
										<content:encoded><![CDATA[<p>I decided to revive my old twitter account and wanted to unfollow all my old friends list,  the majority were gained from an auto-follow script a few years ago and are nothing but spam.   Given I want to start using twitter I only want to follow people I am interested in.   It was more difficult than I expected to simply purge your followers.</p>
<p>It appears twitter don&#8217;t allow most of the apps (and there are lots of them) to mass unfollow as part of their TOS.   I found this at <a href="http://www.hostnexus.com/blog/how-to-bulk-unfollow-on-twitter" target="_blank">http://www.hostnexus.com/blog/how-to-bulk-unfollow-on-twitter</a> and decided to give the steps in there a shot.   I tried a few of the apps with the chrome check all plugin but all of them have daily limits and given up here. This is when I decided instead to just write a quick python script using the API.</p>
<p>It was easy enough to get started with the twitter API.<br />
Simply visit <a href="https://dev.twitter.com" target="_blank">https://dev.twitter.com</a>  and login with your account.  <br />
Create a new application,   get your key.<br />
Install the twitter python API at <a href="http://code.google.com/p/python-twitter/" target="_blank">http://code.google.com/p/python-twitter/</a></p>
<p>You can get the latest version of the script at: <a href="https://github.com/Scott-Mc/python/blob/master/twitter-mass-unfollow.py" target="_blank">https://github.com/Scott-Mc/python/blob/master/twitter-mass-unfollow.py</a> and the version at the time of writing at the bottom of this post.</p>
<p>This was my profile before running the script<br />
<img decoding="async" src="https://scott.cm/wp-content/uploads/2012/04/twitter_friends_before.png" alt="Twitter Friends Before Mass Purge" /></p>
<p>This is my profile now after running the script,</p>
<p><img decoding="async" src="https://scott.cm/wp-content/uploads/2012/04/twitter_friends_after.png" alt="Twitter Friends After Mass Purge" /></p>
<p>This is the code at the time of writing,</p>
<blockquote><p>
#!/usr/bin/env python</p>
<p>#<br />
#Mass unfollow friends on twitter<br />
#</p>
<p># Author<br />
#  &#8211; Scott Mcintyre <scott @scott.cm><br />
#<br />
# Usage<br />
#<br />
# Get your keys from https://dev.twitter.com/<br />
# Ensure it has write access<br />
# Change the api key values marked ##### below with the twitter keys<br />
# Install http://code.google.com/p/python-twitter/</p>
<p>import twitter<br />
import time</p>
<p>api = twitter.Api(consumer_key=&#8217;#####&#8217;, consumer_secret=&#8217;#####&#8217;, access_token_key=&#8217;#####&#8217;, access_token_secret=&#8217;#####&#8217;)</p>
<p>start = time.time()<br />
i = 0<br />
friends=api.GetFriends()</p>
<p>while (1):<br />
 try:<br />
  for u in friends:<br />
   print &#8220;Deleting %s&#8221; % (u.name)<br />
   api.DestroyFriendship(u.id);<br />
   i = i + 1</p>
<p> except:<br />
   print &#8220;Possibly Rate limited? sleeping 60 seconds&#8221;<br />
   time.sleep(60)</p>
<p>elapsed = (time.time() &#8211; start)<br />
print &#8220;Deleted %s friends in %0.2f seconds&#8221; % (str(i), elapsed)<br />
</scott></p></blockquote>
]]></content:encoded>
					
					<wfw:commentRss>https://scott.cm/twitter-mass-unfollow-with-python/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Learning Python</title>
		<link>https://scott.cm/learning_python/</link>
					<comments>https://scott.cm/learning_python/#respond</comments>
		
		<dc:creator><![CDATA[Scott Mcintyre]]></dc:creator>
		<pubDate>Thu, 24 Nov 2011 12:24:02 +0000</pubDate>
				<category><![CDATA[Me]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[football scores python]]></category>
		<category><![CDATA[learn python in 2 days]]></category>
		<category><![CDATA[learning python]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[python threading]]></category>
		<category><![CDATA[python youtube]]></category>
		<category><![CDATA[server version scraper]]></category>
		<category><![CDATA[top 100 charts]]></category>
		<category><![CDATA[youtube charts]]></category>
		<guid isPermaLink="false">https://scott.cm/?p=72</guid>

					<description><![CDATA[I had set myself a goal to make around 20 blog posts per year, it&#8217;s now almost December and I still have not bothered. It is safe to say I am not exactly prolific. I decided that I would learn python, surprisingly it&#8217;s been really easy to pick up and]]></description>
										<content:encoded><![CDATA[<p>I had set myself a goal to make around 20 blog posts per year, it&#8217;s now almost December and I still have not bothered. It is safe to say I am not exactly prolific.</p>
<p>I decided that I would learn python, surprisingly it&#8217;s been really easy to pick up and I thought I would share some of the things I made in my first 2 days of python.</p>
<p>The first I written was to phrase the results from yahoo&#8217;s football score page(http://uk.eurosport.yahoo.com/football/premier-league/2011-2012/results/2011_08.html). I was on this page anyway and thought why not!</p>
<blockquote><p>#!/usr/bin/python<br />
import urllib2<br />
import re<br />
response = urllib2.urlopen(&#8216;http://uk.eurosport.yahoo.com/football/premier-league/2011-2012/results/2011_08.html&#8217;)<br />
html = response.read()<br />
re_channel = re.compile(&#8220;&lt;td class=\&#8221;ko\&#8221;&gt;&lt;abbr class=\&#8221;dtstart\&#8221; title=\&#8221;\&#8221;&gt;([0-9a-zA-z ,:]*)&lt;/abbr&gt;&lt;/td&gt;&#8221; +<br />
 &#8220;\n &lt;td class=\&#8221;match.*?\n&#8221; +<br />
 &#8221; &lt;a href=.*?\&#8221;&gt;&#8221; +<br />
  &#8220;\n &lt;span class=\&#8221;home\&#8221;&gt;([a-zA-Z ]*)&lt;/span&gt;.*?&#8221; +<br />
  &#8220;\n &lt;span class=\&#8221;score\&#8221;&gt;([0-9 :-]*)&lt;/span&gt;.*?&#8221; +<br />
  &#8220;\n &lt;span class=\&#8221;away\&#8221;&gt;([a-zA-Z ]*)&lt;/span&gt;&#8221;, re.I | re.S | re.M)<br />
find_result = re_channel.findall(html)<br />
print find_result</p></blockquote>
<blockquote></blockquote>
<p>Sample output</p>
<p>[(&#8217;13 Aug, 15:00&#8242;, &#8216;Wigan Athletic&#8217;, &#8216;1 &#8211; 1&#8217;, &#8216;Norwich City&#8217;), (&#8217;13 Aug, 15:00&#8242;, &#8216;Fulham&#8217;, &#8216;0 &#8211; 0&#8217;, &#8216;Aston Villa&#8217;), (&#8217;13 Aug, 15:00&#8242;, &#8216;Blackburn Rovers&#8217;, &#8216;1 &#8211; 2&#8217;, &#8216;Wolverhampton Wanderers&#8217;), (&#8217;13 Aug, 15:00&#8242;, &#8216;Liverpool&#8217;, &#8216;1 &#8211; 1&#8217;, &#8216;Sunderland&#8217;), (&#8217;13 Aug, 15:00&#8242;, &#8216;Queens Park Rangers&#8217;, &#8216;0 &#8211; 4&#8217;, &#8216;Bolton Wanderers&#8217;), (&#8217;13 Aug, 17:30&#8242;, &#8216;Newcastle United&#8217;, &#8216;0 &#8211; 0&#8217;, &#8216;Arsenal&#8217;), (&#8217;14 Aug, 13:30&#8242;, &#8216;Stoke City&#8217;, &#8216;0 &#8211; 0&#8217;, &#8216;Chelsea&#8217;), (&#8217;14 Aug, 16:00&#8242;, &#8216;West Bromwich Albion&#8217;, &#8216;1 &#8211; 2&#8217;, &#8216;Manchester United&#8217;), (&#8217;15 Aug, 20:00&#8242;, &#8216;Manchester City&#8217;, &#8216;4 &#8211; 0&#8217;, &#8216;Swansea City&#8217;), (&#8217;20 Aug, 12:00&#8242;, &#8216;Sunderland&#8217;, &#8216;0 &#8211; 1&#8217;, &#8216;Newcastle United&#8217;), (&#8217;20 Aug, 12:45&#8242;, &#8216;Arsenal&#8217;, &#8216;0 &#8211; 2&#8217;, &#8216;Liverpool&#8217;), (&#8217;20 Aug, 15:00&#8242;, &#8216;Swansea City&#8217;, &#8216;0 &#8211; 0&#8217;, &#8216;Wigan Athletic&#8217;), (&#8217;20 Aug, 15:00&#8242;, &#8216;Aston Villa&#8217;, &#8216;3 &#8211; 1&#8217;, &#8216;Blackburn Rovers&#8217;), (&#8217;20 Aug, 15:00&#8242;, &#8216;Everton&#8217;, &#8216;0 &#8211; 1&#8217;, &#8216;Queens Park Rangers&#8217;), (&#8217;20 Aug, 17:30&#8242;, &#8216;Chelsea&#8217;, &#8216;2 &#8211; 1&#8217;, &#8216;West Bromwich Albion&#8217;), (&#8217;21 Aug, 13:30&#8242;, &#8216;Norwich City&#8217;, &#8216;1 &#8211; 1&#8217;, &#8216;Stoke City&#8217;), (&#8217;21 Aug, 14:05&#8242;, &#8216;Wolverhampton Wanderers&#8217;, &#8216;2 &#8211; 0&#8217;, &#8216;Fulham&#8217;), (&#8217;21 Aug, 16:00&#8242;, &#8216;Bolton Wanderers&#8217;, &#8216;2 &#8211; 3&#8217;, &#8216;Manchester City&#8217;), (&#8217;22 Aug, 20:00&#8242;, &#8216;Manchester United&#8217;, &#8216;3 &#8211; 0&#8217;, &#8216;Tottenham Hotspur&#8217;), (&#8217;27 Aug, 12:05&#8242;, &#8216;Aston Villa&#8217;, &#8216;0 &#8211; 0&#8217;, &#8216;Wolverhampton Wanderers&#8217;), (&#8217;27 Aug, 12:30&#8242;, &#8216;Wigan Athletic&#8217;, &#8216;2 &#8211; 0&#8217;, &#8216;Queens Park Rangers&#8217;), (&#8217;27 Aug, 15:00&#8242;, &#8216;Swansea City&#8217;, &#8216;0 &#8211; 0&#8217;, &#8216;Sunderland&#8217;), (&#8217;27 Aug, 15:00&#8242;, &#8216;Chelsea&#8217;, &#8216;3 &#8211; 1&#8217;, &#8216;Norwich City&#8217;), (&#8217;27 Aug, 15:00&#8242;, &#8216;Blackburn Rovers&#8217;, &#8216;0 &#8211; 1&#8217;, &#8216;Everton&#8217;), (&#8217;27 Aug, 17:30&#8242;, &#8216;Liverpool&#8217;, &#8216;3 &#8211; 1&#8217;, &#8216;Bolton Wanderers&#8217;), (&#8217;28 Aug, 13:00&#8242;, &#8216;Newcastle United&#8217;, &#8216;2 &#8211; 1&#8217;, &#8216;Fulham&#8217;), (&#8217;28 Aug, 13:30&#8242;, &#8216;Tottenham Hotspur&#8217;, &#8216;1 &#8211; 5&#8217;, &#8216;Manchester City&#8217;), (&#8217;28 Aug, 15:00&#8242;, &#8216;West Bromwich Albion&#8217;, &#8216;0 &#8211; 1&#8217;, &#8216;Stoke City&#8217;), (&#8217;28 Aug, 16:00&#8242;, &#8216;Manchester United&#8217;, &#8216;8 &#8211; 2&#8217;, &#8216;Arsenal&#8217;)]</p>
<p>The next was to obtain a list of the uk charts top 100 and find the youtube video for it.</p>
<blockquote><p>#!/usr/bin/python<br />
import urllib<br />
import urllib2<br />
import re<br />
import sys<br />
from BeautifulSoup import BeautifulStoneSoup  </p>
<p>def getvideolink(link):<br />
  request = urllib2.Request(link)<br />
  request.add_header(&#8216;User-Agent&#8217;, &#8220;Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/533.3 (KHTML, like Gecko) Qt/4.7.0 Safari/533.3&#8221;)<br />
  response = urllib2.urlopen(request)<br />
  text = response.read()<br />
  videos = re.findall(&#8220;&lt;a href=\&#8221;/watch\?v=([\w-]+)&#8221;, text)<br />
  return &#8220;http://www.youtube.com/watch?v=%s&#8221; % videos[0]</p>
<p>response = urllib2.urlopen(&#8216;http://localhost/test&#8217;)<br />
html = response.read()<br />
re_channel = re.compile(&#8220;&lt;h3&gt;(.*?)&lt;/h3&gt;&#8221; +<br />
 &#8220;\r\n.*?&lt;h4&gt;(.*?)&lt;/h4&gt;.*?&lt;h5&#8243;, re.I | re.S | re.M)<br />
find_result = re_channel.findall(html)<br />
#remove first entry as it&#8217;s a dup<br />
del find_result[0]<br />
for result in find_result:<br />
 title=unicode(BeautifulStoneSoup(result[0],convertEntities=BeautifulStoneSoup.HTML_ENTITIES ))<br />
 artist=unicode(BeautifulStoneSoup(result[1],convertEntities=BeautifulStoneSoup.HTML_ENTITIES ))<br />
 link=&#8221;http://www.youtube.com/results?search_query=&#8221; + urllib.quote_plus(title);<br />
 print getvideolink(link)</p></blockquote>
<blockquote></blockquote>
<blockquote><p>Sample output</p></blockquote>
<blockquote><p>RIHANNA FT CALVIN HARRIS &#8211; WE FOUND LOVE // http://www.youtube.com/watch?v=tg00YEETFzg<br />
FLO RIDA &#8211; GOOD FEELING // http://www.youtube.com/watch?v=3OnnDqH6Wj8<br />
ONE DIRECTION &#8211; GOTTA BE YOU // http://www.youtube.com/watch?v=nvfejaHz-o0<br />
LABRINTH FT TINIE TEMPAH &#8211; EARTHQUAKE // http://www.youtube.com/watch?v=u0fk6syQ7iY<br />
ED SHEERAN &#8211; LEGO HOUSE // http://www.youtube.com/watch?v=c4BLVznuWnU<br />
DAVID GUETTA FT USHER &#8211; WITHOUT YOU // http://www.youtube.com/watch?v=jUe8uoKdHao<br />
MAROON 5 FT CHRISTINA AGUILERA &#8211; MOVES LIKE JAGGER // http://www.youtube.com/watch?v=iEPTlhBmwRg<br />
JLS &#8211; TAKE A CHANCE ON ME // http://www.youtube.com/watch?v=djV11Xbc914<br />
PROFESSOR GREEN FT EMELI SANDE &#8211; READ ALL ABOUT IT // http://www.youtube.com/watch?v=-_oLfC5Z_Ys<br />
CHRISTINA PERRI &#8211; JAR OF HEARTS // http://www.youtube.com/watch?v=8v_4O44sfjM<br />
LMFAO &#8211; SEXY AND I KNOW IT // http://www.youtube.com/watch?v=wyx6JDQCslE<br />
DRAKE FT RIHANNA &#8211; TAKE CARE // http://www.youtube.com/watch?v=PaXslpx3MWY<br />
COLDPLAY &#8211; PARADISE // http://www.youtube.com/watch?v=1G4isv_Fylg<br />
CHARLENE SORAIA &#8211; WHEREVER YOU WILL GO // http://www.youtube.com/watch?v=iAP9AF6DCu4<br />
SATURDAYS &#8211; MY HEART TAKES OVER // http://www.youtube.com/watch?v=DgmoYgpMNX8<br />
CHER LLOYD FT MIKE POSNER &#8211; WITH UR LOVE // http://www.youtube.com/watch?v=axpO86pGHAM<br />
BRUNO MARS &#8211; IT WILL RAIN // http://www.youtube.com/watch?v=W-w3WfgpcGg<br />
LADY GAGA &#8211; MARRY THE NIGHT // http://www.youtube.com/watch?v=O4IgYxHEAuk<br />
LANA DEL REY &#8211; VIDEO GAMES // http://www.youtube.com/watch?v=HO1OV5B_JDw<br />
PIXIE LOTT FT PUSHA T &#8211; WHAT DO YOU TAKE ME FOR // http://www.youtube.com/watch?v=OQCcwNMp830<br />
KELLY CLARKSON &#8211; MR KNOW IT ALL // http://www.youtube.com/watch?v=0C_oNMH0GTk<br />
LOICK ESSIEN &#8211; ME WITHOUT YOU // http://www.youtube.com/watch?v=lKDmJwoZ4RA<br />
FLORENCE &amp; THE MACHINE &#8211; SHAKE IT OUT // http://www.youtube.com/watch?v=WbN0nX61rIs<br />
COLLECTIVE &#8211; TEARDROP // http://www.youtube.com/watch?v=u7K72X4eo_s<br />
ONE DIRECTION &#8211; WHAT MAKES YOU BEAUTIFUL // http://www.youtube.com/watch?v=QJO3ROT-A4E<br />
ED SHEERAN &#8211; THE A TEAM // http://www.youtube.com/watch?v=UAWcs5H-qgQ<br />
WANTED &#8211; LIGHTNING // http://www.youtube.com/watch?v=MQyHyfLp5NI<br />
JESSIE J &#8211; WHO YOU ARE // http://www.youtube.com/watch?v=j2WWrupMBAE<br />
LUCENZO &amp; QWOTE &#8211; DANZA KUDURO // http://www.youtube.com/watch?v=rUFgacK8sZ0<br />
GYM CLASS HEROES/ADAM LEVINE &#8211; STEREO HEARTS // http://www.youtube.com/watch?v=T3E9Wjbq44E<br />
MAVERICK SABRE &#8211; I NEED // http://www.youtube.com/watch?v=VA770wpLX-Q<br />
WESTLIFE &#8211; LIGHTHOUSE // http://www.youtube.com/watch?v=Tivph7mTku4<br />
SEAN PAUL FT ALEXIS JORDAN &#8211; GOT 2 LUV U // http://www.youtube.com/watch?v=tDq3fNew1rU<br />
LADY GAGA &#8211; THE EDGE OF GLORY // http://www.youtube.com/watch?v=QeWBS0JBNzQ<br />
GLEE CAST &#8211; RUMOUR HAS IT/SOMEONE LIKE YOU // http://www.youtube.com/watch?v=qb7zjKkLCoQ<br />
SLOW MOVING MILLIE &#8211; PLEASE PLEASE PLEASE LET ME GET WHAT I // http://www.youtube.com/watch?v=DMQbzLrvwlE<br />
KATY PERRY &#8211; THE ONE THAT GOT AWAY // http://www.youtube.com/watch?v=Ahha3Cqe_fk<br />
ELBOW &#8211; ONE DAY LIKE THIS // http://www.youtube.com/watch?v=0NFV8dHrZYM<br />
CHRISTINA PERRI &#8211; A THOUSAND YEARS // http://www.youtube.com/watch?v=z5Q8x1wYN4w<br />
SNOW PATROL &#8211; THIS ISN&#8217;T EVERYTHING YOU ARE // http://www.youtube.com/watch?v=Q-Gljs8Y3Q8<br />
RIZZLE KICKS &#8211; WHEN I WAS A YOUNGSTER // http://www.youtube.com/watch?v=Rc2iUwMpb8Y<br />
GOO GOO DOLLS &#8211; IRIS // http://www.youtube.com/watch?v=NdYWuo9OFAw<br />
DAPPY &#8211; NO REGRETS // http://www.youtube.com/watch?v=WoImizvsj5w<br />
BRUNO MARS &#8211; MARRY YOU // http://www.youtube.com/watch?v=xB40cQD677s<br />
ADELE &#8211; SET FIRE TO THE RAIN // http://www.youtube.com/watch?v=ss0HAdW1DnY<br />
NICKELBACK &#8211; WHEN WE STAND TOGETHER // http://www.youtube.com/watch?v=76RbWuFll0Y<br />
AFROJACK &amp; STEVE AOKI &#8211; NO BEEF // http://www.youtube.com/watch?v=ksocjhxX_DQ<br />
ADELE &#8211; SOMEONE LIKE YOU // http://www.youtube.com/watch?v=hLQl3WQQoQ0<br />
PIXIE LOTT &#8211; ALL ABOUT TONIGHT // http://www.youtube.com/watch?v=swcULf1ATyU<br />
NICKI MINAJ &#8211; SUPER BASS // http://www.youtube.com/watch?v=4JipHEz53sU<br />
CALLING &#8211; WHEREVER YOU WILL GO // http://www.youtube.com/watch?v=iAP9AF6DCu4<br />
JAMES MORRISON &#8211; I WON&#8217;T LET YOU GO // http://www.youtube.com/watch?v=sgRb_lfIZ6A<br />
OLLY MURS FT RIZZLE KICKS &#8211; HEART SKIPS A BEAT // http://www.youtube.com/watch?v=j5dFe-WKuPs<br />
EXAMPLE &#8211; MIDNIGHT RUN // http://www.youtube.com/watch?v=iwYGi7YG4Js<br />
TINCHY STRYDER/CALVIN HARRIS &#8211; OFF THE RECORD // http://www.youtube.com/watch?v=UknZiaIC9y8<br />
SAK NOEL &#8211; LOCA PEOPLE // http://www.youtube.com/watch?v=-d6b1yn-YhQ<br />
BRUNO MARS &#8211; RUNAWAY BABY // http://www.youtube.com/watch?v=UDG_CrqJV-0<br />
JASON DERULO &#8211; FIGHT FOR YOU // http://www.youtube.com/watch?v=2aSOQRih6WY<br />
CHER LLOYD &#8211; SWAGGER JAGGER // http://www.youtube.com/watch?v=sdbyG2MrBHk<br />
LADY GAGA &#8211; BORN THIS WAY // http://www.youtube.com/watch?v=wV1FrqwZyKw<br />
SNOW PATROL &#8211; CALLED OUT IN THE DARK // http://www.youtube.com/watch?v=GwTXwJg6_VE<br />
WANTED &#8211; WARZONE // http://www.youtube.com/watch?v=yMR382aefmQ<br />
JLS FT DEV &#8211; SHE MAKES ME WANNA // http://www.youtube.com/watch?v=FuwTgZOKcf8<br />
NICOLE SCHERZINGER &#8211; TRY WITH ME // http://www.youtube.com/watch?v=R7sYiTyBjTY<br />
COBRA STARSHIP FT SABI &#8211; YOU MAKE ME FEEL // http://www.youtube.com/watch?v=HpyZEzrDf4c<br />
JESSIE J &#8211; WHO&#8217;S LAUGHING NOW // http://www.youtube.com/watch?v=KsxSxF3JKeU<br />
NOEL GALLAGHER&#8217;S HIGH FLYING &#8211; AKA WHAT A LIFE // http://www.youtube.com/watch?v=lwHpLDgWonM<br />
FOSTER THE PEOPLE &#8211; PUMPED UP KICKS // http://www.youtube.com/watch?v=SDTZ7iX4vTQ<br />
WRETCH 32 FT JOSH KUMRA &#8211; DON&#8217;T GO // http://www.youtube.com/watch?v=bj1BMpUnzT8<br />
BIRDY &#8211; SKINNY LOVE // http://www.youtube.com/watch?v=aNzCDt2eidg<br />
WANTED &#8211; GLAD YOU CAME // http://www.youtube.com/watch?v=2ggzxInyzVE<br />
BIRDY &#8211; PEOPLE HELP THE PEOPLE // http://www.youtube.com/watch?v=OmLNs6zQIHo<br />
NICKI MINAJ FT RIHANNA &#8211; FLY // http://www.youtube.com/watch?v=3n71KUiWn1I<br />
SKREAM FT SAM FRANK &#8211; ANTICIPATE // http://www.youtube.com/watch?v=O3Z1X4MPsqk<br />
WILL YOUNG &#8211; JEALOUSY // http://www.youtube.com/watch?v=9MHtrM-jf9o<br />
ADELE &#8211; ROLLING IN THE DEEP // http://www.youtube.com/watch?v=rYEDA3JcQqw<br />
JESSIE J FT BOB &#8211; PRICE TAG // http://www.youtube.com/watch?v=qMxX-QOV9tI<br />
LMFAO/LAUREN BENNETT/GOONROCK &#8211; PARTY ROCK ANTHEM // http://www.youtube.com/watch?v=KQ6zr6kCPj8<br />
JASON DERULO &#8211; IT GIRL // http://www.youtube.com/watch?v=4oGUHRXT-wA<br />
BEYONCE &#8211; COUNTDOWN // http://www.youtube.com/watch?v=ACkBTqwxcUI<br />
RIZZLE KICKS &#8211; DOWN WITH THE TRUMPETS // http://www.youtube.com/watch?v=-aY92XgykhU<br />
COLDPLAY &#8211; EVERY TEARDROP IS A WATERFALL // http://www.youtube.com/watch?v=fyMhvkC3A84<br />
CALVIN HARRIS &#8211; FEEL SO CLOSE // http://www.youtube.com/watch?v=dGghkjpNCQ8<br />
ADELE &#8211; MAKE YOU FEEL MY LOVE // http://www.youtube.com/watch?v=LLoyNxjhTzc<br />
ONE DIRECTION &#8211; ANOTHER WORLD // http://www.youtube.com/watch?v=RyZfNBVX1q0<br />
COLDPLAY &#8211; VIVA LA VIDA // http://www.youtube.com/watch?v=dvgZkm1xWPE<br />
BEYONCE &#8211; LOVE ON TOP // http://www.youtube.com/watch?v=Ob7vObnFUJc<br />
EAGLE-EYE CHERRY &#8211; SAVE TONIGHT // http://www.youtube.com/watch?v=dTa2Bzlbjv0<br />
EN VOGUE &#8211; DONT LET GO (LOVE) // http://www.youtube.com/watch?v=QUdAT5Fwnvk<br />
KATY PERRY &#8211; FIREWORK // http://www.youtube.com/watch?v=QGJuMBdaqIw<br />
MODESTEP &#8211; TO THE STARS // http://www.youtube.com/watch?v=UTKSUlMbp9A<br />
DRAKE &#8211; HEADLINES // http://www.youtube.com/watch?v=cimoNqiulUE<br />
ED SHEERAN &#8211; YOU NEED ME I DON&#8217;T NEED YOU // http://www.youtube.com/watch?v=temYymFGSEc<br />
WOODKID &#8211; IRON // http://www.youtube.com/watch?v=vSkb0kDacjs<br />
DELILAH &#8211; GO // http://www.youtube.com/watch?v=cxNe9jWNuEU<br />
KATY PERRY FT KANYE WEST &#8211; ET // http://www.youtube.com/watch?v=t5Sd5c4o9UM<br />
JAMES VINCENT MCMORROW &#8211; HIGHER LOVE // http://www.youtube.com/watch?v=9Z-fE1l9SZ4<br />
BRUNO MARS &#8211; JUST THE WAY YOU ARE (AMAZING) // http://www.youtube.com/watch?v=LjhCEhWiKXk<br />
PITBULL/NE-YO/AFROJACK/NAYER &#8211; GIVE ME EVERYTHING // http://www.youtube.com/watch?v=EPo5wWmKEaI</p></blockquote>
<blockquote></blockquote>
<blockquote><p>Then I wanted to test threading so I came up with something to check a list of links and obtain the &#8220;Server:&#8221; header</p></blockquote>
<blockquote><p>#!/usr/bin/env python<br />
import urllib2<br />
import re<br />
import os<br />
import sys<br />
import time<br />
from multiprocessing import Pool</p>
<p>#Accept file name as input or use default<br />
try:<br />
  filename = sys.argv[1]<br />
except IndexError:<br />
  filename = &#8220;links&#8221;</p>
<p>#Function to load urls from file<br />
def loadurls(filename):<br />
  try:<br />
    inputdata = file(filename).readlines()<br />
    if len(inputdata) &gt; 0:<br />
      return inputdata<br />
  except:<br />
    print &#8220;ERROR &#8211; Unable to process url list&#8221;<br />
    sys.exit()</p>
<p>#Function to get SERVER header<br />
def getversion(url):<br />
  try:<br />
      request=urllib2.Request(url)<br />
      response=urllib2.urlopen(request)<br />
      version=response.info().getheader(&#8216;Server&#8217;)<br />
  except:<br />
      return &#8220;ERROR &#8211; Unable to fetch %s&#8221; % (url)</p>
<p>  if version: print &#8220;Url: %s Version: %s&#8221; % (url, version)</p>
<p>start = time.time()<br />
urls=loadurls(filename)<br />
p = Pool(15)<br />
data = p.map(getversion,urls)</p>
<p>elapsed = (time.time() &#8211; start)<br />
print &#8220;Processed %s urls in %0.2f seconds&#8221; % (len(urls), elapsed)</p></blockquote>
<blockquote><p>Sample output</p></blockquote>
<blockquote><p>scott@scott:~/python$ ./server-header.py list<br />
Url: http://www.bbc.co.uk<br />
 Version: Apache<br />
Url: http://www.google.co.uk<br />
 Version: gws<br />
Url: https://scott.cm<br />
 Version: Apache<br />
Processed 4 urls in 1.07 seconds</p></blockquote>
<blockquote></blockquote>
<blockquote><p>None of these really serve any purpose and were merely tests I thought I would share.   Overall things have been quite easy and feel reasonably confident after just 2 days.</p></blockquote>
]]></content:encoded>
					
					<wfw:commentRss>https://scott.cm/learning_python/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
