Giter VIP home page Giter VIP logo

Comments (23)

sheuabdulazeez avatar sheuabdulazeez commented on August 13, 2024 5
  • This runs exec on the .py, .js and .php

  • It compare the message with the format given and assign fails and passes

  • It displays the json format when ?json added

  • This takes in json object with the requires

<?php
$dir = "./scripts/";
$files = scandir($dir);
$data = [];
foreach ($files as $key => $filename) {
    if ($filename !== "." and $filename !== "..") {
        $file  = $dir.$filename;
        if (preg_match("/([a-zA-Z0-9\s_\\.\-\(\):])+.js$/i", $filename)) {
            
            $ouput = exec("node $file");
           
        }
        if (preg_match("/([a-zA-Z0-9\s_\\.\-\(\):])+.php$/i", $filename)) {
            $ouput = exec("php $file");  
    
        }
        if (preg_match("/([a-zA-Z0-9\s_\\.\-\(\):])+.py$/i", $filename)) {
            $ouput = json_encode(exec("py $file"));    
        }
        $ouput = json_decode($ouput);
        $pattern = "/Hello\sWorld,\sthis\sis\s\w+(?:\s\w+)*\swith\sHNGi7\sID\sHNG-[0-9]{5}\susing\s\w+\sfor\sstage\s2\stask/i";
        $data[$key-2]['file'] = $filename;
        $data[$key-2]['name'] = $ouput->name;
        $data[$key-2]['message'] = $ouput->message;
        $data[$key-2]['email'] = $ouput->email;
        $data[$key-2]['hng_id'] = $ouput->id;
        $data[$key-2]['status'] = (preg_match($pattern, $ouput->message)) ? "Passed" : "Failed";
        
        
    }
}
$passes = 0;
$fails = 0;
foreach ($data as $key => $value) {
    if ($value['status'] == "Passed") {
        $passes += 1;
    }else{
        $fails += 1;
    }
}

?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Team Fury Task Tests</title>
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
</head>
<body>
    <?php 
    if ($_SERVER["QUERY_STRING"] == "json") {
        echo json_encode($data);
    }else{?>
    
    <nav class="navbar navbar-default">
    <div>HNGi7 Team Furry</div>
    <div class="navbar">
        <div>Lead: @godstime</div>
        <div>Backend: @lead</div>
        <div>DevOps: @lead</div>
    </div>
    </nav>
    <div  class="container">
        <div class="top">
            <div>Submitted: <?php echo count($data) ?></div>
            <div>Passed: <?php echo $passes  ?></div>
            <div>Failed: <?php echo $fails  ?></div>
        </div>
        <table>
            <thead>
                <th>#</th>
                <th>Name</th>
                <th>Message</th>
                <th>Status</th>
            </thead>
            <tbody>
                <?php for ($i=0; $i < count($data); $i++) { ?>
                    <tr>
                        <td><?php echo $i ?></td>
                        <td><?php echo $data[$i]['name'] ?></td>
                        <td><?php echo $data[$i]['message'] ?></td>
                        <td><?php echo $data[$i]['status'] ?></td>
                    </tr>
                <?php } ?>

            </tbody>
        </table>
    </div>
                <?php } ?>
</body>
</html>

Review if and check with other files.

from team-fury-1.

Abuh05 avatar Abuh05 commented on August 13, 2024 2

Weldone guys, Lets get to work. Just coming now

from team-fury-1.

piouson avatar piouson commented on August 13, 2024 1

No knowledge of PHP but good with regex, I've just read the PHP documentation and came up with this.

Regex pattern for matching output

$pattern = "/Hello\sWorld,\sthis\sis\s\w+(?:\s\w+)*\swith\sHNGi7\sID\sHNG-[0-9]{5}\susing\s\w+\sfor\sstage\s2\stask/";

Read files in scripts folder using glob

$files = glob('./scripts/*');

Run exec on each file and compare with preg_match

foreach($files as $file) {
  if (preg_match("/.py\b/", $file)) {
    $output = exec("python $file");
  }
  else if (preg_match("/.js\b/", $file)) {
    $output = exec("node $file");
  }
  else if (preg_match("/.php\b/", $file)) {
    $output = exec("php $file");
  }
  else {
    # handle other languages here
    $output = exec($file);
  }

  if (preg_match($pattern, $output)) {
    echo "Pass! = $file\r\n";
  }
  else {
    echo "Fail! = $file\r\n";
  }
}

