Site Sponsors:
Passable 'RFC 2822' Localtime in Python 3 
Time ... you would think that it would be easy to express on a computer... What could be more natural than counting the number of seconds?

Yet after decades of computerization, we are still 'haggling over the proper way to express time!

Here is what we cobbled together while creating a client-side API for the new, R&D, AboutTime HTML Server:

import datetime
from email import utils

zdt = # Omits the GMT Offset
zlocal = utils.localtime(zdt) # Adds the official GMT Offset
localtime = utils.format_datetime(zlocal) # RFC 2822-ish

... and here is the output:

/usr/bin/python3.5 .../Python3/AboutTime_API/
2017-12-13 08:02:20.817119
2017-12-13 08:02:20.817119-05:00
Wed, 13 Dec 2017 08:02:20 -0500

Then, as one becomes interested in Zulu / Server Time:

zdt = datetime.datetime.utcnow() # Omits the GMT Offset
zulutime = utils.format_datetime(zdt) # RFC 2822-ish


2017-12-13 13:02:20.817251
Wed, 13 Dec 2017 13:02:20 -0000

For those who would like to use an enumerated set of timezones:
from datetime import timezone
znow =

We can also:
utc_date = znow.strftime(format='%Y-%m-%d %H:%M:%S [%z]')

Sharing is caring!


Google candy: GMT, UTC, Epoch time, conversion, email, RFC 822

[ view entry ] ( 735 views )   |  permalink  |  related link
Collecting Wikiquote Data Using Python 
You've 'gotta love collecting quotes - not only might they teach us, but reviewing quotations revered by others helps us better understand what motivates today's majorities.

Like many others, I also love Python 3. Not only is Python 3 finally ready for prime-time, but - from gainful employment to games - Python's community is simply the most amazing set of programing enthusiasts in our modern world. -If you want to do something, chances are extremely good that someone has a package that can help you do things ALLOT quicker.

So it was with collecting Wikiquotes!

Quotes Matter

I have been collecting quotes since my college days. Indeed, from then to prior to to-date I have amassed a collection of around 100,000.

When it came time to snoop around Wikiquote therefore, how could any 'quotie worthy of the moniker NOT try to collect 'em all, as well?

So as I sat down to "learn something" on this traditional occidental day of rest, I decided to give the wikiquotes package a try.

After pip'ing it down, here is what I came up with:

import wikiquotes

alpha = "abcdefghijklmnopqrstuvwxyz1234567890"
major = 1
minor = 1
with open("./wikiquote_2017_10_22.txt", "w") as results:
for char in alpha:
result =, "english")
zlist = list(result)
for author in zlist:
print(char, major, author)
quotes = wikiquotes.get_quotes(author, "english")
for quote in quotes:
if str(quote).find("proposed by") == 0:
if str(quote).find("(UTC)") != -1:
print("tbd", char, minor, major, author, quote, sep='|', file=results)
minor += 1
major += 1
print("error", char, minor, major, "error", "no quotes", sep='|', file=results)

Using the above, we were able to download 17,068 things to review. The fact that we have an even set of 360 'authors' (10 per) clearly indicates that I did not get 'em all the first time 'round... but I eventually got the vast majority [5,225 topics? 153,621 quotes?] of them... (*)

Quality Comments

Overall, I should note that I was disappointed with the quality of the quotations. While there were some decent citations that I did not have, allot of the jibes seem to be far too fatuous; desperate attempts to garner cheap publicity for far too many unmemorable nouns. More than a few pages have absolutely no quotations on them at-all.

Yet - as mentioned previously - as we 'quoties seek to separate the gold from the gall, over time history has an annoying tendency to insure that only the strong, will survive.

Enjoy the journey!


p.s. If you would like to get the results of today's diversion, we just uploaded them to the Mighty Maxims Project.

(*) In order to keep the server load reasonable for our Wikipedia friends, I will keep THAT bit of code on my own 'local ... still sorting thru them! :)

[ view entry ] ( 763 views )   |  permalink  |  related link
Python - Color Console with Cursor Support 
For those who would like to create an enhanced menu system ... or perhaps your first console game ... here is a re-write for what I posted this morning:

class Cursor:

def goto(xpos, ypos):
if xpos < 1:
xpos = 1
if ypos < 1:
ypos = 1
print(u'\u001b[{};{}H'.format(ypos, xpos), end='')

def on():
print(u'\u001b[?25h', end='')

def off():
print(u'\u001b[?25l', end='')

class Console:
color = {
'black': 30,
'red': 31,
'green': 32,
'yellow': 33,
'blue': 34,
'magenta': 35,
'cyan': 36,
'white': 37,
# 'extended': 38,
'default': 39

scheme = {
"fore":0, # FOREGROUND
"back":10, # BACKGROUND
"bfore":60, # BRIGHT FORE
"bback": 70 # BRIGHT BACK

def _esc(zint, zmode):
print(u"\u001b[{}{}".format(zint, zmode), end='')

def cls():
Console._esc('1', 'J')
for line in range(100):

def get_colors():
return sorted(Console.color.keys())

def get_schemes():
return sorted(Console.scheme.keys())

def set_color(color, scheme='fore'):
if scheme in Console.scheme:
if color in Console.color:
Console._esc(Console.color[color] + Console.scheme[scheme], 'm')
Console._esc(Console.color['default'], 'm')

def set_colors(fore, back, cfore='fore', cback='back'):
if fore in Console.color and back in Console.color:
if cfore in Console.scheme and cback in Console.scheme:
Console._esc(Console.color[fore] + Console.scheme[cfore], 'm')
Console._esc(Console.color[back] + Console.scheme[cback], 'm')

def has_color():
import os
if is 'posix':
return True
if is 'nt':
import platform
ver = platform.version()
if ver is None or len(ver) is 0:
return False
ver = ver.split('.')
if ver[0] == '10':
return True
return False

if __name__ == "__main__":
if Console.has_color() is False:
print("Sorry, at the moment only POSIX has default VT100 / ANSI support.")
print("Some version of Windows use ANSY.SYS / VT100.sys. 'Google it.")

print("1.) Cursor Test")
Console.set_colors('yellow', 'blue')
y = 0
for x in range(1, 20, 2):
y += 2
Cursor.goto(x, y)
print("(", x, y, ")", end='')

input("Press enter for next test ...")

Console.set_colors('blue', 'white')
print("2.) Color Test")
input("Press enter for test ...")
print(Console.set_color("color"), "unknown?")

for color in Console.get_colors():
Console.set_color(color); print(color, end="...")
Console.set_color(color, 'bfore'); print("bright fore", color, end="...")
Console.set_color(color, 'bback'); print("bright back", color, end="...")
Console.set_color('default', 'back')


Console.set_color("green", 'bback')
print("(5,5)", end='')
print("*** TESTING SUCCESS ***")

Unfortunately, the price of adding cursor management pretty much prohibits test case review (above) under any (?) modern IDE.

Be prepared to use bash on Windows (cygwin) or on POSIX.

--Sharing is caring!


p.s. If you are looking for a reasonable, POSIX way to get mouse movements, function keys, and other device events, then check out the low-level information at --Most can be made to work on WinDOS under Cygwin, as well!

Google Keywords: Free Source Code Public Domain Roguelike Console Terminal TTY DOS Prompt

[ view entry ] ( 791 views )   |  permalink  |  related link

<<First <Back | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Next> Last>>