python-snippets/examples.py

57 lines
2.0 KiB
Python

import array
from pseudodb import pseudodb
from utils.file_utils import search_path
from utils.str_utils import obscure, unobscure, get_random_string, get_dash_suffix
from utils.misc_utils import immutable_to_list
if __name__ == '__main__':
db = pseudodb.PseudoDB('pseudodb.default.data')
data_collections = db.get_collections()
print("Collections in Pseudodb: "+str(data_collections))
for collection, coltype in data_collections:
if coltype is dict:
print("Processing Dictionary: "+collection)
for key in db.get_keys(collection):
print("\t"+key+": "+str(db.get_values(collection, key)))
elif coltype is list:
print("Processing List: "+collection)
print([str(item) for item in db.get_values(collection)])
elif coltype is array.array:
print("Processing Array: "+collection)
print([str(item) for item in db.get_values(collection)])
elif coltype is tuple:
print("Processing Tuple: "+collection)
print([str(item) for item in db.get_values(collection)])
else: # just assume it's a string
print(str(db.get_values(collection)))
print("\n\n")
immutable_list = ('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine')
print("Immutable: "+str(immutable_list))
shuffled_list = immutable_to_list(immutable_list, scramble=True)
print("Shuffled Mutable: "+str(shuffled_list))
print("\n\n")
files = search_path("./utils", "misc")
print("Search Results: "+str(files))
print("\n\n")
rando_string = get_random_string(30, caps=True, numbers=True, specials=True)
print("Random: "+rando_string)
obscured = obscure(rando_string)
print("Obscured: "+str(obscured))
unobscured = unobscure(obscured)
print("Unobscured: "+unobscured)
dash_suffix = get_dash_suffix("example-silly-string-with-dashes-"+get_random_string(10))
print("Suffix found: "+dash_suffix)