My first Python code

For a challenge I’ve tried to teach myself the Python programming language. It’s a big language with many features which I, as an ex-programmer from many decades ago, am unfamiliar with. But I’ve managed to write and test the code below, though I’m not sure I want to take this much further. I’ll see…..

import csv
from datetime import datetime
from operator import attrgetter
#======================================================
# A re-creation of my Reminder program from several decades ago!! My first Python program!
#
# Version 0.1 04-Mar-2021 In the beginning
# Version 0.2 07-Mar-2021 In the beginning 
# Version 0.3 07-Mar-2021 I'm finally happy!
#======================================================
class Reminder:
    def __init__(self, myRec):
        self.Date = myRec[0]
        self.DateTimeConversion = datetime.strptime(myRec[0],"%d-%b-%Y")
        self.Message = myRec[1]
#======================================================
# Function GetReminderData to get the reminder data
#
#
# Read each record in the file
# Ignore any blank lines 
# Add each record to the list myReminders
#
def GetReminderData(myFile,myReminders) :
    with open(myFile) as csv_file:
        csv_reader = csv.reader(csv_file, delimiter=',')
        line_count = 0
        for rec in csv_reader:
            if rec == []:
                pass
            else:
                line_count += 1
                p = Reminder(rec)
                myReminders.append(p)    
    csv_file.close()
#====================================================
# Function HowManyDaysDifference to get the number of days between today's date and a text date
# This is my weird code - what a palaver!
def HowManyDaysDifference(TextDate):
    today_object = datetime.now()
    mydate_in_datetime = datetime.strptime(TextDate,"%d-%b-%Y")
    tdiff = mydate_in_datetime - today_object
    diff_in_days = tdiff.days
    if diff_in_days >= 0:
        diff_in_days += 1
    else:
        tdiff = today_object - mydate_in_datetime
        diff_in_days = -tdiff.days
  
    return diff_in_days
#==================================================
# Function PrintList to nicely print the data
def PrintList ():
    mySectionSeparator = "-" * 75
    tChange = True
    print ("\n" * 10 )
    print ("         Welcome to my Python Reminder program!")
    print (mySectionSeparator)
    
    for i in sorted(myReminders, key = attrgetter('DateTimeConversion')):
        nDays = HowManyDaysDifference(i.Date)
        if tChange and nDays > 0:
            tChange = False
            print (mySectionSeparator)
        if nDays == 0:
            t1 = "     Today    "
        elif nDays == -1:
            t1 = "   Yesterday  "
        elif nDays == 1:
            t1 = "    Tomorrow  "
        elif nDays < 0:
            t1 = '{:4d}'.format(-nDays) + " days since"
        else:
            t1 = '{:4d}'.format(nDays) + " days until"
        t2 = i.Date +t1
        print (t2,i.Message) 
    
    print (mySectionSeparator)
#=================================================
# This is the MAIN  program
#
myFile = 'C:/Users/Mike/Documents/Documents/MyPythonCode/Reminder.dat'

myReminders = []

GetReminderData(myFile, myReminders)

PrintList()

And the output is….


How to Remotely Troubleshoot Your Relative’s Computer

I have a friend who occasionally rings me up with his computer problems. Yesterday he called to say his annual anti-virus licence was going to expire that day. He confessed to having ignored the renewal reminders!

My experience with renewing McAfee anti-virus licences is that a) renewing from McAfee is ridiculously expensive, and b) not renewing from McAfee is never straightforward. My friend took my advice and went for the second option and purchased a McAfee licence from another company (InterSecure.co.uk). Inevitably the update wasn’t straightforward and wasn’t successful, hence his call for my assistance. In normal times I would probably have gone to my friend’s home, but these are not normal times.

I searched the web for how to remotely take control of someone’s computer and came across a very helpful page on the PCMag site “How to Remotely Troubleshoot Your Relative’s Computer“. Although I’ve had a career in IT support I’d never needed to do this before and this web page proved a godsend. The section on using a Windows 10 PC to take control of another Windows 10 PC was very straightforward and uses the Quick Assist tool (found under Windows Accessories). Having taken remote control of my friend’s PC I was able to install the new licence for his anti-virus software, though it wasn’t straightforward!!😎


Being a writer

I’m currently reading ‘Confessions of a Ghostwriter’ by Andrew Crofts, one of a handful of recent books from Dorking’s Oxfam Books. It’s prompted me to recall the time I sat in an office opposite Colin, who was a freelancer and had the job title of technical writer.

At the time I never understood how someone could write a technical document on a subject they had no knowledge or experience of. My view of Colin was probably also conditioned by the fact that he seemed to spend most of the working day on the phone discussing this, that and the other about cricket. Colin was either a cricketer or involved in the running of a local cricket club or league. I don’t recall seeing any technical documents Colin produced, so I’m not able to judge whether he was good at his job.

As part of the process of developing computer software, I always loved writing the necessary user documentation. I wrote documentation much as I wrote software. I dived in and after many re-writes and revisions I would arrive at what I regarded a pleasing end-product. This is probably not recommended or efficient but it was the way that suited my way of thinking and working.

Interestingly, when it comes to writing a blog post, I can often write something in my head but when it comes to entering it into the computer I somehow lose the words. Hence most of my posts are mainly images!

That was the week that was

This week, the new Dell laptop came. It’s very, very quick, having an i7 processor and a solid-state drive rather than a hard-drive. What a contrast to the old (7 years) one.

The last two episodes of Modus on BBC4 confirmed the series to be a dreadful mess and a waste of 8 hours. However binging on Maltese: The Mafia Detective, on All4 was most satisfying. (binging or bingeing?)

Reading Skinny Dip by Carl Hiaasen was a terrific  romp about a husband who throws his wife off a cruise liner on their wedding anniversary.

Needing extra motivation to visit the cinema more often, I became a member of the Curzon art-house cinema chain.

Snow is always a childish delight for me but its stay was all too short and there really wasn’t enough of it.