Books Read & Calibre Web Update

Previously (Making A “Books Read” Page) I had posted how I added info to the default Calibre Web templates to add the Series and Pub date information so I could scrape it. Well, it’s gotten a bit more complex since then. Someone added a similar mod to the Github repository which has not yet been incorporated. They didn’t add the pub dates, but did add the series to a few more pages so I thought I would restate my changes here for future reference.

/templates/shelf.html

Add both series info and pub date for the python web scraping program to access:

{% if entry.series|length > 0 %}
    <p class="series">
        {{_('Book')}} {{entry.series_index}} {{_('of')}} <a href="{{url_for('web.books_list', data='series',sort='abc', book_id=entry.series[0].id)}}">{{entry.series[0].name}}</a>
    </p>
{% endif %}


{% if entry.pubdate[:10] != '0101-01-01' %}
    <p class="publishing-date">{{entry.pubdate|formatdate}} </p>
{% endif %}

Added around line 45 (just after the {% endif  %} for the author section). 

/templates/index.html

Add only series info just for aesthetics (note the code is from the proposed mod and is slightly different):

        {% if entry.series.__len__() > 0 %}
        <p class="series">
          <a href="{{url_for('web.books_list', data='series', sort='new', book_id=entry.series[0].id )}}">
            {{entry.series[0].name}}
          </a> 
          ({{entry.series_index}})
        </p>
        {% endif %}

Added around line 193 111 (just after the {% endif  %} for the author section). (This might be 36… there seems to have been a change…)

/templates/discover.html

        {% if entry.series.__len__() > 0 %}
        <p class="series">
          <a href="{{url_for('web.books_list', data='series', sort='new', book_id=entry.series[0].id )}}">
            {{entry.series[0].name}}
          </a> 
          ({{entry.series_index}})
        </p>
        {% endif %}

Added around line 36 (just after the {% endif  %} for the author section).


I am trying to figure out a way to automate the mods if the main repository doesn’t decide to incorporate the changes but so far an elegant solution eludes me.

Not stupid exactly but…

I’m filing this under Stupid Human Tricks but it’s not exactly stupid. I  am on the fence about gun control (although I agree that some guns really have no place in the marketplace). But this exchange from CBC.ca’s comments really exemplifies one of the core issues. It’s not about the gun, it’s about the social philosophy that states we should all have what we “want” if we manage to work hard enough or have enough money/privilege/connections. Spoiler alert: No, no we can’t always get what we want.

XXXXXX posted 18 minutes ago
Yeah, ’cause I need an assault rifle to wipe out gophers and covid on my property.

 
Reply to @XXXXXX: Do you “need” a 10k Rolex? Or a car that does double the speed limit? This isn’t about need, it’s about want, and how every law abiding taxpaying citizen is entitled to want and subsequently own whatever property they desire.

Instagram This Week

Of course there is this image, also called “Working” from almost exactly a year ago. Much better scenery! Sigh. #workingremotely @nanaimoyachtcharters #DesolationSound #2019
Of course there is this image, also called “Working” from almost exactly a year ago. Much better scenery! Sigh.
#workingremotely @nanaimoyachtcharters #DesolationSound #2019
I like to call this Working from Home. Notice the discrepancy in the definitions of “working.”
I like to call this Working from Home. Notice the discrepancy in the definitions of “working.”

Stupid Human Tricks revisited

It’s been a while since I posted one of these.

An article on the CBC about an 18-year old kid caught doing 308 km/hr in a 100 zone.
https://www.cbc.ca/news/canada/hamilton/burlington-qew-stunt-driving-308-1.5564486

This was one of the comments. I can’t even…

Reuben Danko 8 minutes ago
Nothing wrong with speeding as long as one know how to handle a vehicle at that speed , what is dangerous is those who can not handle a vehicle within or below the ridicule speed limits. It is quite feasible to drive on a 3 lane hiwghay at 140 Km/H to 16 Km/h, the Europeans do, with narrower lanes, and have less accidents than drivers in the US and CAN, because they know how to drive,m most drive 5 speeds, not that girl sort of nonsense of automatic (works to sell cars and place more inept behind the wheel, mostly women and mentally slow men). Driving needs to be reserved for those who can handle a foot cluctch, 5-6 sped manual on a rear wheel traction, try texting, put on make up (CAN and US women are known to do dirty things to) eat (that is something utterly abhorrent eat in a car). In life there are drivers and there are commuters, most CAN and US are commuters, and they proved it, more safety toolls in cars today than ever and the number of accidents and dead has not dropped significantly.

It was deleted about 30 minutes later (thank god). The number of people defending the kid blew me away (200 km/hr OVER people!) but this guy doubled down big time.

Instagram This Week

My mom. In her 80s and still doing cool shit. #AlwaysMyHero
My mom. In her 80s and still doing cool shit.
#AlwaysMyHero
I had some glass I had picked up at a garage sale that I didn’t particularly like so I thought I would try out a few glass “sketches.” A few really quick experiments... #stainedglass #quickart
I had some glass I had picked up at a garage sale that I didn’t particularly like so I thought I would try out a few glass “sketches.” A few really quick experiments…
#stainedglass #quickart

Updating a digital log

Years ago when we first started chartering I created a Filemaker database to track our voyages and sea miles. A lot of charter companies want a “resume” and I had heard if I ever wanted to get some really advance certification that one needed minimum numbers of recorded miles as crew and captain. So I used the database to track miles etc. At the end of each trip I would diligently add in all the days, miles, notes and lat/long if I had happened to note them.

