Date/Time Conversion in Python – ISO 8601 UTC to Pacific Standard Time

I had an issue where I was getting an ISO 8601 UTC date back from one of my API requests and I was asked to convert it to Pacific time as I was providing the information in a report. Since I had no idea what I was doing I first had to figure out what kind of date I was dealing with so that I could then figure out what I was trying to get to.

Here is what an ISO 8601 date looks like:  2019-12-24T15:04:18Z


Here is what the format of the data will look like after the process has been run: 12-24-2019 7:04:18

#Modules needed
import datetime
import pytz

#set the variable for Pacific timezone
pst = pytz.timezone(‘US/Pacific’)

#create the time variable date_time that will be used throughout, the data is coming from an api request and I am getting back json data.
date_time = (ISO 8601 Date)
#set the format for the date time
date_time = datetime.datetime.strptime(date_time, “%Y-%m-%dT%H:%M:%SZ”)
#tell python the current timezone is UTC
date_time = pytz.timezone(‘UTC’).localize(date_time)
#tell python to change the timezone to Pacific
date_time = date_time.astimezone(pst)
#update the variable with the new time and date in the new format
date_time = date_time.strftime(“%m-%d-%y %H:%M:%S”)


Books read during the 2020 year

As I did last year, here are the books I managed to consume this year. Granted that I had alot of freetime with whole Covid thing, but I did manage to get through a lot of books:

Eclipsed Core
Hell Divers 6 – Allegiance
The Admirals: Nimitz, Halsey, Leahy, and King
Archangel Rising
Warship(Black Feet Saga Book 1)
Call To Arms(Black Feet Saga Book 2)
The Battle of Midway
New Frontiers(Black Feet Saga Book 3)
Counterstrike(Expansion War)
Iron & Blood(Expansion War)
Destroyer(Expansion War)
Battleground(Unification War Trilogy Book1)
Omega Rising
Omega Force – Soldiers of Fortune
Omega Force – Savage Homecoming
Omega Force – The Enemy Within
Omega Force – Return of the Archon
Omega Force – Secret of the Phoenix
Omega Force – Redemption
Omega Force – The Human Factor
Omega Force – Revolution
Omega Force – Legends Never Die
Omega Force – Rebellion
Rainbow Six
Marine – Joshua Dalzelle
Boneshaker – Joshua Dalzelle
Terms of Enlistment – Mark Kloos
Lines of Departure – Mark Kloos
Chaos Core – Gage Lee
Angles of Attack – Marko Kloos
Chains of Command – Marko Kloos
Points of Impact – Marko Kloos
Fields of Fire – Marko Kloos
Into the Black – Evan Currie
CWSP – Certified Wireless Security Professional
The Heart of the Matter – Evan Currie
CWDP – Certified Wireless Design Professional
The Right of the Line – Ark Royal Book 14 – Christopher Nuttall
Duel in the Dark – Blood on the Stars I – Jay Allen
Call to Arms – Blood on the Stars II – Jay Allen
Ruins of Empire – Blood on the Stars III – Jay Allen
Echoes of Glory – Blood on the Stars IV – Jay Allen
Cauldron of Fire – Blood on the Stars V – Jay Allen
Dauntless – Blood on the Stars VI – Jay Allen
The White Fleet – Blood on the Stars VII – Jay Allen
Black Dawn – Blood on the Stars VIII – Jay Allen
Invasion – Blood on the Stars IX – Jay Allen
Night Fall – Blood on the Stars X – Jay Allen
The Grand Alliance – Blood on the Stars XI – Jay Allen
Relentless – RA Salvatore
Omega Force The Pandora Paradox – Joshua Dalzelle
Colossus – Blood on the Stars XII – Jay Allen
The Others – Blood on the Stars XIII – Jay Allen
Last Stand – Blood on the Stars XIV – Jay Allen
Surviving Home – A American
Escaping Home – A American
Going Home – A American
Forsaking Home – A American
Favour the Bold – Christopher G. Nuttall
Burning Core – Gage Lee
Infinite Core – Gage Lee
The Lion and Unicorn – Christopher G. Nuttall
The Ember War – Richard Fox
Order of Battle – Frontlines Book 7 – Marko Kloos

