MongoDB and Python: A Simple Example

This seems to be a very popular blog post on this blog. Here it is again for those who want to play around with Python and MongoDB.

Bruce Elgort

The code below demonstrates how to use Python to connect to a MongoDB database. I chose to use a cloud based instance of MongoDB provided free of charge by MongoLab.com. The script demonstrates how to:

  • Use the PyMongo library to connect to a Mongo database
  • Insert documents into a collection
  • Display all of the documents from the collection

I also used a local instance of MongoDB for testing. You will will need to use a Python package manager such as EasyInstall to install the PyMongo library.

Here is the Python code:

If you have any questions please let me know.

View original post

Your Email Says Absolutely Nothing

Here’s the sound a blind person hears when their screen reader reads your email aloud that only contains a graphical image announcing an event:

“Image, Event announcement”

Pro Tip: Don’t send email messages that have all the content in your super cool Photoshop/MSPaint graphic.

The Creative World’s Bullshit Industrial Complex

They are what philosopher Harry Frankfurt would call “bullshitters.” Those that are giving advice for the sake of giving advice, without any regard as to how it is actually implemented, if it can even be implemented at all. “It’s not important to [the bullshitter] what the world really is like,” he says in a short video documentary about the phenomenon (below). “What is important is how he’d like to represent himself.”

This Bullshit Industrial Complex has always existed. But thanks to the precarious economics and job prospects of the creative person, it is often in a creative’s financial interest to climb the bullshit pyramid. In the short term, it’s creating a class of (often young) creatives deluded into thinking they are doing something meaningful by sharing “advice.” Long term, it’s robbing us of a creative talent.

Read the entire story on 99U >

Using IBM Watson Language Translation Services with Python

Here is a very simple example using Python of calling the IBM Watson Language Translation Service. Feel free to use and modify the code as needed. You will need an IBM Bluemix account in order to use the translation service.

# CTEC 121 Intro to Programming and Problem Solving
# Bruce Elgort / Clark College
# Using IBM Watson's Language Translator
# February 27, 2016
# Revised: May 24, 2016
# Version 1.1

import requests

def cls():
    print("\n" * 5)

def translate_text(text,source,target):
    username = 'your username'
    password = 'your password'
    watsonUrl = 'https://gateway.watsonplatform.net/language-translation/api/v2/translate?source=' + source + '&target=' + target + '&text=' + text
    try:
        r = requests.get(watsonUrl,auth=(username,password))
        #print(r)
        return r.text
    except:
        return False

def welcome():
    message = "Welcome to the IBM Watson Translator\n"
    print(message + "-" * len(message) + "\n")
    print("Have fun!\n")

def main():
    cls()
    welcome()

    data = input("Enter some text to be translated:\n")

    print()
    print("What language should I translate it to?")
    print("1) Spanish")
    print("2) Arabic")
    print("3) French")
    print("4) Portuguese")
    print()
    target = input("Select a language from the list above: ")

    if target == "1":
        target = 'es'
    elif target == "2":
        target = 'ar'
    elif target == "3":
        target = 'fr'
    elif target == "4":
        target = 'pt'

    results = translate_text(data,'en',target)
    print()
    print("Here is the text translated for you:")
    print(results)

main()