Fast forward a bunch of years and my version Filemaker now no longer runs reliably on my updated OS. And since I no longer have any need for it, buying a new license doesn’t seem like a reasonable expense. Luckily I had both a printout of the contents and was able to export the data from the files between crashes. But it was time to acquire a new database tool.

MySql/php

A bit of  sniffing around the internet and it became clear that building a MySql database was going to be the likely successor. But unlike Filemaker, it has no graphical interface—so that meant if I wanted it to be at all user friendly I would need to build a custom php website to add, view and edit the data. Since my knowledge of both MySql and php was cursory to say the least, it looked like an impossible task. But nothing ventured, nothing gained…

MySql text interface

To cut a very long story short (or at least shorter) I managed to find a nice tutorial for building a CMS (content management system) and then began the painful task of hacking it into my new Cruising Log. Along the way I have learned tons and tons and have thoroughly enjoyed the exercise. As a work in progress it probably took me around a year to get it to the state it’s in now—although a lot of that was back-tracking to do things over so future changes would also work. I am a very dangerous coder.

Entering Data

The original design was based on the idea that I would get home after a cruise, grab info from the official ship’s log and then type it all in manually. But I use Farkwar.com to post updates on a daily basis while I am cruising which updates our position by means of an email formatted in particular way:

Enter text and/or notes here.
-----
At 04/24/2020 10:40 (pdt) our position was 49°50.1068?N,124°31.6473’W
Destination: Nanaimo

It occurred to me that my site could also parse the email and potentially update the database automatically. So I rejigged the email in a way that allows Farkwar to ignore the extra information and leaving me able to enter what I wanted to. Next I wrote a python script to parse the email, extract the relevant data and output in a format that MySql will understand. Then when I send it to my secret Farkwar email, I cc it to a personal secret email—Farkwar will post the position and update its map, and my python script will parse and post it to the database. So now the email looks like this:

Log Entry
We decided to go. It will be an arduous journey but I have faith we will survive it mostly unscathed.

Whales will be looking forward to our visit
-----
At 05/21/2020 10:40 (pdt) our position was 49°50.1068?N,124°31.6473’W
Destination: Nanaimo
From: Edmonton
To: Nanaimo
Distance: 0

…and this results in a posted entry that looks like this:

Back to the site

But before I could really get going I had to build the website, connect it to the MySql database in a more or less secure way and start formatting various pages. Another long , hijinx-filled story I won’t bore you with. So after a few farcical fits and starts, the site now consists of a front end with two pages (an overall view and a detail page for each cruise):

…and an admin backend that allows me to add/delete/edit  boat lists, crew lists, and the cruises themselves.

Of course it is never that simple, and a lot of extra things needed to be built along the way—like a login screen, a database table to hold users and some truly convoluted MYSQL statements to  be able to display and edit the information I wanted in the way I wanted it. (And, as I just discovered, a way to delete an entire voyage.) But in the end I got it done.

I also realized that since I had the latitude and longitude nicely formatted it wouldn’t be hard to build a link to google maps: https://www.google.com/maps/place/49%C2%B0%2030.8916%20N+123%C2%B0%2057.8196%20W so I could visually see the various locations each entry was made. So I did.

Printing

The last piece of the puzzle was the ability to print a nicely formatted pdf version of the log as a whole. I started off experimenting with some php to pdf utilities but in the end decided to design a nicely formatted webpage and then print direct to pdf.

Conclusion

After all that, I decided not to schedule the updating script and rather I will just run it when I get home —at least for the first few trips to ensure everything works in real world conditions. That is if we ever get to go cruising again 😉

The very last thing I did was port a copy from my personal server to the server where NeverforEver.ca is situated and try and set it up as a sample. Which, after a long battle, you can now find here: Cruising Log. If anyone is interested in the back end, let me know and I might send you a temp admin password.

It’s been a great learning experience and makes me want to do more development. Apparently Swift is pretty close to Python, and Swift is the official language of iOS development. Maybe I could make it into an iphone app next? If this COVID thing goes on long enough, well, who knows…

P.S. As a side note, according to my fancy new cruising log, not including inland water trips, I am officially at 6218 nm total cruising.

P.P.S. I will likely post at least the python code over at macblaze.ca, but probably not for a few days as it will take a bit of cleaning up.
—Bruce #Posts

Instagram This Week

Sourdough in a day. Cold starter at 9 am this morning and out of the oven at 5:20 pm. Pretty successful experiment I’d say.
Sourdough in a day. Cold starter at 9 am this morning and out of the oven at 5:20 pm.
Pretty successful experiment I’d say.
Sandhill cranes! Must of been a couple thousand right over the house. So lucky to spot them this year. #yeg #yegbirds
Sandhill cranes! Must of been a couple thousand right over the house. So lucky to spot them this year. #yeg #yegbirds
Fixing cat tails. Does this qualify me as a vet? ?
Fixing cat tails. Does this qualify me as a vet? ?
Me. Today.
Me. Today.

Instagram This Week

Did you ever wonder what would happen if you used convection to preheat an oven and then forgot to turn it off? #breaddisaster #breadfail #sourdough @bakewithjack
Did you ever wonder what would happen if you used convection to preheat an oven and then forgot to turn it off?#breaddisaster #breadfail #sourdough @bakewithjack