2
* Created by IntelliJ IDEA.
9
import groovy.beans.Bindable
13
@Bindable String status = "\u00a0"
15
XmlSlurper slurper = new XmlSlurper()
18
def withStatus(status, c) {
24
} catch (Throwable t) {
25
setStatus("Error $status : ${t.message =~ '400'?'Rate Limit Reached':t}")
31
boolean login(def name, def password) {
32
withStatus("Logging in") {
33
Authenticator.setDefault(
34
[getPasswordAuthentication : {
35
return new PasswordAuthentication(name, password) }
37
authenticatedUser = getUser(name)
43
getFriends(authenticatedUser)
46
def getFriends(String user) {
47
return getFriends(getUser(user))
50
def getFriends(user) {
52
withStatus("Loading Friends") {
54
def list = slurper.parse(new URL("http://twitter.com/statuses/friends/${user.screen_name}.xml").openStream())
56
list.user.collect(friends) {it}
59
list = slurper.parse("http://twitter.com/statuses/friends/${user.screen_name}.xml&page=$page")
60
} catch (Exception e) { break }
63
withStatus("Loading Friends Images") {
65
loadImage(it.profile_image_url as String)
70
def getFriendsTimeline() {
71
getFriendsTimeline(user)
74
def getFriendsTimeline(String friend) {
75
getFriendsTimeline(getUser(friend))
78
def getFriendsTimeline(user) {
80
withStatus("Loading Timeline") {
81
timeline = slurper.parse(
82
new URL("http://twitter.com/statuses/friends_timeline/${user.screen_name}.xml").openStream()
85
withStatus("Loading Timeline Images") {
86
return timeline.each {
87
loadImage(it.user.profile_image_url as String)
93
return getTweets(user)
96
def getTweets(String friend) {
97
return getTweets(getUser(frield))
100
def getTweets(friend) {
102
withStatus("Loading Tweets") {
103
tweets = slurper.parse(
104
new URL("http://twitter.com/statuses/user_timeline/${friend.screen_name}.xml").openStream()
107
withStatus("Loading Tweet Images") {
109
loadImage(it.user.profile_image_url as String)
114
def getUser(String screen_name) {
115
withStatus("Loading User $screen_name") {
116
if (screen_name.contains('@')) {
117
return slurper.parse(
118
new URL("http://twitter.com/users/show.xml?email=${screen_name}").openStream()
121
return slurper.parse(
122
new URL("http://twitter.com/users/show/${screen_name}.xml").openStream()
129
withStatus("Tweeting") {
130
def urlConnection = new URL("http://twitter.com/statuses/update.xml").openConnection()
131
urlConnection.doOutput = true
132
urlConnection.outputStream << "status=${URLEncoder.encode(message, 'UTF-8')}"
133
return slurper.parse(urlConnection.inputStream)
137
// no need to read these, swing seems to cache these so the EDT won't stall
138
def loadImage(image) {
139
if (!imageMap[image]) {
140
Thread.start {imageMap[image] = new javax.swing.ImageIcon(new URL(image))}
b'\\ No newline at end of file'