package com.josketres.moneros.atom;

import com.josketres.moneros.atom.rss.LaJornadaRss;
import com.josketres.moneros.atom.rss.PatricioRss;
import com.josketres.moneros.atom.rss.QuchoRss;
import com.rometools.rome.feed.synd.SyndFeed;
import com.rometools.rome.io.FeedException;
import com.rometools.rome.io.SyndFeedInput;
import com.rometools.rome.io.SyndFeedOutput;
import com.rometools.rome.io.XmlReader;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.time.LocalDate;
import java.time.Month;

public class FetchCartoonsJob implements Job {

    public static final String CURRENT_ATOM_URL = "http://josketres.github.io/moneros-atom/current.atom";

    final static Logger LOG = LoggerFactory.getLogger(FetchCartoonsJob.class);

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {

        LOG.info("Fetching cartoons, using current atom url: " + CURRENT_ATOM_URL);

        SyndFeed feed = new FeedBuilder()
                .initialDate(LocalDate.of(2015, Month.FEBRUARY, 1))
                .entries(new PatricioRss(),
                        new LaJornadaRss(),
                        new QuchoRss())
                .mergeWith(readCurrentFromServer())
                .build();

        try {
            if (!Files.exists(Paths.get("website"))) {
                Files.createDirectory(Paths.get("website"));
                Files.createFile(Paths.get("website/current.atom"));
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        try (Writer writer = new FileWriter("website/current.atom", false)) {
            new SyndFeedOutput().output(feed, writer, false);
        } catch (IOException | FeedException e) {
            throw new RuntimeException(e);
        }
    }

    private static SyndFeed readCurrentFromServer() {

        try (Reader reader = new XmlReader(new URL(CURRENT_ATOM_URL))) {
            return new SyndFeedInput().build(reader);
        } catch (FeedException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

@@ -580,92 +580,9 @@
 .io.
-FileWriter;%0Aimport java.io.IOException;%0Aimport java.io.Reader;%0Aimport java.io.Writer
+*
 ;%0Aim
@@ -1039,24 +1039,96 @@
 xception %7B%0A%0A
+        LocalDate initialDate = LocalDate.of(2015, Month.FEBRUARY, 1);%0A%0A
         LOG.
@@ -1180,11 +1180,54 @@
 rl: 
-%22 +
+(%7B%7D) and initial-date: (%7B%7D) %22,%0A               
  CUR
@@ -1239,16 +1239,29 @@
 ATOM_URL
+, initialDate
 );%0A%0A    
@@ -1331,45 +1331,19 @@
 ate(
-Loc
+initi
 alDate
-.of(2015, Month.FEBRUARY, 1)
 )%0A  
@@ -1543,24 +1543,644 @@
  .build();%0A%0A
+        writeFeed(feed);%0A%0A        deployToGitHubPages();%0A    %7D%0A%0A    private void deployToGitHubPages() %7B%0A        %0A        try %7B%0A            Process process = new ProcessBuilder(System.getProperty(%22user.dir%22) + %22/deploy_website.sh%22).start();%0A            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));%0A            String line = null;%0A            while ((line = reader.readLine()) != null) %7B%0A                LOG.info(line);%0A            %7D%0A        %7D catch (IOException e) %7B%0A            throw new RuntimeException(e);%0A        %7D%0A    %7D%0A%0A    private void writeFeed(SyndFeed feed) %7B%0A%0A
         try 

Add step to publish feed to gh-pages