Skip to content

Instantly share code, notes, and snippets.

@crazy4groovy
Forked from mike-neck/TimeAvatar.groovy
Created May 22, 2012 19:26
Show Gist options
  • Save crazy4groovy/2771102 to your computer and use it in GitHub Desktop.
Save crazy4groovy/2771102 to your computer and use it in GitHub Desktop.
inspired by image change script git://gist.github.com/1481409.git written by Yusuke Yamamoto. see https://gist.github.com/1481409
/**
* Copyright (C) 2011 Yusuke Yamamoto
* Licensed under the Apache License, Version 2.0 (the "License");
* http://www.apache.org/licenses/LICENSE-2.0
*
*
**/
@Grab(group='quartz', module='quartz', version='1.5.2')
@Grab(group='org.twitter4j', module='twitter4j-core', version='2.2.5')
import org.quartz.*
import org.quartz.impl.StdSchedulerFactory
import twitter4j.TwitterFactory
import twitter4j.Twitter
Twitter.metaClass.define {
imageFile {
new File("${new Date().format('yyyyMMdd')}.png")
}
profileChange {
return {
delegate.updateProfileImage(imageFile())}
}
}
class UpdateProfile implements Job {
@Override void execute(JobExecutionContext context){
context.jobDetail.jobDataMap.each { key, task ->
println key
task()
}
}
}
JobDetail.metaClass.define {
job {String nm ->
delegate.name = nm
delegate
}
does {Class cls ->
delegate.jobClass = cls
delegate
}
}
CronTrigger.metaClass.define {
cron {String nm ->
delegate.name = nm
delegate
}
when {String exp ->
delegate.cronExpression = exp
delegate
}
}
def twitter = TwitterFactory.singleton
def jobs = new JobDetail().job('updateProfile').does(UpdateProfile.class)
def map = jobs.getJobDataMap()
map << ['updateProfile' : twitter.profileChange()]
def cron = new CronTrigger().cron('cron').when('0 20 20 * * ?')
def schedule = new StdSchedulerFactory().getScheduler()
schedule.start()
schedule.scheduleJob(jobs, cron)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment