mirror of
https://github.com/jwinterm/ethtrader-ticker.git
synced 2026-11-13 09:04:13 +01:00
pull new ticker changes every loop
This commit is contained in:
@@ -3,7 +3,6 @@ package org.ethtrader.ticker
|
||||
import java.io.File
|
||||
import java.net.CookieHandler
|
||||
import java.net.CookieManager
|
||||
import java.net.CookiePolicy
|
||||
import java.net.URL
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
@@ -15,42 +14,47 @@ fun main(args: Array<String>) {
|
||||
|
||||
val outputDir = File("output")
|
||||
outputDir.mkdirs()
|
||||
val config = TickerEthConfig(::getResourceUrl)
|
||||
val reader = DataReader(config.providers)
|
||||
|
||||
val tickerFactory = TickerFactory(outputDir, ::getResourceUrl)
|
||||
val client = OAuthClient(config.reddit.apiUrl, AuthInfo(args[1], args[2], args[3], args[4]))
|
||||
val reddit = Reddit(client, args[0])
|
||||
val test = args.contains("--test")
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
val config = TickerEthConfig(::getResourceUrl)
|
||||
val reader = DataReader(config.providers)
|
||||
|
||||
val tickerFactory = TickerFactory(outputDir, ::getResourceUrl)
|
||||
val client = OAuthClient(config.reddit.apiUrl, AuthInfo(args[1], args[2], args[3], args[4]))
|
||||
val reddit = Reddit(client, args[0])
|
||||
val test = args.contains("--test")
|
||||
|
||||
|
||||
val data = reader.read(config.dataPoints)
|
||||
config.tickers.entries.forEach {
|
||||
try {
|
||||
val (name, tickerConfig) = it
|
||||
val ticker = tickerFactory.produceTicker(name, data, tickerConfig)
|
||||
if (!test) reddit.uploadImage(name, ticker)
|
||||
} catch (e: Exception) {
|
||||
println("ERROR: " + e.message)
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
val data = reader.read(config.dataPoints)
|
||||
config.tickers.entries.forEach {
|
||||
try {
|
||||
val (name, tickerConfig) = it
|
||||
val ticker = tickerFactory.produceTicker(name, data, tickerConfig)
|
||||
if (!test) reddit.uploadImage(name, ticker)
|
||||
} catch (e: Exception) {
|
||||
println("ERROR: " + e.message)
|
||||
val oldCss = reddit.getStylesheet()
|
||||
File(outputDir, "old.css").writeTextAndLog(oldCss, "Wrote old css to %s")
|
||||
val newCss = tickerFactory.getAndResetCss(oldCss)
|
||||
File(outputDir, "new.css").writeTextAndLog(newCss, "Wrote new css to %s")
|
||||
|
||||
if (!test) reddit.uploadStylesheet(newCss)
|
||||
} catch (e: Throwable) {
|
||||
println("Error trying to update tickers")
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
val oldCss = reddit.getStylesheet()
|
||||
File(outputDir, "old.css").writeTextAndLog(oldCss, "Wrote old css to %s")
|
||||
val newCss = tickerFactory.getAndResetCss(oldCss)
|
||||
File(outputDir, "new.css").writeTextAndLog(newCss, "Wrote new css to %s")
|
||||
|
||||
if (!test) reddit.uploadStylesheet(newCss)
|
||||
println("Waiting ${config.reddit.frequencySeconds} seconds.")
|
||||
Thread.sleep(TimeUnit.SECONDS.toMillis(config.reddit.frequencySeconds))
|
||||
if (test) break;
|
||||
} catch (e: Throwable) {
|
||||
println("Error trying to update tickers")
|
||||
e.printStackTrace()
|
||||
System.err.println("Unexpected error while running ticker." + e)
|
||||
}
|
||||
println("Waiting ${config.reddit.frequencySeconds} seconds.")
|
||||
Thread.sleep(TimeUnit.SECONDS.toMillis(config.reddit.frequencySeconds))
|
||||
if (test) break;
|
||||
}
|
||||
} catch (e: Throwable) {
|
||||
System.err.println("Usage: <<subreddit>> <<username>> <<password>> <<clientId>> <<secret>> <<resourceUrl>>")
|
||||
|
||||
Reference in New Issue
Block a user