Site Sponsors:
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:
try:
result = wikiquotes.search(char, "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:
continue
if str(quote).find("(UTC)") != -1:
continue
print("tbd", char, minor, major, author, quote, sep='|', file=results)
minor += 1
major += 1
except:
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!

--Randall

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! :)

[ add comment ] ( 52 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:

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

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

@staticmethod
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
}

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

@staticmethod
def cls():
Console._esc('1', 'J')
for line in range(100):
print()
Cursor.goto(1,1)

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

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

@staticmethod
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')
return
Console._esc(Console.color['default'], 'm')

@staticmethod
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')

@staticmethod
def has_color():
import os
if os.name is 'posix':
return True
if os.name 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.")
exit(-1)

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

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

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

Cursor.goto(1,10)
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('default')
Console.set_color(color, 'bback'); print("bright back", color, end="...")
Console.set_color('default', 'back')
print()

print()

Cursor.goto(5,5)
Console.set_color("yellow")
Console.set_color("green", 'bback')
print("(5,5)", end='')
print()
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!


-Randall


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 kernel.org. --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

[ add comment ] ( 84 views )   |  permalink  |  related link
Python: Colorized Textual User Interfaces on Windows and POSIX 
With the advent of Windows 10, for the first time in history we could do - installed by default - what everyone else had been doing for over 50 years: Create colorized applications right-out of the box!

(PyCharm IDE)


While the use of drivers such as `ANSI.SYS` or `VT100.SYS` had come and gone over the decades, those of us who wanted to create cool looking Textual User Interfaces (TUIs) were encouraged by the fact that we could finally use simple "ESCAPE SEQUENCES" once again!



And then - in the infinite "wisdom" of corporate-think, the zombies disabled it... once again! (sigh)

Oh well: Different millennium... same 'ol Microsoft! (lol)

Cygwin


Yet we should understand that STANDARD terminal support STILL works fine on Microsoft Windows when using things like Cygwin:



Standards


So - as ever - in the STANDARDS BASED world creating cool TUIs remains precisely as it has ever been on Linux, OS X, and everywhere else:



Hence, for those who like to use PREDICTABLE operating systems ;) here is the code I created today:


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

@staticmethod
def _esc(zint, zmode):
return u"\u001b[{}{}".format(zint, zmode)

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

@staticmethod
def get_color(key):
if key in Console.color:
return Console._esc(Console.color[key], 'm')
return Console._esc(Console.color['default'], 'm')

@staticmethod
def get_color_back(key):
if key in Console.color:
return Console._esc(Console.color[key] + 10, 'm')
return Console._esc(Console.color['default'] + 10, 'm')


@staticmethod
def get_color_back_bright(key):
if key in Console.color:
return Console._esc(Console.color[key] + 70, 'm')
return Console._esc(Console.color['default'] + 70, 'm')


@staticmethod
def get_color_bright(key):
if key in Console.color:
return Console._esc(Console.color[key] + 60, 'm')
return Console._esc(Console.color['default'] + 60, 'm')

@staticmethod
def has_color():
import os
if os.name is 'posix':
return True
if os.name 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 Console.has_color() is False:
print("Sorry, at the moment only POSIX has default VT100 / ANSI support.")
print("Some versions of DOS use ANSY.SYS / VT100.sys. 'Google it.")
exit(-1)

for color in Console.get_colors():
print(Console.get_color(color), color, end="...")
print(Console.get_color_bright(color), "bright", color, end="...")
print(Console.get_color('default'), end="")
print(Console.get_color_back_bright(color), "back", color, end="...")
print(Console.get_color_back('default'))



Please note that most people will have to update the above to return 'False' when the OS is 'nt.' But if you are lucky enough to be running the Bourne-Again Shell (bash) under Windows, then you've hit a home-run ... omit the platform checking, all together?

etc ...


For what its worth:




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



[ add comment ] ( 91 views )   |  permalink  |  related link

| 1 | 2 | 3 | 4 | 5 | 6 | Next> Last>>