Compute working days

2009-03-14 Thread Gonsolo

I found no solution on the net so I am posting my solution here.
It can be called with "python cwd 1-1-2009 14-3-2009"

from dateutil.rrule import *
from dateutil.parser import *
from datetime import *
from sys import *

start = parse( argv[1] )
#end = datetime.now()
end = parse( argv[2] )
workdays = ( MO, TU, WE, TH, FR )

r = rrule(DAILY, byweekday=workdays, dtstart = start, until = end)
print len( list( r ) )


g
--
http://mail.python.org/mailman/listinfo/python-list


H-Index with Google Scholar

2009-02-25 Thread Gonsolo
I wrote a small script to compute the H-Index of an author.
It is modeled after activestate's google search:
http://code.activestate.com/recipes/523047/

Example use:
hindex i daubechies
Result:
49

The script:

#!/usr/bin/python

import httplib, urllib, re, sys
from BeautifulSoup import BeautifulSoup

terms = sys.argv[1:]
limit = 100
params = urllib.urlencode( { 'q': "+".join( terms ), 'num': limit } )
headers = {'User-Agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows
NT)'}
url = '/scholar'+"?"+params
conn = httplib.HTTPConnection( 'scholar.google.com' )
conn.request( "GET", url, {}, headers )

resp = conn.getresponse()
cites = []
if resp.status == 200:
html = resp.read()
html = html.decode( 'ascii', 'ignore' )
soup = BeautifulSoup( html )
for record in soup( 'p', { 'class': 'g' } ):
match = re.search("Cited by ([^<]*)", str(record))
if match != None:
cite = int( match.group( 1 ) )
cites.append( cite )
else:
print 'Error: '
print resp.status, resp.reason

cites.sort()
cites.reverse()

h = 0
for cite in cites:
if cite > h:
h += 1
print h
--
http://mail.python.org/mailman/listinfo/python-list