Created
July 15, 2018 19:30
-
-
Save marios8543/c5376f57bea4c228302ddf63b02f2047 to your computer and use it in GitHub Desktop.
will mcafee eat his own dick api in java. requires javalin and unirest
This file contains 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
package com.company; | |
import com.mashape.unirest.http.JsonNode; | |
import com.mashape.unirest.http.Unirest; | |
import java.text.SimpleDateFormat; | |
import java.util.HashMap; | |
import java.util.Map; | |
import java.util.concurrent.TimeUnit; | |
import io.javalin.Javalin; | |
import org.json.JSONObject; | |
public class Main { | |
public static void print(Object x){ | |
System.out.print(x); | |
} | |
public static void main(String[] args) throws Exception { | |
Javalin app = Javalin.start(5000); | |
app.get("/",ctx->ctx.result(new JSONObject(mcafee()).toString())); | |
} | |
public static Map mcafee() throws Exception{ | |
Double bpi = get_bpi(); | |
Double tbpi = 2244.265; | |
Double grate = 0.7826319559; | |
Long days_elapsed = TimeUnit.MILLISECONDS.toDays(System.currentTimeMillis() - new SimpleDateFormat("yyyy/MM/dd").parse("2017/07/17").getTime()); | |
Long days_remaining = TimeUnit.MILLISECONDS.toDays(new SimpleDateFormat("yyyy/MM/dd").parse("2020/12/31").getTime() - System.currentTimeMillis()); | |
Double pprice = Math.pow(10,grate*(new Double(days_elapsed)/new Double(365)))*tbpi; | |
Double pdiff = ((bpi-pprice)/pprice)*100; | |
String isdickonthemenu = "Yes!"; | |
if(pdiff>=0 && pdiff<=10){ | |
isdickonthemenu = "Maybe?"; | |
} | |
if(pdiff>10){ | |
isdickonthemenu = "No!"; | |
} | |
pprice = (double)Math.round(pprice * 100d) / 100d; | |
pdiff = (double)Math.round(pdiff * 100d) / 100d; | |
Map result = new HashMap(); | |
result.put("isdickonthemenu",isdickonthemenu); | |
result.put("current_price",bpi); | |
result.put("tweet_price",tbpi); | |
result.put("goal_rate",grate); | |
result.put("days_elapsed",days_elapsed); | |
result.put("days_remaining",days_remaining); | |
result.put("parity_price",pprice); | |
result.put("difference_percent",pdiff); | |
return result; | |
} | |
public static Double get_bpi() throws Exception{ | |
JsonNode res = Unirest.get("https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=USD,EUR").asJson().getBody(); | |
return res.getObject().getDouble("USD"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment