battle programming a forum for elite programmers with extreme will power to sharpen theire skills
 
HomeSearchRegisterLog in
Post new topic   Reply to topic
 

 DICorona skill

Go down 
AuthorMessage
kurosen
codding
codding
kurosen

Posts : 152
Join date : 2012-04-17

DICorona skill Empty
PostSubject: DICorona skill   DICorona skill EmptyTue Mar 17, 2020 8:03 am

this skill uses xml parsing to get how many are currently infected by the covid19
virus AKA coronachan clown

the skill is made of 2 classes :

Covid19 (java)

Code:
package com.yotamarker.lgkotlin1;

import android.os.AsyncTask;
import org.json.JSONArray;
import org.json.JSONObject;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;

public class Covid19 {

    private static String infected = "unknown";
    private static Boolean hasBeenUpdated = false;

    public static void updateStatistics() {
        DownloadTask task = new DownloadTask();
        String s1 = "https://www.worldometers.info/coronavirus/";
        task.execute(s1);
    }

    public static ArrayList<String> getCovidStats() {
        // returns vital weather info
        ArrayList<String> result = new ArrayList<String>();
        result.add("yes your majesty");
        //String numz = "0123456789";
        String tempInfected = infected;
        tempInfected = tempInfected.replace(",","");
//        result.add("infected");
//        result.add("infected 2");
//        result.add("infected 3");
//        result.add("infected 4");
        result.add(tempInfected);
        result.add("estimately");
        result.add("infected");
//        result.add("infected");
//        result.add("infected");
//        result.add("infected");
        http://result.add("infected");
        hasBeenUpdated = false;
        return result;
    }

    public static Boolean getHasBeenUpdated() {
        return hasBeenUpdated;
    }
    public static class DownloadTask extends AsyncTask<String,Void,String> {

    @Override
    protected String doInBackground(String... urls) {
    String result = "";
    URL url;
    HttpURLConnection urlConnection = null;

    try {

    url = new URL(urls[0]);
    urlConnection = (HttpURLConnection) url.openConnection();
    InputStream in = urlConnection.getInputStream();
    InputStreamReader reader = new InputStreamReader(in);
    int data = reader.read();

    while (data != -1) {
    char current = (char) data;
    result += current;
    data = reader.read();
    if(result.contains("<h1>Deaths:</h1>")){break;}
    }
    return result;

    } catch (Exception e) {
    e.printStackTrace();
    return null;
    }
    }

    @Override
    protected void onPostExecute(String s) {
    super.onPostExecute(s);

    try {
        RegexUtil regexUtil = new RegexUtil();
        infected = regexUtil.regexChecker(
                "(?<=<h1>Coronavirus Cases:</h1> <div class=\\\"maincounter-number\\\"> <span style=\\\"color:#aaa\\\">)(.*)(?=</span>)",
                s);
    hasBeenUpdated = true;
    http://Log.i("maalot",temp);
    } catch (Exception e) {
    e.printStackTrace();
    }

    }
    }
}

and DICorona :

Code:
package com.yotamarker.lgkotlin1;

import java.util.ArrayList;

public class DICorona extends DISkill {
    // tells the weather
    private Boolean where = false;

    public DICorona(Kokoro kokoro) {
        super(kokoro);
    }

    @Override
    public void input(String ear, String skin, String eye) {
        if (ear.contains("corona")) {
            Covid19.updateStatistics();
        }
    }

    @Override
    public void output(Neuron noiron) {
        if (Covid19.getHasBeenUpdated()) {
            noiron.algParts.add(verbatimGorithm());
        }
    }

    private Algorithm verbatimGorithm() {
        // returns a simple algorithm for saying sent parameter
        AbsAlgPart itte = new APVerbatim(Covid19.getCovidStats());
        String representation = "corona";
        ArrayList<AbsAlgPart> algParts1 = new ArrayList<>();
        algParts1.add(itte);
        Algorithm algorithm = new Algorithm("corona", representation, algParts1);
        return algorithm;
    }
}



demo :

https://streamable.com/pccnf

flower
Back to top Go down
 
DICorona skill
Back to top 
Page 1 of 1

Permissions in this forum:You can reply to topics in this forum
battle programmers alliance :: battle programming alliance :: the LivinGrimoire-
Post new topic   Reply to topicJump to: