Skip to content

Instantly share code, notes, and snippets.

@feehe21
Created December 21, 2018 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save feehe21/2896ea696563b1c048bac0cf975095f4 to your computer and use it in GitHub Desktop.
Save feehe21/2896ea696563b1c048bac0cf975095f4 to your computer and use it in GitHub Desktop.
char letter;
String sym = "";
String savedKey = "";
int boxX = 10;
int boxY = 75;
int displayWidth = 200;
int price = 0;
String beta = "";
String name = "";
ArrayList<String> listA = new ArrayList<String>();
String[] set = {"WMT","XOM","AAPL","UNH","MCK","CVS","AMZN","T","GM","F"};
int stripX = 600;
int stripX2 = 600;
boolean pressed = false;
int text = 0;
boolean two = false;
int x = 400;
int x2 = 600;
int spot = 0;
int spot2 = 0;
int stringX = 600;
String use = "";
int listLength = 0;
boolean reloading = false;
void setup(){
size(600, 480);
textSize(30);
//create();
}
void draw(){
background(0);
fill(0,0,255);
rect(boxX,boxY, 220,50);
fill(255);
text("Current key: " + sym, 10, 40);
text("Click For Stats", boxX + 5, boxY + 35);
for(int i = 0; i<3; i++){
rect(i*displayWidth,200, displayWidth,100);
}
text("Price", 0,190);
text("Beta", displayWidth ,190);
text("Name", 2*displayWidth,190);
fill(0);
text(price,0, 230);
text(beta,displayWidth, 230);
text(name,2*displayWidth, 230);
fill(255);
//strip();
//arrayLIST();
longString();
if(/*minute()%10 == 0 &&*/ second() == 0 && !reloading){
print("reloaded");
reload();
}
}
void reload(){
reloading = true;
for(int i = 0; i < listA.size(); i+=2){
savedKey = listA.get(i);
read();
listA.set(i+1,": " + price);
}
reloading = false;
//makeString();
}
void longString(){
text(use, stringX,400);
stringX -= 3;
if(stringX < -100 - (listLength * 80)){
stringX = 600;
makeString();
}
}
void makeString(){
use = "";
for(int i = 0; i < listA.size(); i+=2){
use = use + listA.get(i) + "" + listA.get(i+1) + " ";
}
listLength = listA.size();
}
void arrayLIST(){
print("1");
if(listA.size()>3){
print("2");
if(spot > listA.size()){
spot = 0;
}
text(listA.get(spot) + "" + listA.get(spot+1),x,400);
spot2 = spot+2;
if(spot2 >= listA.size()){
spot2 = 0;
}
text(listA.get(spot2) + "" + listA.get(spot2+1),x+300,400);
if(x<-100){
skip();
}
x-=5;
}
}
void create(String a){
listA.add(a);
savedKey = a;
read();
listA.add(": " + price);
}
void skip(){
spot += 2;
x = 600;
}
void strip(){
print("in");
if(stripX >=0){
print("1");
savedKey = set[text];
read();
text(set[text] + "" + price,stripX,400);
stripX -=5;
}else{
print("2");
if(!two){
two = !two;
stripX2 = stripX;
stripX = 600;
}
if(stripX2 < -50){
two = !two;
text+=1;
}
savedKey = set[text];
read();
text(set[text] + "" + price, stripX2, 400);
savedKey = set[text];
read();
text(set[text+1] + "" + price, stripX, 400);
stripX -= 5;
stripX2 -= 5;
}
}
void keyTyped() {
if ((key >= 'A' && key <= 'z') || key == ' ') {
letter = key;
letter = Character.toUpperCase(letter);
sym = sym + letter;
}
}
void keyPressed(){
//print(" " + keyCode);
if (keyCode == LEFT && sym.length() > 0) {
sym = sym.substring(0,sym.length()-1);
}
}
void mouseReleased(){
if(mouseX >= boxX && mouseX <= boxX + 220 && mouseY >= boxY && mouseY <= boxY + 50){
//print("Pressed!");
buttonPressed();
}
}
void buttonPressed(){
/*pressed = true;
savedKey = sym;
read();
pressed = false;*/
create(sym);
sym = "";
}
public void read(){
String[] ll = loadStrings("https://financialmodelingprep.com/api/company/profile/" + savedKey);
ll[0] = trim(ll[0].substring(ll[0].indexOf("{")));
String lines = "";
for(int i=0; i<ll.length; i++){
//println(ll[i]);
lines += ll[i];
}
JSONObject jarr = JSONObject.parse(lines);
JSONObject stock = jarr.getJSONObject(savedKey);
price = stock.getInt("Price");
beta = stock.getString("Beta");
name = stock.getString("companyName");
println("Price: "+price + ", Beta: " + beta + ", Name: " + name);
//sym = "";
//listA.add(savedKey);
//return price;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment