#author: korakot, http://www.bigbold.com/snippets/user/korakot/13
#Python for series 60 enables many fun bluetooth stuff.
from socket import *
a = '00:10:60:ab:25:6f'
bt_obex_discover(a) # found at port 3
f = u'C:\\Nokia\\Startermonlog.txt'
bt_obex_send_file(a, 3, f)
13 Ağustos 2007 Pazartesi
Sending file via bluetooth
Efficiently process big xml files with cElementTree
#ElementTree is becoming python's standard XML framework.
#It also supports processing data as it coming/loading.
import cElementTree
for event, elem in cElementTree.iterparse(file):
if elem.tag == "record":
# ... process record element ...
elem.clear()
Get link popularity on delicious
#author: dfdeshom , http://www.bigbold.com/snippets/user/dfdeshom/14
#We are using python's delicious-py module
def get_popular_count(user="user"):
import delicious
notapi = delicious.DeliciousNOTAPI()
#Get user's posts
user_posts = notapi.get_posts_by_user(user)
data = '#tagID popularity\n'
#For each url, get how popular it is
for i in range(len(user_posts)):
data += str(i)+" "+str(len(notapi.get_posts_by_url(user_posts[i]["url"])))+'\n'
str1 = user + "-data" #file name
data_file = file(str1,'w')
data_file.write(data)
data_file.close()
The resulting file will look like this:
$ less jemisa-data
#tagID popularity
0 6
1 744
2 928
3 120
4 1934
5 111
6 425
7 16
8 19
9 2
10 44
11 308
12 12
13 1
14 1
15 7
16 3
17 46
18 7
19 139
20 318
21 174
22 288
23 3
24 1
25 33
26 3
27 154
Get recent tags used by any user on delicious
author: dfdeshom
>>>import delicious
>>> delicious.get_userposts('dfdeshom').tags[1:]
[u'gnuplot', u'math math/culture', u'python', u'music', u'creativity', u'python', u'academia/culture advice gradschool', u'academia/culture advice gradschool', u'wordpress', u'python unicode', u'advice creativity', u'delicious', u'creativity', u'code programming tags', u'delicious', u'math/culture', u'wordpress', u'linux', u'wordpress', u'python', u'python', u'python', u'python', u'computer-algebra math number-theory python', u'php', u'haiti', u'delicious', u'haiti', u'delicious', u'creativity']
>>>
10 Ağustos 2007 Cuma
Opens pydoc in your browser
#!/bin/bash
PYDOC=`which pydoc`
if [ ! -x ${PYDOC} ]
then
echo "could not find executable pydoc (tried: ${PYDOC})"
exit 1
fi
# passthru ...
if [ $# -gt 0 ]
then
${PYDOC} $@
exit $?
fi
#--------------------------------------
# or else... start it up automagically :
PYDOC_PORT=9000
PYDOC_SERVER=http://localhost:${PYDOC_PORT}/
running=0
pydoc_pses=0
function browse_docs()
{
open ${PYDOC_SERVER}
}
for ps in `ps ax grep "${PYDOC}" awk '{ print $1 }'`
do
let pydoc_pses++
done
if [ $pydoc_pses -ge 2 ]
then
browse_docs
else
${PYDOC} -p ${PYDOC_PORT} &
until `curl -o /dev/null ${PYDOC_SERVER} &>/dev/null`
do
echo "waiting for pydoc server ..."
sleep 2
done
browse_docs
fi
exit 0