2019 Reading List

Listing of the books I managed to consume in 2019. I would say I don’t have a lot of time on my hands and that I don’t have time to read with my job and everything else that I have going on, but I think I managed to consume a good number of books this year. Some from different genres, some technical, and some that are just books I read over and over(The Martian). Without further ado, here is my list of books for 2019:

CWAP
CWNA
Oath of Office
The Pacific Crucible
Hollowcore
Boundless
The devil in the white city
The Magitech Chronicles books 1-4
Mech Warriors: The complete series
The True Measure
A house Divided
The Ibarra Sanctions
Terran Strike Marines Books 1 and 2
Iron Dragoons
Ark Royal Series Books 1-12
Complete book of the SR-71
Hell Divers V
Maestro
Underwater Photography Masterclass
Vengence of the Iron Dwarf
Warrior King (Odyssey One Book 5)
Odysseus Awakening (Odyssey One Book 6)
Ferrum Corde (Terran Armor Corps Book 6)
Odysseus Ascendant (Odyssey One Book 7)
Krox Rises: The Magitech Chronicles Book 5
Infinity War: Collected Edition
Nefarius: The Magitech Chronicles Book 6
The Ruins of Anthalas (The Ember War Saga Book 2)
Blood of Heroes (The Ember War Saga Book 3)
Earth Defiant (The Ember War Saga Book 4)
The Gardens of Nibiru (The Ember War Saga Book 5)
The Battle of the Void (The Ember War Saga Book 6)
The Siege of Earth (The Ember War Saga Book 7)
The Crucible (The Ember War Saga Book 8)
Cartwright’s Cavaliers (The Revelations Cycle Book 1)
Asbaran Solutions (The Revelations Cycle Book 2)
Winged Hussars (The Revelations Cycle Book 3)
The Dotari Salvation (Terran Strike Marines Book 1)
The Golden Horde (The Revelations Cycle Book 4)
Peacemaker (The Revelations Cycle Book 6)
Karma Upsilon 4 (Jim Cartwright at Large Book 1)
Valley of Loss (Jim Cartwright at Large Book 2)
Empire of Machines (Jim Cartwright at Large Book 3)
Eye of Minerva (Jim Cartwright at Large Book 4)
The Midnight Sun (The Omega War Book 2)
Rage of Winter (Terran Strike Marines Book 2)
Valdar’s Hammer (Terran Strike Marines Book 3)
Dark Moon Arisen (The Omega War Book 3)
Sinclair’s Scorpions (The Omega War Book 5)
The Beast of Eridu (Terran Strike Marines Book 4)
Til Valhalla: An Ember War Novel
When the Axe Falls (The Omega War Book 7)
Archangel One
Godswar: The Magitech Chronicles Book 7
The Xaros Reckoning (The Ember War Saga Book 9)
Alabaster Noon (The Omega War Book 12)
Armageddon (Expeditionary Force Book 8)
Renegades (Expeditionary Force Book 7)
Storm Clouds (The Guild Wars Book 1)
Hunted (Jim Cartwright at Large Book 5)
Hollow Core (School of Swords and Serpents Book 1)
Gott Mit Uns (Terran Strike Marines Book 5)
Iron Dragoons (Terran Armor Corps Book 1)
The Martian

What it is like to be a Network Engineer as translated into normal person speak.

I don’t remember where I found this, but figured it was an appropriate explanation of my job and what I do.

What it’s like to be a network engineer…translated into normal people speak:

User: I think we are having a major road issue.

Me: What? No, I just checked, the roads are fine. I was actually just on the roads.