An idea for other languages might be to use get_file_contents and preg_match

from team-fury-1.

piouson avatar piouson commented on August 13, 2024 1

$_SERVER might be useful to check that query string equals json, then show json output with json_encode()

if $_SERVER['QUERY_STRING'] == "json"
  echo json_encode($output)
else
  echo $output

from team-fury-1.

delight500 avatar delight500 commented on August 13, 2024 1

I have written a script that runs js and python but and prints the desired result but I can't get it to run PHP any help

from team-fury-1.

piouson avatar piouson commented on August 13, 2024 1

I have written a script that runs js and python but and prints the desired result but I can't get it to run PHP any help

@delight500 please share your code here. If your environment runs php, you can just use exec("php $file") to run php file.. it should also work from the command line but you need to add php path to your system variables if using Windows

from team-fury-1.

samueluchendu avatar samueluchendu commented on August 13, 2024 1

weldone guys, currently working on how to display all files in json format, i would share my code as soon as am done.

from team-fury-1.

Bisola248 avatar Bisola248 commented on August 13, 2024 1

Well done guys, still working on my code as well but I'm using SQL

from team-fury-1.

thebolarin avatar thebolarin commented on August 13, 2024 1

Weldone guys

from team-fury-1.

maroafenogho avatar maroafenogho commented on August 13, 2024 1

Great job guys.

from team-fury-1.

Emmyola avatar Emmyola commented on August 13, 2024 1

Welcome guys, God will bless all our effort, keep moving is the key to archive our goal...working on my too using php

from team-fury-1.

sheuabdulazeez avatar sheuabdulazeez commented on August 13, 2024 1

Ok @piouson

from team-fury-1.

Arch997 avatar Arch997 commented on August 13, 2024 1

Hey guys, on the regex. I would suggest we add a fail-safe that considers the possibility of someone having their HNG ID in brackets. I'll give an example in python. I'm sure PHP guys can replicate it:

pattern = r"Hello world\S? this is \w+/S? with HNGi7 ID \W?\S?\w+-\d+\W?\S? using (Python|Javascript||PHP|Java) for Stage 2 task"

The idea is that I'm writing my ID in a bracket after the "with HNGi7ID". The patterns I'm seeing will not match it. Please respond to this if you see it. My script is like that and I'm not ready to pull it again😩

from team-fury-1.

Arch997 avatar Arch997 commented on August 13, 2024 1

Well we should incorporate it. The text is intrinsically still valid.

from team-fury-1.

 avatar commented on August 13, 2024

I have written a script that runs js and python but and prints the desired result but I can't get it to run PHP any help

we already have 2 scripts doing that, but let's see yours, we are trying to compare the results with a particular pattern

from team-fury-1.

piouson avatar piouson commented on August 13, 2024

@geraldon1997 and everyone else, please share your written code here to compare and merge efforts

from team-fury-1.

simply-alliv avatar simply-alliv commented on August 13, 2024

Firstly, where are we going to host the backend (server side) code? Have we sorted that out yet?

Secondly, do we need to make an API for the frontend developers?

from team-fury-1.

piouson avatar piouson commented on August 13, 2024

@simply-alliv yea an API is the best outcome, this way the frontend team maintain their code and link the backend work in index.html

from team-fury-1.

piouson avatar piouson commented on August 13, 2024

@Tijatech wow you've spent good time on this, thank you!!

Can you please move this to #22 where @dave-ok is already working on a solution.
You both and others can brainstorm on there..

from team-fury-1.

codessage avatar codessage commented on August 13, 2024

Splendid job @Tijatech

from team-fury-1.

piouson avatar piouson commented on August 13, 2024

Hey @Arch997 thanks for working on this, can you please share your PR number in #22 and add your idea there as well.

I think the Task Specification was clear enough, there shouldn't be brackets around IDs, however, some might do this, so at the very least, we might want to consider this..

Discuss with @dave-ok in #22

from team-fury-1.

piouson avatar piouson commented on August 13, 2024

FYI @IsmailMuhammed2019 has demo'd a Live Site of the last commit from @dave-ok πŸ₯‡

from team-fury-1.

Adiomojeed avatar Adiomojeed commented on August 13, 2024

@dave-ok can you add my script to the files you are testing so I can know my status. It is in my PR, where you copied the FE UI codes

from team-fury-1.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.