{"id":304,"date":"2013-09-30T19:39:00","date_gmt":"2013-09-30T19:39:00","guid":{"rendered":"http:\/\/thomas.w-p.me.uk\/blog\/2013\/09\/the-python-challenge-7\/"},"modified":"2020-08-23T08:49:42","modified_gmt":"2020-08-23T08:49:42","slug":"the-python-challenge-7","status":"publish","type":"post","link":"https:\/\/thomas.w-p.me.uk\/blog\/2013\/09\/the-python-challenge-7\/","title":{"rendered":"The Python Challenge &#8211; 7"},"content":{"rendered":"<p>This was pretty easy.\u00a0 The hardest thing was realising I needed the PIL image library and then installing it.\u00a0 Thank you to Samson for <a href=\"http:\/\/www.pythonware.com\/products\/pil\/\">the link to the PIL download page<\/a>.\u00a0 Once up and running it was pretty easy to pick the grey squares and decode their RGB value to a letter&#8230;<\/p>\n<p>The code was the same for both this time since I opted to open the page directly and not use print.<\/p>\n<p>Python 2.7 and 3.2.3 code <\/p>\n<pre>#smarty?<br>from PIL import Image<br>import re, webbrowser<br>im = Image.open(\"oxygen.png\")<br>#get height and width<br>xy = im.size<br>height = xy[1]<br>width = xy[0]<br>#grey lines appear to go down the middle, assume that the value corresponds to a letter and boxes are 7 square<br>count = 3<br>message = \"\"<br>while count < width-21:<br>    pix = im.getpixel((count,45))<br>    count += 7<br>    message += chr(pix[0])<br>regex = r'((?<=\\[).*(?=\\]))'<br>numbers = re.findall(regex, message)<br>letters = numbers[0].split(\", \")<br>final = \"\"<br>for letter in letters:<br>    final += chr(int(letter))<br>webbrowser.open(\"http:\/\/www.pythonchallenge.com\/pc\/def\/\" + final + \".html\",new=2)<br><br><br><br><br><br><br><br><br><br><br><br><br><br><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This was pretty easy.\u00a0 The hardest thing was realising I needed the PIL image library and then installing it.\u00a0 Thank you to Samson for the link to the PIL download page.\u00a0 Once up and running it was pretty easy to pick the grey squares and decode their RGB value to a letter&#8230; The code was &hellip; <a href=\"https:\/\/thomas.w-p.me.uk\/blog\/2013\/09\/the-python-challenge-7\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">The Python Challenge &#8211; 7<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[39],"class_list":["post-304","post","type-post","status-publish","format-standard","hentry","category-general","tag-python"],"_links":{"self":[{"href":"https:\/\/thomas.w-p.me.uk\/blog\/wp-json\/wp\/v2\/posts\/304","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thomas.w-p.me.uk\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thomas.w-p.me.uk\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thomas.w-p.me.uk\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thomas.w-p.me.uk\/blog\/wp-json\/wp\/v2\/comments?post=304"}],"version-history":[{"count":1,"href":"https:\/\/thomas.w-p.me.uk\/blog\/wp-json\/wp\/v2\/posts\/304\/revisions"}],"predecessor-version":[{"id":1009,"href":"https:\/\/thomas.w-p.me.uk\/blog\/wp-json\/wp\/v2\/posts\/304\/revisions\/1009"}],"wp:attachment":[{"href":"https:\/\/thomas.w-p.me.uk\/blog\/wp-json\/wp\/v2\/media?parent=304"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thomas.w-p.me.uk\/blog\/wp-json\/wp\/v2\/categories?post=304"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thomas.w-p.me.uk\/blog\/wp-json\/wp\/v2\/tags?post=304"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}