-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtweet.scala
64 lines (64 loc) · 1.92 KB
/
tweet.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package org.scala_twitter
import scala.xml._
/**
* Simple object that holds tweets
*/
class Tweet
{
var user_description:String = null
var user_url:String = null
var user_name:String = null
var profile_image_url:String = null
var user_protected:Boolean = false
var screen_name:String = null
var location:String = null
var user_id:Int = 0
var followers_count:Int = 0
var in_reply_to_screen_name:String = null
var in_reply_to_status_id:Option[Long] = None
var in_reply_to_user_id:Option[Long] = None
var truncated:Boolean = false
var favorited:Boolean = false
var created_at:String = null
var text:String = null
var source:String = null
var msg_id:Long = 0
def parse(xml:Node):Unit = {
created_at = (xml \ "created_at").text
msg_id = (xml \ "id").text.toLong
text = (xml \ "text").text.replaceAll("<","<").replaceAll(">",">")
source = (xml \ "source").text
truncated = (xml \ "truncated").text.toBoolean
in_reply_to_status_id = (xml \ "in_reply_to_status_id").text
in_reply_to_user_id = (xml \ "in_reply_to_user_id").text
favorited = (xml \ "favorited").text.toBoolean
in_reply_to_screen_name = (xml \ "in_reply_to_screen_name").text
user_id = (xml \ "user" \ "id").text.toInt
user_name = (xml \ "user" \ "name").text
screen_name = (xml \ "user"\ "screen_name").text
location = (xml \ "user" \ "location").text
user_description = (xml \ "user" \ "description").text
profile_image_url = (xml \ "user" \ "profile_image_url").text
user_url = (xml \ "user" \ "url").text
user_protected = (xml \ "user" \ "protected").text.toBoolean
followers_count = (xml \ "user" \ "followers_count").text.toInt
}
// Prevents null exceptions for all the ids
implicit def optioner(x:String):Option[Long] = {
x match {
case "" => None
case _ => Some(x.toLong)
}
}
}
/**
* Companion object that allows for factory creation
*/
object Tweet
{
def apply(x:Node):Tweet={
var i = new Tweet
i.parse(x)
return i
}
}