-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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