User: No, I’m pretty sure the roads are down because I’m not getting pizzas.

Me: Everything else on the roads is fine. What do you mean you aren’t getting pizzas?

User: I used to get pizzas when I ordered them, now I’m not getting them. It has to be a road issue.

Me: As I said, the roads are fine. Where are you getting pizzas from?

User: I’m not really sure. Can you check all places that deliver pizzas?

Me: No I don’t even know all the places that deliver pizza. You need to narrow it down.

User: I think it is Subway.

Me: Okay, I’ll check…No, I just looked and Subway doesn’t deliver pizzas.

User: I’m pretty sure it is Subway. Can you just allow all food from Subway and we can see if pizza shows up?

Me: Sigh, fine I’ve allowed all food from Subway, but I don’t think that is the issue.

User: Yeah I’m still not getting pizza. Can you check the roads?

Me: It’s not the roads, the roads are fine. I’m pretty sure Subway isn’t the place.

User: Okay, I found it. It’s Papa Johns.

Me: Okay, I looked and Papa Johns does deliver pizza. Is it the local Papa Johns or one in a different town?

User: I don’t know. Can you allow pizza from all Papa Johns to me?

Me: No I can’t do that. Can you get me an address for Papa Johns?

User: No, I only know it as Papa Johns. Can you get me all the addresses of all Papa Johns and I’ll tell you if one of them is correct?

Me: No, I don’t have time for that. Okay, I looked at the local one and it looks like they have sent you pizza in the past and they are currently allowed to send you pizzas. Try ordering a pizza while I watch.

User: Yeah still no pizza. I’m guessing they are getting blocked at the freeway. Can you check the freeway to make sure they can get through?

Me: No, this is a local delivery. They aren’t even using the freeway.

User: Okay, well then it has to be a road issue.

Me: No, the roads are fine. Okay, I just drove from the Papa Johns to the address they have on file for you and there is nothing there.

User: Hmm, wait we did move recently.

Me: Did you give your new address to Papa Johns?

User: No, I just thought they would be able to look me up by name.

Me: No they need your new address. What’s your new address?

User: I’m not really sure. Can you look it up?

Me: Sigh, give me a second…Okay, I found your address and gave it to Papa Johns. Try ordering a pizza now.

User: HEY! PIZZA JUST SHOWED UP!

Me: Okay, good.

User: (To everyone else they know) I apologize for the delay in the pizza but there was a major road issue that was preventing the pizza from getting to me. The network engineer has fixed the roads and we are able to get pizza again.

Me: But it wasn’t the roads…whatever.

User: Oh, can you also check on an issue where Chinese food isn’t getting to me? I think it may be a road issue.

pyenv on Mac OS 10.15 Catalina

I have been running pyenv from homebrew on Mac so I could run Python3 rather than 2.7. However when I upgraded to Catalina I ran into an issue that pyenv wasn’t working anymore. When I went through the GitHub page for pyenv at: pyenv and followed all of the steps and got to this part:

  • Add pyenv init to your shell to enable shims and autocompletion. Please make sure eval "$(pyenv init -)" is placed toward the end of the shell configuration file since it manipulates PATH during the initialization.$ echo -e ‘if command -v pyenv 1>/dev/null 2>&1; then\n eval “$(pyenv init -)”\nfi’ >> ~/.bash_profile
    • Zsh note: Modify your ~/.zshenv file instead of ~/.bash_profile.
    • fish note: Use pyenv init - | source instead of eval (pyenv init -).
    • Ubuntu and Fedora note: Modify your ~/.bashrc file instead of ~/.bash_profile.General warning: There are some systems where the BASH_ENV variable is configured to point to .bashrc. On such systems you should almost certainly put the abovementioned line eval "$(pyenv init -)" into .bash_profile, and not into .bashrc. Otherwise you may observe strange behaviour, such as pyenv getting into an infinite loop. See #264 for details.

