2.039 lens case, coding

Sunday 01/10/2021

(I just realized that day 3.001 is also going to be a palindrome, 12/02/2021. But that’s 11 months away.)

After the Sunday paper and watering the plants and the crossword it was only 9:20 and I decided to go for a Baylands walk. But I got to the basement and realized I had another chore to do, setting up the volunteer sign-up sheet for next week’s package reception task. So back to the room and do that and then out again 15 minutes later. Walked about 3 miles feeling nominal, so that’s good.

I called the kitchen and canceled my tray lunch, and for lunch had instead the rest of the very good chili from Willies, and one rib. There’s still 4 ribs to consume.

Then I worked on a minor project that I’ve had in mind for some time. The Channing House Xfinity system a plethora of channels and I find myself using the search function often to find them, because the printed channel list that came with the X1 receiver is badly organized and hard to read. I want the channels in a spreadsheet form where I can sort the rows by number or by channel name. But there are several hundred (I can say now, definitively, 454 total) and that’s a lot of tedious data entry.

So I used my OCR software and the scanner in my printer to OCR the Xfinity pamphlet. That got me the list as text, still in a badly organized format. But a little editing to clean it up and then… how to make it a CSV so I could load it in Numbers? I wrote a tiny program in Python to do the job. Nobody cares but I’m going to put the code right here.

Quick and dirty program to convert a file like this (made by OCR of an Xfinity pamphlet)
    2 KTVU (FOX)
    3 KNTV (NBC)
    25,1068 KTLN (INR)
    26,29,1074,1076 Government Access
into a file like this:
    26,"Government Access","LIMITED BASIC"
    29,"Government Access","LIMITED BASIC"
    1074,"Government Access","LIMITED BASIC"
    1076,"Government Access","LIMITED BASIC"
that is, a CSV file in which the first column is a single channel number,
the second is the station name/description, and the third is the package.

A sufficient file path must be the first argument. The output goes to
"output.csv" in the current directory.
import sys
file_path = sys.argv[1]
the_file = open(file_path,mode='r',encoding='Latin 1')
the_data = the_file.read() # slurp it all in
lines = the_data.split('\n') # make a list of the lines
# print(len(lines)) answer was 454
package = ""
output = [] # list of output lines
for line in lines:
    if len(line)==0 : continue # ignore blank line
    if line[0].isalpha():
        # new package name e.g. "PREMIUM CHANNELS"
        package = line
        # a line with channel numbers and name e.g. "25,1068 KTLN (INR)"
        number_group = line.split(' ')[0] # "25,1068"
        channel = line[len(number_group):].strip() # "KTLN (INR)"
        numbers = number_group.split(',') # ["25","1068"]
        for number in numbers: # "1068"
csv_file = open('output.csv',mode='w',encoding='Latin 1')
csv_file.writelines(output) # splurt all the output

(Goodness the WordPress “code” format block is crap.) That’s pretty crude but it did the job, and all 454 rows loaded into Numbers just fine. Next to fiddle with it in spreadsheet land to make it easier to sort.

I wrote about the 500mm telephoto lens on day 2.031. I mentioned that its leather case was dry dirty and cracked. Over the last couple of days I’ve been working “Leather Honey” into it, and putting black shoe polish on the worst of the places where the black has chipped off.

It ain’t great but it’s better than it was. I have the lens on the camera, on the tripod, on the deck waiting for something in the sky to shoot. The moon or something.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s