OU blog

Personal Blogs

David Pennington

New blog post

Visible to anyone in the world
Edited by David Pennington, Wednesday, 23 Mar 2016, 19:11

As mentioned, I am a newbie to Python. I was concerned about learning it because of my experience with Ruby on Rails some years ago. When I tackled Ruby, I kept getting annoyed because most of the stuff was so complicated in comparison with Smalltalk that I wondered why anyone would bother. Along the way, I got caught up in its constant automatic update of versions and finally threw it away. On first glance, I had a similar impression of Python but I had no choice but to get to grips with it if I was to make a good fist of the up-coming course.

I set myself a timetable of 8 hours a week to study as this got me into the right frame of mind that will be needed for my OU course. I then set myself a project to recreate my "Let's learn Latin" web program in Python. The plan included three steps.

  1. To write a Python program to test vocabulary.
  2. To add the Pandas library to it and start to do some statistical analysis of the results. (Pandas is a library that includes lots of stats stuff).
  3. Convert it to be a web program.

I got as far as midway through 2 when I came up with a better plan. 

Problem

I run an e-mail and web server from home. The e-mail server provides a domain for all of the family to have simple e-mail addresses. Mine, for instance, is david@xxxweb.com. Recently, I replaced the server with a new Lenovo machine that has now updated itself to Windows 10. Being a long time Mac man (since 1990!), I don't much like this but I can't get the e-mail moved to the Mac as we have some much history in the Windows program that we use (Magic Winmail). The problem is that the server randomly freezes and I can't find any reason. I have got so irritated that I have considered going back to Windows XP. I don't always notice that the server has frozen so, sometimes, it is down for a couple of hours. I have a Pingdom account but that sends to my own e-mail address which is useless but, since Pingdom changed their web site, I can't seem to find where to go to change the address. 

Answer

I have written a headless Python program that loops around every 20 seconds and tests that one of the web sites on the server is responding. If it isn't then it sends an e-mail to my Outlook mail account, which gets forwarded to my iCloud mail. Along the way, it logs its actions and responses to a logfile on the Mac. This took about 7 hours to write and works perfectly.

Assessment

Python has proved to be very understandable, once I got the idea of line indentation and its use of commas. The main thing that I like is the depth of its available libraries. I have the following libraries in my program:

import smtplib
import requests
import time
import configparser
import os
These provide simple access to e-mail sending, html gets, delay management, ini file and text file access. These significantly reduced my development time. I am very impressed. I now feel that I have come to grips with the language and, although I am a long way from being an expert, I feel that I can cope with anything that comes along. The code can be seen HERE.

I am now going back to the vocabulary tester to complete the statistical side.

Permalink Add your comment
Share post