Permalink
Browse files

Here is a useful shell for debugging or playing around with the library.

  • Loading branch information...
1 parent 4eeb2ef commit 65c249058ec0fcaa59f5a4d6baf65caf684f3345 @sir-pinecone sir-pinecone committed Jun 3, 2010
Showing with 35 additions and 1 deletion.
  1. +35 −0 posterous-shell
  2. +0 −1 posterous/__init__.py
View
35 posterous-shell
@@ -0,0 +1,35 @@
+#!/usr/bin/env python
+
+from getpass import getpass
+from optparse import OptionParser
+import posterous
+
+"""Launch an interactive shell ready for Posterous usage
+
+This script is handy for debugging posterous during development
+or to just play around with the library.
+It imports posterous and creates an authenticated API instance (api)
+using the credentials provided.
+"""
+
+opt = OptionParser(usage='posterous-shell <username> <password>')
+options, args = opt.parse_args()
+
+if len(args) == 1:
+ username, password = args[0], getpass()
+elif len(args) == 2:
+ username, password = args[0], args[1]
+else:
+ username, password = None, None
+
+local_ns = {'posterous': posterous, 'api': posterous.API(username, password)}
+shellbanner = '<Posterous shell>'
+
+try:
+ import IPython
+ ipshell = IPython.Shell.IPShell([''], user_ns = local_ns)
+ ipshell.mainloop(sys_exit=1, banner = shellbanner)
+except ImportError:
+ import code
+ code.interact(shellbanner, local = local_ns)
+
View
1 posterous/__init__.py
@@ -18,7 +18,6 @@
__credits__ = ['Michael Campagnaro <http://github.com/mikecampo>']
from posterous.api import API
-from posterous.models import Site, Post, Tag, Comment, Media, ModelFactory
# unauthenticated instance
api = API()

0 comments on commit 65c2490

Please sign in to comment.