May 23rd, 2009
Python has some good GUI kits for developers looking to make cross platform tools that are fast and rapid to develop. There are some great libraries out there to help you get up to speed very fast.
wxPython
wxPython is a GUI toolkit for the Python programming language. It allows Python programmers to create programs with a robust, highly functional graphical user interface, simply and easily. It is implemented as a Python extension module (native code) that wraps the popular wxWidgets cross platform GUI library, which is written in C++.
Like Python and wxWidgets, wxPython is Open Source which means that it is free for anyone to use and the source code is available for anyone to look at and modify. Or anyone can contribute fixes or enhancements to the project.
wxPython is a cross-platform toolkit. This means that the same program will run on multiple platforms without modification. Currently supported platforms are 32-bit Microsoft Windows, most Unix or unix-like systems, and Macintosh OS X.
pyQT
PyQt is a set of Python bindings for Nokia’s Qt application framework and runs on all platforms supported by Qt including Windows, MacOS/X and Linux. There are two sets of bindings: PyQt v4 supports Qt v4; and the older PyQt v3 supports Qt v3 and earlier. The bindings are implemented as a set of Python modules and contain over 300 classes and over 6,000 functions and methods.
- http://www.riverbankcomputing.co.uk/software/pyqt/download
- Supports lots of great libraries such as:
-
- The QtNetwork module contains classes for writing UDP and TCP clients and servers. It includes classes that implement FTP and HTTP clients and support DNS lookups. Network events are integrated with the event loop making it very easy to develop networked applications.
- The QtOpenGL module contains classes that enable the use of OpenGL in rendering 3D graphics in PyQt applications.
- The QtWebKit module implements a web browser engine based on the WebKit open source browser engine used by Apple’s Safari. It allows the methods and properties of Python objects to be published and appear as JavaScript objects to scripts embedded in HTML pages.
- The QtScript module contains classes that enable PyQt applications to be scripted using Qt’s JavaScript interpreter.
PyGTK: GTK+ for Python
PyGTK lets you to easily create programs with a graphical user interface using the Python programming language. The underlying GTK+ library provides all kind of visual elements and utilities for it and, if needed, you can develop full featured applications for the GNOME Desktop.
PyGTK applications are truly multiplatform and they’re able to run, unmodified, on Linux, Windows, MacOS X and other platforms.
Opinion
My personal opinion is that wxPython is best for many windows developers. PyQt looks great and has many great libraries, Qt itself is a very fast C++ library so using it is beneficial. PyGTK is also great but more common for *nix apps.
Tags: applications, desktop, gui, python, wrappers
Posted in coding, engineering, technology | Comments Off
May 22nd, 2009
You can read from the Windows registry in Python. So for instance you can read the location of an application you want to see if it is installed and then run it by finding the installed location of the EXE in the registry, then calling os.command(reg_key_value) or popen2.popen3(reg_key_value) to run it.
import pickle
import struct
import _winreg
def floater (s):
return struct.unpack ("f", s)[0]
def unpickler (s):
return pickle.loads (s)
root = _winreg.HKEY_CURRENT_USER
key_values = [
(r"Software\PySoft\PyApp", "owner", unicode),
(r"Software\PySoft\PyApp", "settings", list),
(r"Software\PySoft\PyApp", "version", floater),
(r"Software\PySoft\PyApp", "dump", unpickler),
]
for keypath, value_name, factory in key_values:
hKey = _winreg.OpenKey (root, keypath, 0, _winreg.KEY_READ)
value, type = _winreg.QueryValueEx (hKey, value_name)
print "%s:%s" % (keypath, value_name), "=>", factory (value)
Posted in Uncategorized | Comments Off
May 22nd, 2009
You can call the command to launch applications or run commands in Python two ways.
With os.system(my_command)
import os
os.system("c:\\windows\\notepad.exe")
Or with popen2.popen3(my_command)
import popen2
popen2.popen3("c:\\windows\\notepad.exe")
Tags: commands, popen2, python, running, tips
Posted in coding, engineering, technology | Comments Off
May 18th, 2009
pyamf is pretty sweet for Flash remoting with Pythonic server side, but now we have two nicely done and integrated remoting kits for python on the server side.
amfast is a new remoting library that looks to be as sweet as pyamf (where sweet == fast and useful). I am checking out amfast now but the speed boost alone might be worth it. For instance, working with real-time games, when you need static content you need to grab that quickly sometimes via a content service. The faster that link the better. It also has Twisted integration which is great for networking and SQLAlchemy integration which is in my opinion the best ORM for python (pyamf has twisted, django, pylons, sqlalchemy as well)
amfast is well documented and has some great examples. If you have the Python addiction, check it.
Tags: actionscript, amf, as3, flash, gamedev, python
Posted in coding, engineering, syndication, technology, web | Comments Off
March 3rd, 2009
Python is a dynamic language that you can pretty much use for anything. One area that is pretty common is loading up a dynamic class. Let’s say you get back a list of classes and you want to initialize one into an object and use it. You can use the script below to load in a python class from introspection.
classname = "ClassToLookFor"
the_module = __import__("my.module", globals(), locals(), [classname])
the_class = getattr(the_module, classname)
obj = the_class()
More on introspection in Python (sometimes called Reflection in other languages like C# and Java):
Tags: introspection, python
Posted in coding, engineering, technology | Comments Off
February 10th, 2009
We have lots of blogs to manage and keep backed up so we employ Python scripts that are scheduled to run every day and backup the full database sets. Python is a great language because you can use it for web development (WSGI/Django/etc), game development, automation, systems administration, desktop apps and many other things. We will have more python scripts here on how we use it to run things. Keep in mind these are cross platform because we manage applications on all types of environments from Windows, to UNIX/Linux to OSX (same as *nix really).
How to Use
Use this script by scheduling it to run nightly or when you choose. Then make a folder under it called target or change the location in the script.
The file that will export will be a complete sql dump and stamped like the following filename, it contains the zipped up database.sql file that is your backup:
export-2009-02-03-Tuesday.zip
If you need to change settings to get flat files or other read on mysqldump utility to pass the options you need, currently it backs up in SQL format.
The Script
import os, time, sys, zipfile, datetime,calendar
from os import sep
# Script Parameters
# Target Directory for final Zip files
target_dir = r'target'
copy_dir = r'copy'
# The name of the sql file (this will be the same for all backups)
file_name = 'databases.sql'
# Authentication
user = '[YOUR USER]'
password = '[YOUR PASSWORD]'
# The command for the mysql dump. This could include the entire path to the executable if mysqldump is not on the path environment variable
dumpcmd = r'mysqldump'
# The host you want to connect to
host = 'localhost'
args = [dumpcmd, '-C', '-f', '--host=%s' %host, '--user=%s' %user, '--password=%s' %password, '--result-file=%s' %file_name, '--all-databases']
os.chdir(target_dir)
cmd = ' '.join(args)
print 'Running Command: %s' %cmd.replace(password, '*'*len(password))
os.system(cmd)
# Below is for zipping the files and creating a redundant backup
def getZipFileName():
# Set time variables (
# Note: you don't have to use some of them,
# but they make the script easier to understand
t = time.time(); g = time.gmtime(t)
year = g[0]; month = g[1]; day = g[2]
try:
datetime.date(year, month, day+1)
except:
# Last day of the month, return month name
root = time.strftime('%Y', g)
if not os.access(root, os.F_OK):
os.mkdir(root)
return os.path.join(root, '%s.zip' %time.strftime('%b'))
if int(time.strftime('%w', g)) == 0:
# Last day of week, return week number
cal_month = calendar.monthcalendar(year, month)
for week in cal_month:
if day in week:
return 'Week%i.zip' %month.index(week)
# Just a regular weekday...
return '%s.zip' %time.strftime('%A')
# Write the zip file
zip_name = 'export-' + str(datetime.date.today()) + '-' + getZipFileName()
zip_file = os.path.abspath(zip_name)
zip = zipfile.ZipFile(zip_file, 'w', zipfile.ZIP_DEFLATED)
zip.write(file_name)
zip.close()
# Remove uncompressed sql file
os.remove(file_name)
to_path = os.path.join(copy_dir, zip_name)
to_dir = sep.join(to_path.split(sep)[:-1])
if not os.access(to_dir, os.F_OK):
os.makedirs(to_dir)
if os.access(to_path, os.F_OK):
os.remove(to_path)
shutil.copy(zip_file, to_path)
Tags: administration, backup, management, mysql, python, wordpress
Posted in syndication, web | 1 Comment »
January 6th, 2009
- User
- Friends
- Stats
- GamesPlayed
- AppsUsed
- GameStats
- GameAchievements
- Relations
- User
- Groups
- Friends
- Status
- etc.
- Friends
- IsFriends
- IsFriendUsingGame
- IsFriendUsingApp
- Apps
- Stats
- stats for apps
- stat for games
- Feed
- Market
- Apps
- Games
- Status
- CurrentStatus
- PreviousStatus
- Emotion
- Friends
- getFriends
- setFriends ?
- getFriend
- setFriend ?
- Groups
- getGroups
- setGroups ?
- getGroup
- setGroup ?
List of API actions in OpenSocial and Facebook,
You can see they vary, having a common library for social networks and widgets are needed these days as the frameworks grow
OPEN SOCIAL API DOCS: http://code.google.com/apis/opensocial/docs/0.8/reference/
OpenSocial API Reference (v0.8)
The OpenSocial JavaScript API includes two namespaces: opensocial.* and gadgets.*. This page covers the opensocial.* namespace. The gadgets.* namespace is covered in the Gadgets API Reference.
Contents
FACEBOOK WIKI API DOCS – http://wiki.developers.facebook.com/index.php/API
Facebook REST Interface
The API uses a REST-like interface. This means that our Facebook method calls are made over the internet by sending HTTP GET or POST requests to the Facebook API REST server . Nearly any computer language can be used to communicate over HTTP with the REST server.
API Methods
- Admin.getAllocation
- Returns the current allocation limit for your application for the specified integration point.
- Admin.getMetrics
- Returns specified metrics for your application, given a time period.
- Admin.getDailyMetrics
- Returns specified daily metrics for your application, given a date range.
- admin.getAppProperties (BETA)
- Returns values of properties for your applications from the Facebook Developer application.
- admin.setAppProperties (BETA)
- Sets values for properties for your applications in the Facebook Developer application.
- application.getPublicInfo (BETA)
- Returns public information about a given application (not necessarily your own).
- auth.createToken
- Creates an auth_token to be passed in as a parameter to login.php and then to auth.getSession after the user has logged in.
- auth.getSession
- Returns the session key bound to an auth_token, as returned by auth.createToken or in the callback URL.
- auth.promoteSession
- Returns a temporary session secret associated to the current existing session, for use in a client-side component to an application.
- auth.expireSession
- Expires the session indicated in the API call, for your application.
- batch.run (BETA)
- Execute a list of individual API calls in a single batch.
- data.getCookies (BETA)
- Returns all cookies for a given user and application.
- data.setCookie (BETA)
- Sets a cookie for a given user and application.
- events.get
- Returns all visible events according to the filters specified.
- events.getMembers
- Returns membership list data associated with an event.
- fbml.refreshImgSrc
- Fetches and re-caches the image stored at the given URL.
- fbml.refreshRefUrl
- Fetches and re-caches the content stored at the given URL.
- fbml.setRefHandle
- Associates a given “handle” with FBML markup so that the handle can be used within the fb:ref FBML tag.
- feed.publishStoryToUser
- Publishes a News Feed story to the user corresponding to the session_key parameter.
- feed.publishActionOfUser
- Publishes a Mini-Feed story to the user corresponding to the session_key parameter, and publishes News Feed stories to the friends of that user.
- feed.publishTemplatizedAction
- Publishes a Mini-Feed story to the user or Page corresponding to the session_key or page_actor_id parameter.
- fql.query
- Evaluates an FQL (Facebook Query Language) query.
- friends.areFriends
- Returns whether or not each pair of specified users is friends with each other.
- friends.get
- Returns the identifiers for the current user’s Facebook friends.
- friends.getAppUsers
- Returns the identifiers for the current user’s Facebook friends who are signed up for the specific calling application.
- friends.getLists
- Returns the identifiers for the current user’s Facebook friend lists.
- groups.get
- Returns all visible groups according to the filters specified.
- groups.getMembers
- Returns membership list data associated with a group.
- liveMessage.send (BETA)
- Sends a “message” directly to a user’s browser, which can be handled in FBJS.
- marketplace.createListing
- Create or modify a listing in Marketplace.
- marketplace.getCategories
- Returns all the Marketplace categories.
- marketplace.getListings
- Return all Marketplace listings either by listing ID or by user.
- marketplace.getSubCategories
- Returns the Marketplace subcategories for a particular category.
- marketplace.removeListing
- Remove a listing from Marketplace.
- marketplace.search
- Search Marketplace for listings filtering by category, subcategory and a query string.
- notifications.get
- Returns information on outstanding Facebook notifications for current session user.
- notifications.send
- Sends a notification to a set of users.
- notifications.sendRequest
- This method is disabled.
- notifications.sendEmail
- Sends an email to the specified users who have the application.
- pages.getInfo
- Returns all visible pages to the filters specified.
- pages.isAdmin
- Checks whether the logged-in user is the admin for a given Page.
- pages.isAppAdded
- Checks whether the Page has added the application.
- pages.isFan
- Checks whether a user is a fan of a given Page.
- photos.addTag
- Adds a tag with the given information to a photo.
- photos.createAlbum
- Creates and returns a new album owned by the current session user.
- photos.get
- Returns all visible photos according to the filters specified.
- photos.getAlbums
- Returns metadata about all of the photo albums uploaded by the specified user.
- photos.getTags
- Returns the set of user tags on all photos specified.
- photos.upload
- Uploads a photo owned by the current session user and returns the new photo.
- profile.setFBML
- Sets the FBML for a user’s profile, including the content for both the profile box and the profile actions.
- profile.getFBML
- Gets the FBML that is currently set for a user’s profile.
- users.getInfo
- Returns a wide array of user-specific information for each user identifier passed, limited by the view of the current user.
- users.getLoggedInUser
- Gets the user ID (uid) associated with the current session.
- users.hasAppPermission
- Checks whether the user has opted in to an extended application permission.
- users.isAppAdded
- Returns whether the logged-in user has added the calling application.
- users.setStatus
- Updates a user’s Facebook status.
Batching API BETA
Data Store API BETA
Permissions API BETA
Additional documentation
External links
Posted in Uncategorized | Comments Off
June 22nd, 2008
Syndication has many layers built in it these days, but really when you get down to the formats making your own parsers and writers for your syndication formats is quite easy. Good knowledge of the formats and some basic tricks can make your feeds highly customized and tailored by your own work.
Tips for Generating Good Feeds
RSS and Atom are easy to work with, but like any new format, you may encounter some problems in using them. This section attempts to address the most common issues that arise when generating a feed.
- Distinct Entries — Make sure that aggregators can tell your entries apart, by using different identifiers in
rdf:about (RSS 1.0), guid (RSS 2.0) and id (Atom). This will save a lot of headaches down the road.
- Meaningful Metadata — Try to make the metadata useful on its own; for example, if you only include a short
<title>, people may not know what the link is about. By the same token, if you shove an entire article into <description>, it’ll crowd people’s view of the feed, and they’re less likely to stay interested in what you have to say. Generally, you want to put enough into the feed to help someone decide whether they should follow the link.
- Encoding HTML — Although it’s tempting, refrain from including HTML markup (like
<a href="...">, <b> or <p>) in your RSS feed; because you don’t know how it will be presented, doing so can prevent your feed from being displayed correctly. If you need to include a a tag in the text of the feed (e.g., the title of an entry is “Ode to <title>”), make sure you escape ampersands and angle brackets (so that it would be “Ode to <title>”).
- XML Entities — Remember that XML doesn’t predefine entities like HTML does; therefore, you won’t have
© and other common entities available. You can define them in the XML, or alternatively just use an character encoding that makes what you need available.
- Character Encoding — Some software generates feeds using Windows character sets, and sometimes mislabels them. The safest thing to do is to encode your feed as UTF-8 and check it by parsing it with an XML parser.
- Communicating with Viewers — Don’t use entries in your feed to communicate to your users; for example, some feeds have been known to use the
<description> to dictate copyright terms. Use the appropriate element or module.
- Communicating with Machines — Likewise, use the appropriate HTTP status codes if your feed has relocated (usually,
301 Moved Permanently) or is no longer available (410 Gone or 404 Not Found).
- Making your Feed Cache-Friendly — Successful feeds see a fair amount of traffic because clients poll them often to see if they’ve changed. To support the load, Web Caching can help; see the caching tutorial.
- Validate — use the Feed Validator to catch any problems in your feed; it works with RSS and Atom. Also, don’t just run it once; make sure you regularly check your feed, so that you can catch transient errors.
This is an incomplete list of tools for creating feeds and checking them to make sure that you’ve done so correctly. Note that there are many more libraries that help parsing feeds; these haven’t been included here because this tutorial focuses on the Webmaster, not consumers of feeds.
- xpath2rss — Tool for scraping Web sites using XPath expressions (a method of selecting parts of HTML and XML documents).
- Site Summaries in XHTML — Online service (also available as an XSLT stylesheet) that uses hints in your HTML to generate a feed.
- myRSS — An online, third-party automated scraping service. Doesn’t require any special markup.
- RSS.py — Python library for generating and parsing RSS.
- ROME — Java library for parsing and generating RSS and Atom feeds, as well as translating between formats.
- XML::RSS — Perl module for generating and parsing RSS.
- Online Validator – Check your RSS 1.0, 2.0 and Atom feeds.
[source]
Tags: atom, business, content, marketing, rest, rss, service, syndication
Posted in marketing, syndication, web | Comments Off
June 22nd, 2008
Retro posters are just so cool. Check out these Retro posters for Wall-E.
Guess Which Movie has this story up but it is so cool I added it to the drawcode web conscious stream.
Eric Tan, who has done retro poster art for Pixar in the past with THE INCREDIBLES and RATATOUILLE, has finished up work on his new posters for WALL-E. Be sure to visit Eric’s blog where you can check out more of his work, including his retro poster for INDIANA JONES AND THE TEMPLE OF DOOM.






Tags: advertising, cool, marketing, movie, pixar, poster, retro, wall-e
Posted in entertainment, marketing, web | 1,750 Comments »
April 18th, 2008
… on this site .. check back
Posted in Uncategorized | 1,382 Comments »