diff options
author | Sebastian Korotkiewicz <skorotkiewicz@gmail.com> | 2022-03-19 09:33:58 +0100 |
---|---|---|
committer | Sebastian Korotkiewicz <skorotkiewicz@gmail.com> | 2022-03-19 09:33:58 +0100 |
commit | 9472e4c4973f971ee640c651ede28096070e9a26 (patch) | |
tree | b234336a06d70fe8b6aabf6194e8fc84e278d8c7 | |
download | botany_widget-9472e4c4973f971ee640c651ede28096070e9a26.tar.gz |
Initial commit
-rw-r--r-- | README.md | 16 | ||||
-rw-r--r-- | botany.php | 120 |
2 files changed, 136 insertions, 0 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..ca008e4 --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +# botany widget + +a very simple script that allows you to host your plant on your website (lol) + +rename your home directory before use and check that the path to the botany matches your server + +it probably does not work completely, so i will probably update it quite often, +live demo: [tilde.team/~grizzly](https://tilde.team/~grizzly/) + +are you a member of tilde.team? visit my plant and water it! `grizzly` :) + +--- + +if you want to change or improve something, clone the repo, add changes, upload to some git server and send me the link, if you are a user of tilde.institute, send me an email with the path to your repo on the server + +=> grizzly/at/nand.sh diff --git a/botany.php b/botany.php new file mode 100644 index 0000000..989bc40 --- /dev/null +++ b/botany.php @@ -0,0 +1,120 @@ +<?php + $json = file_get_contents("/home/grizzly/.botany/grizzly_plant_data.json"); + $data = json_decode($json, true); + $art = file_get_contents("/srv/botany/botany/art/" . $data['stage'] . ".txt"); + + // https://github.com/jifunks/botany/blob/master/menu_screen.py#L233 + function water_gauge($last) { + $water_left_pct = 1 - ((time() - $last)/86400); + # don't allow negative value + $water_left_pct = max(0, $water_left_pct); + $water_left = intval(ceil($water_left_pct * 10)); + //$water_string = "(" . (")" * $water_left) . ("." * (10 - $water_left)) . ") " . strval(intval($water_left_pct * 100)) . "% "; + $water_string = strval(intval($water_left_pct * 100)) . "% "; + return $water_string; + } + +?> + +<div class="plant"> + <div class="status <?php echo $data['is_dead'] ? "dead" : "alive" ?>"><?php echo $data['is_dead'] ? "Dead 💀" : "Alive 👍" ?></div> + <div class="stats"> + plant: <?=$data['stage']?><br /> + score: <?=$data['score']?><br /> + age: <?=$data['age']?><br /> + generation: <?=$data['generation']?><br /> + water: <?=water_gauge($data['last_watered'])?> + + <em class="description"><?=$data['description']?></em> + </div> + <div class="ascii"> + <pre><?=getArt($data['stage'], $data['species'], $data['is_dead'])?></pre> + </div> +</div> + +<style> + .plant { + display: flex; + width: 450px; + border: 4px dotted greenyellow; + padding: 10px; + border-radius: 1rem; + background-color: beige; + position: relative; + } + .stats { + display: flex; + flex-direction: column; + align-items: center; + width: 35%; + } + .ascii { + width: 65%; + } + em.description { + margin-top: 10px; + } + .status { + position: absolute; + top: 0; + right: 0; + padding: 10px; + } + .alive { + color: green; + } + .dead { + color: red; + } +</style> + +<?php + + function getArt($stage, $species, $is_dead) { + + $stage_list = [ + 'seed', + 'seedling', + 'young', + 'mature', + 'flowering', + 'seed-bearing', + ]; + + $stage = array_keys($stage_list, $stage)[0] + 1; + + if ($is_dead) { + echo ascii_render('rip.txt'); + + } else if (date("m", time()) == 10 and date("d", time()) == 31) { + echo ascii_render('jackolantern.txt'); + + } else if ($stage == 0) { + echo ascii_render('seed.txt'); + + } else if ($stage == 1) { + echo ascii_render('seedling.txt'); + + } else if ($stage == 2) { + $this_filename = $species . '1.txt'; + echo ascii_render($this_filename); + + } else if ($stage == 3 or $stage == 5) { + $this_filename = $species . '2.txt'; + echo ascii_render($this_filename); + + } else if ($stage == 4) { + $this_filename = $species . '3.txt'; + echo ascii_render($this_filename); + + } else { + + } + + } + + function ascii_render($art) { + return file_get_contents("/srv/botany/botany/art/" . $art); + } + +?> \ No newline at end of file |