Skip to content

Commit

Permalink
updated for 0.4
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.mike.verdone.ca/pyprojects/twitter/trunk@174 d723f978-dc38-0410-87ed-da353333cdcc
  • Loading branch information
mverdone committed Oct 1, 2008
1 parent 7f6c5ae commit 21e3bd2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
7 changes: 4 additions & 3 deletions setup.py
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages
import sys, os

version = '0.3.1'
version = '0.4'

setup(name='twitter',
version=version,
Expand All @@ -17,7 +17,7 @@
""",
# Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers=[
"Development Status :: 4 - Beta",
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: End Users/Desktop",
"Natural Language :: English",
Expand All @@ -26,12 +26,13 @@
"Topic :: Communications :: Chat :: Internet Relay Chat",
"Topic :: Internet :: WWW/HTTP :: Dynamic Content :: CGI Tools/Libraries",
"Topic :: Utilities",
"License :: OSI Approved :: MIT License",
],
keywords='twitter, IRC, command-line tools, web 2.0',
author='Mike Verdone',
author_email='mike.verdone+twitterapi@gmail.com',
url='http://mike.verdone.ca/twitter/',
license='',
license='MIT License',
packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
include_package_data=True,
zip_safe=True,
Expand Down
8 changes: 7 additions & 1 deletion twitter/api.py
Expand Up @@ -7,6 +7,10 @@
from exceptions import Exception

class TwitterError(Exception):
"""
Exception thrown by the Twitter object when there is an
error interacting with twitter.com.
"""
pass

class TwitterCall(object):
Expand All @@ -24,7 +28,9 @@ def __getattr__(self, k):
self.uri + "/" + k)
def __call__(self, **kwargs):
method = "GET"
if self.uri.endswith('new') or self.uri.endswith('update'):
if (self.uri.endswith('new')
or self.uri.endswith('update')
or self.uri.endswith('create')):
method = "POST"
argStr = ""
if kwargs:
Expand Down
33 changes: 31 additions & 2 deletions twitter/cmdline.py
Expand Up @@ -17,19 +17,31 @@
in a while (default: every 5 minutes)
-R --refresh-rate <rate> set the refresh rate (in seconds)
-f --format <format> specify the output format for status updates
-c --config <filename> read username and password from given config
file (default ~/.twitter)
FORMATS for the --format option
default one line per status
verbose multiple lines per status, more verbose status info
urls nothing but URLs. Dare you click them?
CONFIG FILES
The config file should contain your email and password like so:
[twitter]
email: <username>
password: <password>
"""

import sys
import time
from getopt import getopt
from getpass import getpass
import re
import os.path
from ConfigParser import SafeConfigParser

from api import Twitter, TwitterError

Expand All @@ -40,13 +52,14 @@
'refresh': False,
'refresh_rate': 600,
'format': 'default',
'config_filename': os.environ.get('HOME', '') + os.sep + '.twitter',
'extra_args': []
}

def parse_args(args, options):
long_opts = ['email', 'password', 'help', 'format', 'refresh',
'refresh-rate']
short_opts = "e:p:f:h?rR:"
'refresh-rate', 'config']
short_opts = "e:p:f:h?rR:c:"
opts, extra_args = getopt(args, short_opts, long_opts)

for opt, arg in opts:
Expand All @@ -63,6 +76,8 @@ def parse_args(args, options):
elif opt in ('-?', '-h', '--help'):
print __doc__
sys.exit(0)
elif opt in ('-c', '--config'):
options['config_filename'] = arg

if extra_args:
options['action'] = extra_args[0]
Expand Down Expand Up @@ -139,12 +154,26 @@ def __call__(self, twitter, options):
'set': SetStatusAction,
}

def loadConfig(filename):
email = None
password = None
if os.path.exists(filename):
cp = SafeConfigParser()
cp.read([filename])
email = cp.get('twitter', 'email', None)
password = cp.get('twitter', 'password', None)
return email, password

def main():
return main_with_args(sys.argv[1:])

def main_with_args(args):
parse_args(args, options)

email, password = loadConfig(options['config_filename'])
if not options['email']: options['email'] = email
if not options['password']: options['password'] = password

if options['refresh'] and options['action'] == 'set':
print >> sys.stderr, "You can't repeatedly set your status, silly"
print >> sys.stderr, "Use 'twitter -h' for help."
Expand Down

0 comments on commit 21e3bd2

Please sign in to comment.