Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of https://github.com/13yo/iCal4WS

Conflicts:
	src/main/scala/eu/kaatz/iCal/ImporterActor.scala
  • Loading branch information...
commit d2018146bb9adedd81e25813c59827eff609349b 2 parents 1905c41 + acd8cb1
unknown authored
View
3  build.sbt
@@ -38,5 +38,6 @@ libraryDependencies ++= Seq(
"ch.qos.logback" % "logback-classic" % "0.9.26" % "compile->default", // Logging
"org.mnode.ical4j" % "ical4j" % "1.0.3",
"org.scala-tools.time" % "time_2.9.1" % "0.5",
- "com.typesafe.akka" % "akka-actor" % "2.0"
+ "com.typesafe.akka" % "akka-actor" % "2.0",
+ "org.clapper" %% "markwrap" % "0.5.3"
)
View
4 src/main/scala/eu/kaatz/iCal/ImporterActor.scala
@@ -40,7 +40,6 @@ class ImporterActor extends Actor with EventImplicits {
private def getTagFilteredEvents(tags: List[String], now: Date) = {
events(now).collect({ case x: Event if !(x.tags.intersect(tags).isEmpty) => x })
}
-
private def calcMD5(s: String): String = {
val md5 = MessageDigest.getInstance("MD5")
md5.reset()
@@ -50,6 +49,7 @@ class ImporterActor extends Actor with EventImplicits {
private def events(now: Date) = {
val md5 = calcMD5(eventsSource.getLines().foldLeft("") { _ + _ })
+ //eventsSource.getLines().foreach(println)
// println(now.getTime - updateDate.getTime)
// println(eventsMD5)
// println(md5)
@@ -93,4 +93,4 @@ class ImporterActor extends Actor with EventImplicits {
case class AllEvents(now: Date)
case class OneEvent(id: String)
-case class TaggedEvents(tags: List[String], now: Date)
+case class TaggedEvents(tags: List[String], now: Date)
View
110 src/main/scala/eu/kaatz/iCal/model/Event.scala
@@ -16,68 +16,70 @@ import net.fortuna.ical4j.model.Recur
import scala.collection.mutable.ListBuffer
import java.net.URLEncoder
-case class Event(id: String, title: String, description: String, tags: Seq[String], start: Date, end: Date)
+case class Event(id : String, title : String, description : String, tags : Seq[String], start : Date, end : Date)
object Event {
- implicit def str2date(dString: String): Date = {
- new SimpleDateFormat("yyyyMMdd-HHmmss-").parse(dString.replace('T', '-').replace('Z', '-'))
- }
+ implicit def str2date(dString : String) : Date = {
+ new SimpleDateFormat("yyyyMMdd-HHmmss-").parse(dString.replace('T', '-').replace('Z', '-'))
+ }
- def fromVEvent(event: VEvent): Seq[Event] = {
- def vd(p: DateProperty) = p match {
- case null => null
- case _ => p.getDate()
- }
- def vs(p: Property) = p match {
- case null => ""
- case _ => p.getValue()
- }
- def toEvent(e: VEvent) = {
- val id = vs(e.getUid())
- val title = vs(e.getSummary())
- val description = vs(e.getDescription())
- val tags = vs(e.getProperty(Property.CATEGORIES)).replaceAll("\\\\,", ",").split(",")
- val begin = vd(e.getStartDate())
- val end = vd(e.getEndDate())
- Event(id, title, description, tags, begin, end)
- }
+ def fromVEvent(event : VEvent) : Seq[Event] = {
+ def vd(p : DateProperty) = p match {
+ case null => null
+ case _ => p.getDate()
+ }
+ def vs(p : Property) = p match {
+ case null => ""
+ case _ => p.getValue()
+ }
+ def toEvent(e : VEvent) = {
+ import org.clapper.markwrap._
+ val mdParser = MarkWrap.parserFor(MarkupType.Markdown)
+ val id = vs(e.getUid())
+ val title = vs(e.getSummary())
+ val description = mdParser.parseToHTML(vs(e.getDescription()))
+ val tags = vs(e.getProperty(Property.CATEGORIES)).replaceAll("\\\\,", ",").split(",")
+ val begin = vd(e.getStartDate())
+ val end = vd(e.getEndDate())
+ Event(id, title, description, tags, begin, end)
+ }
- val eList = ListBuffer[Event]()
- val p = event.getProperty(Property.RRULE)
- if (p != null) {
- println(p.asInstanceOf[RRule].getRecur())
- val r: Recur = p.asInstanceOf[RRule].getRecur()
- val begin = new net.fortuna.ical4j.model.Date((DateTime.now - 1.month).toDate)
- val end = new net.fortuna.ical4j.model.Date((DateTime.now + 1.year).toDate)
- val period = new net.fortuna.ical4j.model.Period(new net.fortuna.ical4j.model.DateTime(event.getProperty(Property.DTSTART).getValue()), new net.fortuna.ical4j.model.DateTime(event.getProperty(Property.DTEND).getValue()))
- val dateIt = r.getDates(begin, end, Value.DATE_TIME).iterator
- while (dateIt.hasNext()) {
- val d = dateIt.next().asInstanceOf[net.fortuna.ical4j.model.DateTime]
- val per = new net.fortuna.ical4j.model.Period(d, period.getDuration())
- val eProps = event.getProperties()
- eProps.getProperty(Property.DTSTART).setValue(per.getStart().toString())
- eProps.getProperty(Property.DTEND).setValue(per.getEnd().toString())
- eProps.remove(eProps.getProperty(Property.RRULE))
- eList += toEvent(new VEvent(eProps))
+ val eList = ListBuffer[Event]()
+ val p = event.getProperty(Property.RRULE)
+ if (p != null) {
+ println(p.asInstanceOf[RRule].getRecur())
+ val r : Recur = p.asInstanceOf[RRule].getRecur()
+ val begin = new net.fortuna.ical4j.model.Date((DateTime.now - 1.month).toDate)
+ val end = new net.fortuna.ical4j.model.Date((DateTime.now + 1.year).toDate)
+ val period = new net.fortuna.ical4j.model.Period(new net.fortuna.ical4j.model.DateTime(event.getProperty(Property.DTSTART).getValue()), new net.fortuna.ical4j.model.DateTime(event.getProperty(Property.DTEND).getValue()))
+ val dateIt = r.getDates(begin, end, Value.DATE_TIME).iterator
+ while (dateIt.hasNext()) {
+ val d = dateIt.next().asInstanceOf[net.fortuna.ical4j.model.DateTime]
+ val per = new net.fortuna.ical4j.model.Period(d, period.getDuration())
+ val eProps = event.getProperties()
+ eProps.getProperty(Property.DTSTART).setValue(per.getStart().toString())
+ eProps.getProperty(Property.DTEND).setValue(per.getEnd().toString())
+ eProps.remove(eProps.getProperty(Property.RRULE))
+ eList += toEvent(new VEvent(eProps))
+ }
+ } else {
+ eList += toEvent(event)
}
- } else {
- eList += toEvent(event)
- }
- eList.toSeq
- }
+ eList.toSeq
+ }
}
object EventImplicits extends EventImplicits
trait EventImplicits {
- import net.liftweb.json._
- // import net.liftweb.json.JsonParser._
- implicit val f = DefaultFormats
+ import net.liftweb.json._
+ // import net.liftweb.json.JsonParser._
+ implicit val f = DefaultFormats
- implicit def VEvent2Events(e: VEvent): TraversableOnce[Event] = Event.fromVEvent(e)
- implicit def Json2Event(s: String) = parse(s).extract[Event]
- implicit def Event2Json(e: Event): JObject = ("id", e.id) ~ ("title", e.title) ~ ("description", e.description) ~
- ("tags", JArray(e.tags.map(x => JString(x.trim)).toList)) ~
- ("start", (e.start.getTime() / 1000)) ~
- ("end", (e.end.getTime() / 1000)) ~ ("url", URLEncoder.encode(e.id + e.start))
- implicit def EList2Json(l: List[Event]) = JArray(l map { Event2Json(_) })
+ implicit def VEvent2Events(e : VEvent) : TraversableOnce[Event] = Event.fromVEvent(e)
+ implicit def Json2Event(s : String) = parse(s).extract[Event]
+ implicit def Event2Json(e : Event) : JObject = ("id", e.id) ~ ("title", e.title) ~ ("description", e.description) ~
+ ("tags", JArray(e.tags.map(x => JString(x.trim)).toList)) ~
+ ("start", (e.start.getTime() / 1000)) ~
+ ("end", (e.end.getTime() / 1000)) ~ ("url", URLEncoder.encode(e.id + e.start))
+ implicit def EList2Json(l : List[Event]) = JArray(l map { Event2Json(_) })
}
Please sign in to comment.
Something went wrong with that request. Please try again.