Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

Multiprocessing in Python

While researching some information about threads and processes in Python, I came across with this great post about Multiprocessing in Python.

./M6

Facial Recognition with Python

While researching for image recognition I came across some very interesting articles about how to perform facial recognition in Python:

./M6

How to perform basic image recognition with the use of Python


While searching for information about image recognition with Python, I've came across with this tutorial, with video explanation.


./M6

Machine Learning with Python

While researching for image recognition in Python, I came across with TensorFlow, they have a tutorial and documented API.
If you'r looking for a fast and simple kick start, check the TensorFlow Image Recognition Python API Tutorial.
If you'r looking for a bit more detail kick start, check Image Recognition with 10 lines of code.
If you'r specifically looking for image recognition, check this.

You can find the TenserFlow framework here and their models here.

./M6

Debug Email in Web Applications

Email debugging may be painless.

This simple technique shows how one can do it in a very simple way.
It aims at Django applications, but the first technique is actually a generic one that anyone can use if Python is installed in the development machine: Debugging email on Django application development

./M6

Setting Up Django Applicatications in Production

Setting up a Django application in a production environment is not as straight forward as one usually is used to. Currently, there are two ways to deploy a Django application:
  1. Deploying on our own server, using WSGI.
  2. Deploying on a shared hosting environment, using FastCGI, SCGI, or AJP.
Django’s primary deployment platform is WSGI, the Python standard for web servers and applications, which requires Apache and mod_wsgi.

But when it comes to deploy, Django official documentation seems superseded by the Linode Library Deploy Python/Django Applications with Apache and mod_wsgi tutorials, an easy to follow step-by-step tutorial, available for several distros.

./M6

Painless Django Kickoff

I'm learning Django and, so far, I'm enjoying it.
But putting it to work, as a simple development environment on my laptop, was harder than I expected. Specially when it came to install the MySQL-Python connector.

If you'r looking for a great step-by-step tutorial, I recommend Starting a Django 1.6 Project the Right Way.

If you're starting with Django, or are having trouble setting Python with MySQL, maybe this will help: Painless Django with MySQL Install.

./M6

Automatic FTP

I currently need to upload of some text files via FTP, but since some files are big, over 5Gb, I get a lot timeouts, which stops me from using the FTP mput command.
So, I've developed a small Python script to automate this task and avoid the timeouts.
It has the following features:
  • can be scheduled;
  • accepts file masks;
  • assumes a default local directory where the files to be uploaded are located;
  • supports text files only;
  • opens the connection for each file transfer in order to avoid timeout problems;
Here it is:

# -*- coding: iso-8859-15 -*-
'''
Automatic FTP
'''

import sys
import string
import ftplib
import os
import glob
import datetime

# Server name or IP address
__SERVER = "server.com"
# FTP username
__USER = "username"
# FTP password
__PASSWORD = "password"
# Default local directory were files are located to be uploaded
__DEFAULT_LOCATION = "C:\\ftp\\upload"

#
# Shows the time difference.
#
def showTimeDifference(init):
td = datetime.datetime.now()-init
print "in",td.seconds,"seconds (",td.seconds/60," minutes )."

#
# Transfers the files
#
def transferFile(ftpFile):
ftpInit = datetime.datetime.now()
file = os.path.basename(ftpFile)

print "\tTransfering:",file,

ftp = ftplib.FTP(__SERVER)
ftp.login(__USER, __PASSWORD)

ftp.storlines("STOR " + str(file).upper(), open(ftpFile))

ftp.close()

showTimeDifference(ftpInit)

print ""

#
# Get the files to transfer
#
def getTransferFiles(location, mask):
result = []
for file in glob.glob1(location, mask):
result.append(os.path.join(location, file))

return result

#
# Main
#
def main(args):
fileMask = ""
fileLocation = __DEFAULT_LOCATION
if len(args) == 2:
fileMask = sys.argv[1]
elif len(args) == 3:
fileMask = args[1]
fileLocation = args[2]
else:
print "autoFTP filemask [location]"
sys.exit(0)

print "Transfer files from",fileLocation,"to", __SERVER,"..."
ftpInit = datetime.datetime.now()
for file in getTransferFiles(fileLocation, fileMask):
transferFile(file)

print "Transfer competed",
showTimeDifference(ftpInit)

#
# Main
#
main(sys.argv)

After setting things up for one's needs, it's quite easy to use.
To transfer all .txt files starting with "A" from the default local directory, just:
python autoFTP A*.txt

To transfer all .xml files from a specific directory "Z:\test", just:
python autoFTP *.xml Z:\test


If one needs to adapt this to either get file, i.e. download, or to support binary file, just check the Python ftplib documentation, it's quite easy.

./M6

Java by API examples

I was seeking information for the FilteredTree Jface object and I've found a great knowledge repository for Java, SWT, JFace EJB, and other technologies, like C#, C++, Python, SQL Server, and many more.

In the Java By API examples, everything is by example and it's hierarchically organized, which helps a lot when one's exploring Java packages, for instance.

You can take a look at it in http://www.java2s.com/.

./M6