Twitter Python

Python

Public Domain

Description

Download (right click, save as, rename as appropriate)

Embed

Tags:

twitter
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
######from lxml import etree

file = 'http://twitter.com/status/user_timeline/c_alan_zoppa.xml?count=10'

#file = '/home/alan/alan.xml'

xml = etree.parse(file)
foo = xml.findall('status') 
tweets = []

def mapnode(dict, searchTuple, parentLoop):
	for j in searchTuple:
		dict[j] = parentLoop.findtext(j)

for i in foo:
	newTweet = {}
	nodes = ('id', 'text', 'created_at', 'user/screen_name')
	mapnode(dict=newTweet, searchTuple=nodes, parentLoop=i)
	tweets = tweets + [newTweet]

#print tweets

for n in tweets:
	print n['user/screen_name'] + ': ' + n['text']