GithubHelp home page GithubHelp logo

dachangge / love-mail Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hwywl/love-mail

0.0 1.0 0.0 201 KB

爱的邮件,定时给我家妹子发一份

License: Apache License 2.0

Java 4.38% CSS 89.56% JavaScript 5.52% HTML 0.55%

love-mail's Introduction

love-mail

爱的邮件,定时给我家妹子发一份

先看效果

分析源码

其实源码很简单,一个Scheduled定时器就可以搞定了,天气的数据来自第三方接口

@Component
public class ScheduledTasks {
    private static final Logger log = LoggerFactory.getLogger(ScheduledTasks.class);

    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

    /**
     * 每天中午12点自动执行一次
     */
    @Scheduled(cron = "0 0 12 1/1 * ?")
    public void cronTask() throws MessagingException {
        StringBuffer buffer = new StringBuffer();
        Date date = new Date();

        String result = HttpUtil.get("http://t.weather.sojson.com/api/weather/city/101280101", CharsetUtil.CHARSET_UTF_8);

        Weather weather = JSONUtil.toBean(result, Weather.class);
        List<Forecast> list = weather.getData().getForecast();

        buffer.append("今天是" + dateFormat.format(date) + StrUtil.COMMA + DateUtil.dayOfWeekEnum(date).toChinese() + StrUtil.CRLF + StrUtil.CRLF);

        buffer.append("首先今天好也想你喔(づ ̄3 ̄)づ╭❤~,然后我就要来播送天气预报了!!" + StrUtil.CRLF + StrUtil.CRLF);

        if (list == null || list.isEmpty()){
            buffer.append("好讨厌,今天的天气数据没有更新,不能给我家的抱抱预报天气了[○・`Д´・ ○]");
        }else {
            Forecast forecast = list.get(0);

            buffer.append("今天最:");
            buffer.append(forecast.getHigh());
            buffer.append(",最");
            buffer.append(forecast.getLow());
            buffer.append(StrUtil.CRLF);
            buffer.append(StrUtil.CRLF);

            buffer.append(forecast.getType());
            buffer.append(",风力" + forecast.getFl());
            buffer.append(",空气质量是" + weather.getData().getQuality());

            buffer.append(StrUtil.CRLF);
            buffer.append(StrUtil.CRLF);

            buffer.append("今天将在 " + forecast.getSunset() + " 太阳会缓缓落下,我会在家做好饭等你哟!");

            buffer.append(StrUtil.CRLF);
            buffer.append(StrUtil.CRLF);

            buffer.append("最后" + forecast.getNotice());

            buffer.append(StrUtil.CRLF);
            buffer.append(StrUtil.CRLF);
            buffer.append("爱你٩(๑>◡<๑)۶傻宝宝!!!");
        }


        OhMyEmail.subject("男朋友的日常问候(^.^)")
                .from("亲爱的傻宝宝:(^.^)")
                .to(Config.to)
                .text(buffer.toString())
                .send();

        log.info("cron 现在时间是 {}", dateFormat.format(new Date()));
    }
}

部署使用

把邮箱配置信息改为你的账号密码,然后发送人也改一下,就好了,打成jar包部署 如果用QQ游戏需要第三方客户端授权码,就是密码换为第三方授权码!!!

web天气查询

如果你想看web页面的天气,可以直接访问 http://localhost:9999

问题建议

love-mail's People

Contributors

hwywl avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.