suumo-search

Perform advanced searches on Suumo.jp
git clone https://git.neuralcrash.com/suumo-search.git
Log | Files | Refs | README

commit bba5d14b40f25c8fd624cd0b71ebc262ab52aed5
parent 70fd033c5030eb5aae2089822f01c387327113a1
Author: Kebigon <git@kebigon.xyz>
Date:   Sun,  8 Mar 2020 14:27:08 +0900

Save caches into var/state

Diffstat:
Msrc/assembly/assembly.xml | 7+++++++
Msrc/main/java/xyz/kebigon/housesearch/browser/yahoo/transit/YahooTransitBrowser.java | 7++-----
Msrc/main/java/xyz/kebigon/housesearch/file/RoutesCache.java | 20+++++++++++++-------
Msrc/main/java/xyz/kebigon/housesearch/file/SearchArchive.java | 6+++++-
4 files changed, 27 insertions(+), 13 deletions(-)

diff --git a/src/assembly/assembly.xml b/src/assembly/assembly.xml @@ -15,6 +15,13 @@ <exclude>*/**</exclude> </excludes> </fileSet> + <fileSet> + <directory>.</directory> + <outputDirectory>var/state</outputDirectory> + <excludes> + <exclude>*/**</exclude> + </excludes> + </fileSet> </fileSets> <dependencySets> <dependencySet> diff --git a/src/main/java/xyz/kebigon/housesearch/browser/yahoo/transit/YahooTransitBrowser.java b/src/main/java/xyz/kebigon/housesearch/browser/yahoo/transit/YahooTransitBrowser.java @@ -1,6 +1,5 @@ package xyz.kebigon.housesearch.browser.yahoo.transit; -import java.io.File; import java.io.IOException; import java.util.Collection; import java.util.HashSet; @@ -22,8 +21,7 @@ public class YahooTransitBrowser extends Browser public YahooTransitBrowser() throws JsonParseException, JsonMappingException, IOException { - final File file = new File("cache.json"); - cache = RoutesCache.load(file); + cache = RoutesCache.load(); } @Override @@ -31,8 +29,7 @@ public class YahooTransitBrowser extends Browser { super.close(); - final File file = new File("cache.json"); - cache.save(file); + cache.save(); } public Collection<Route> search(String from, String to) diff --git a/src/main/java/xyz/kebigon/housesearch/file/RoutesCache.java b/src/main/java/xyz/kebigon/housesearch/file/RoutesCache.java @@ -21,6 +21,12 @@ import xyz.kebigon.housesearch.domain.Route; @NoArgsConstructor public class RoutesCache { + private static final File ROUTES_CACHE_FILE = new File("var/state/routes-cache.json"); + static + { + ROUTES_CACHE_FILE.getParentFile().mkdirs(); + } + private Map<String, Collection<Route>> cache = new HashMap<>(); public Collection<Route> get(String cacheKey) @@ -33,21 +39,21 @@ public class RoutesCache cache.put(cacheKey, routes); } - public void save(File file) throws JsonGenerationException, JsonMappingException, IOException + public void save() throws JsonGenerationException, JsonMappingException, IOException { - log.info("Saving {} routes to {}", cache.size(), file); + log.info("Saving {} routes to {}", cache.size(), ROUTES_CACHE_FILE.getAbsolutePath()); final ObjectMapper mapper = new ObjectMapper(); - mapper.writeValue(file, this); + mapper.writeValue(ROUTES_CACHE_FILE, this); } - public static RoutesCache load(File file) throws JsonParseException, JsonMappingException, IOException + public static RoutesCache load() throws JsonParseException, JsonMappingException, IOException { - if (file.exists()) + if (ROUTES_CACHE_FILE.exists()) { - log.info("Loading routes cache from {}", file); + log.info("Loading routes cache from {}", ROUTES_CACHE_FILE.getAbsolutePath()); final ObjectMapper mapper = new ObjectMapper(); - return mapper.readValue(file, RoutesCache.class); + return mapper.readValue(ROUTES_CACHE_FILE, RoutesCache.class); } else return new RoutesCache(); diff --git a/src/main/java/xyz/kebigon/housesearch/file/SearchArchive.java b/src/main/java/xyz/kebigon/housesearch/file/SearchArchive.java @@ -17,7 +17,11 @@ import xyz.kebigon.housesearch.domain.Posting; @Slf4j public class SearchArchive implements Closeable { - private static final File ARCHIVE_FILE = new File("archive"); + private static final File ARCHIVE_FILE = new File("var/state/archive"); + static + { + ARCHIVE_FILE.getParentFile().mkdirs(); + } private final Collection<String> urls = new HashSet<String>();