Comments (23)
-
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.
Weldone guys, Lets get to work. Just coming now
from team-fury-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 usingglob
$files = glob('./scripts/*');
Run
exec
on each file and compare withpreg_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
andpreg_match
from team-fury-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.
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.
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.
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.
Well done guys, still working on my code as well but I'm using SQL
from team-fury-1.
Weldone guys
from team-fury-1.
Great job guys.
from team-fury-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.
Ok @piouson
from team-fury-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.
Well we should incorporate it. The text is intrinsically still valid.
from team-fury-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
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.
@geraldon1997 and everyone else, please share your written code here to compare and merge efforts
from team-fury-1.
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.
@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.
@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.
Splendid job @Tijatech
from team-fury-1.
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..
from team-fury-1.
FYI @IsmailMuhammed2019 has demo'd a Live Site of the last commit from @dave-ok π₯
from team-fury-1.
@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)
- Email Regex in Output HOT 2
- json data display format HOT 4
- Remove email from regex HOT 6
- All Python Scripts not working HOT 1
- Update link to the website HOT 2
- Possible improvements HOT 2
- Creating Server to run script and also to watchout for new commits HOT 1
- Improve Documentation HOT 1
- Add Gitpod for Live Review
- Merging PRs of Scripts Team HOT 14
- Python Scripts not working on my xampp. HOT 5
- israel HOT 1
- Implement frontend ui HOT 2
- Live server edit HOT 5
- JSON output fails validation
- Clean repo files
- Ideas for the next tasks HOT 4
- Ideas for Designers HOT 1
- Ideas for Frontend HOT 1
- Ideas for backend HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from team-fury-1.