.zshenv should actually be .zshrc

First Half of Python for Network Engineers

It’s been non stop for 5 weeks of training, but this week we had a week off so I thought I would post this.

I was able to get my work to fund the Python for Network Engineers course taught by Kirk Byers. 

https://pynet.twb-tech.com/class-pyauto.html

I had taken the free class a couple of times and learned quite a bit. I thought that being able to take the paid course would give me a better understanding of things related to python and how to handle some of the more complex things that I want to do. I really want to be able to take advantage of more automation in our environment and make things work better/easier with fewer chances for errors. I also want to empower my Helpdesk to be able to do more things, we are a very small shop with a large footprint of stores/offices. We have deployed Meraki to almost all of the locations so being able to take advantage of python/rest apis has been a great benefit so far. However I feel there is more that I can do, I just need some more training. Also the more stuff I can give to my Helpdesk the less they have to call me for and I can try and get some more sleep(as though that would happen). 

I have really enjoyed the first half of the class and learned quite a bit so far in just using Netmiko, textfsm, and jinja2. The other part that is nice is the community of people that Kirk has put together so that we can all learn off from each other and exchange ideas and questions. Between using Slack and some group channels there has been a lot of good comments/questions exchanged back and forth. 

As for the class Kirk’s videos have been informative and I have found a lot of useful information in them. His examples have been good and have shown some real life information in working with equipment. Not diving into actual network engineering, but showing some information in relation to real life data/examples. I have also found the exercises he has assigned us to be challenging and quite good. I have picked up some good ideas from them and it has pushed my learning and understanding of python.

In all I am really enjoying it and can’t wait for the next half and to see how my python programming improves.

Meraki Script to pull LTE Card Signal

Script for pulling the make and signal strength of wireless cards

We are trying to continually audit our LTE cards in the Meraki Routers so we wanted to be able to monitor the stores LTE connections and see the signal strength and then determine which if any needed to be swapped out. However that data is only stored at the device level so you have to iterate through the whole Organization then by network and then by device in the network. Meraki has a polling limit for how many times you can poll the cloud per second so I put a 1 second delay in there to keep the program from overwhelming everything and causing issues for itself or for our users monitoring on the website.

The script can be found here:

https://github.com/undrwatr/MERAKI_CARD_SIGNAL

How I handle credentials and shared variables in Python

How to handle common variables between programs

I have been writing a lot of python programs lately for interacting with the Meraki Platform. I was tired of copying and pasting my variables and credentials between programs, plus I wanted the ability to easily upload the programs to GitHub without having to worry about sanitizing the program of my companies or personal data. I did some searching and didn’t find a lot so what I figured I would do is put this information into a python module and then I could call that module from within my programs and then I wouldn’t have to worry about keeping all of my data secure. I decided to call my module cred.py and then I could call it from within the program with just a “import cred”. I used to copy this file into each of the directories where I was working on a program. Then I ran into a problem where I had to change an API key, I then had to go through and find all of the cred.py files I had created and then update the data in them. That proved to be more of a pain than I wanted to deal with so I decided to place it in a central directory for all of my programs. This proved much easier, but then I had to figure out how to call it from within Python without making it a module in the install path.

That is where I came up with this:

import sys

#Import the CRED module from a separate directory
sys.path.insert(0,’../CRED’)
import cred

With this it allows me to keep one central directory to store all of my credentials, but also commonly needed variables. I call it from within the program and can then run my programs easily. Love to hear how others are handling this or if there is a better way for me to do it.

Walt Disney World in October

As a family we made our yearly trip to WDW for Food and Wine and to have some fun in the heat and humidity. We as parents like going and our son likes to go and has a good time. At least we think he does and usually he doesn’t dissuade us from that notion. Here are some of the shots I took as we went to Epcot and Animal Kingdom.

Epcot food and Wine and of course character Meet and Greets:

Random shots from around the park.    Continue reading