2to3, Python 2 to Python 3 made easy!

Do I need to upgrade from Python 2 to Python 3?

I started to develop my ADS-B tracker software in Python 2 and I delayed the upgrade to Python 3 for a long time. I was thinking it would be pretty difficult! Now that PIP is soon to drop support of Python 2.7, I finally got to it. It was much easier than I expected thanks to 2to3!

The magic of 2to3

You don’t really need to know much about Python 3 to do the upgrade! Just copy all your files in a new Python 3 directory, make sure you have installed all the Python 3 packages you need and use 2to3 and it is done!

cp project_master project_master_py3
cd project_master_py3
sudo apt-get install python3 python3-pip <<your Python 3 packages>>
python3 -m pip install <<your packages>>
2to3 -w *.py

It should almost work…

A little bit of tuning is needed

You may still have some errors due to 2 things:
– Python 3 does not like when mixing space and tab for indentation. It is quite easy to solve by being consistant. Use only spaces or only tabs, whatever is best for you (I don’t have a religion there!).
– Python 3 has a different way to manage strings and bytes. That one is trickier. I solved it by adding 2 functions to change the variable to bytes or to string when needed:

#fn to_bytes
def to_bytes(arg):
if hasattr(arg, 'encode'): return arg.encode('utf-8')
if hasattr(arg, 'decode'): return arg
return repr(arg).encode('utf-8')

#fn to_string
def to_string(arg):
if hasattr(arg, 'encode'): return arg
if hasattr(arg, 'decode'): return arg.decode('utf-8')
return repr(arg).decode('utf-8')

I just ran my program until it detected all the instances where bytes and strings were mixed.

That’s it, it did the job. My trackers are now running Python 3, and still connect to my online database, tweet when detect new or interesting planes, connect through SigFox when off grid,… as they were doing in Python 2. I didn’t notice an impact on the error rate so far.

A DC-3 landing in Hong Kong

Another interesting catch by my ADS-B trackers in Hong Kong has been a Douglas DC-3 with tail number N41CQ on December 4th, 2019. This rare aircraft made a special trip from Hong Kong to Beijing via Guangzhou and Shanghai, to celebrate the 70th anniversary of the CNAC (China National Aviation Corporation) initial flight.

DC-3 details
Hex codeA4D208
Tail NumberN41CQ
TypeDouglas DC-3

12 free tools for website optimization

After developing my ADS-B trackers and the central database of aircraft, I wanted to share the results to the world. What’s best than having my own website for this? Over the years, I discovered these 12 tools to test and optimise my website. There are few directions which are important for website optimization: make sure your website is known by the main search engines, make sure your SEO meta data is right, make sure your website load fast enough and solve all your technical issues.

Website Optimization for SEO

Browseo
Browseo is a great free tool to make all the SEO data visible. It will show the title, meta tags, and other invisible data that are key for SEO just to make sure you got them right. At first, I didn’t see what it was useful for, because I was just checking my main index page, but when I used it to test my php pages, with dynamic meta tags, that was super useful to see what’s wrong with those tags!


Seositecheckup
Seositecheckup is a great free tool to analyse all the SEO data of your website and highlight what is missing. The free version can only scan your website once a day, but that let’s you some time to solve all the issues before checking them again.


Brokenlinkcheck
Broken links are impacting your SEO ranking, but are hard to find. Brokenlinkcheck will find them for you. Free for 2000 links. If you are using WordPress there are some dedicated plugins for this.

Make sure you are known to main search engines

Bing, Google, Yandex are the one to start with. Create an account, give them your URL and they will start to crawl your website. Check the result of those crawls regularly as they will report errors. Browseo (see above) is a great tool to understand canonical url issues. Regarding sitemaps, there are 2 philosophy: let them discover your site by themselves or use a very detailed one. I went with the first one and only put the main pages in my sitemap.

Website Optimisation for Speed

gtmetrix and Google Pagespeed Insight are two great free tools to understand what is making your website slow to load. Solving the issues requires some technical knowledge, but some tricks are very useful: optimise your images and videos, use a CDN, use Gzip compression and optimize PHP code.

Solve technical issues

Dnschecker
Have you recently switched web host or started a new website, then you are in the right place! DNS Checker provides free DNS lookup service for checking domain name server records against a randomly selected list of DNS servers in different corners of the world. Do a quick DNS propagation lookup for any domain name and check DNS data collected from all location for confirming that the website is completely propagated or not worldwide.


Immuniweb
Website security testing (GDPR compliance, CSH and HTTP headers check, common Javascript libraries version check…). Make sure you have all the security basics right!


Onlineconverter
A free tool to convert any image into the format you need for your website.


DownNotifier
A free tool to check if your website is offline.

Have fun!