Skip to content

A live bird collage card for your Home Assistant dashboard.

adding image retrieval

mcguirepr8984bec4756fc6
diff --git a/scripts/get_citation.sh b/scripts/get_citation.sh
new file mode 100755
index 00000000..5452d628
--- /dev/null
+++ b/scripts/get_citation.sh
@@ -0,0 +1,9 @@
+#!/usr/bin/env bash
+# testing getting images dynamically
+first_call=$(lynx -dump -listonly "https://commons.wikimedia.org/w/index.php?search=${1//_/+}&title=Special:MediaSearch&go=Go&type=image")
+lynx -dump -nonumbers $(lynx -dump \
+ $(echo "$first_call" \
+ | sed '11q;d' \
+ | awk '{print $2}' ) \
+ | awk -F'. ' '/Cite/ {print $2}' \
+ | xargs echo -n) 2>&1 | grep -A10 'Chicago style' | grep -A10 -e '^$' | grep -B10 'CBE' | grep -B10 -e '^$'
diff --git a/scripts/get_image.sh b/scripts/get_image.sh
new file mode 100755
index 00000000..132df458
--- /dev/null
+++ b/scripts/get_image.sh
@@ -0,0 +1,10 @@
+#!/usr/bin/env bash
+# testing getting images dynamically
+first_call=$(lynx -dump -listonly "https://commons.wikimedia.org/w/index.php?search=${1//_/+}&title=Special:MediaSearch&go=Go&type=image")
+lynx -dump -listonly \
+ $(echo "$first_call" \
+ | sed '11q;d' \
+ | awk '{print $2}' ) \
+ | awk '/thumb/ {print $2}' \
+ | head -1 \
+ | xargs echo -n
diff --git a/scripts/stats.php b/scripts/stats.php
index 2f1d4051..b03be6d4 100644
--- a/scripts/stats.php
+++ b/scripts/stats.php
@@ -119,6 +119,16 @@ a {
text-align: center;
}
+img {
+ width:75%;
+}
+
+.center {
+ display: block;
+ margin-left: auto;
+ margin-right: auto;
+}
+
select {
font-size:large;
width: 60%;
@@ -148,7 +158,7 @@ form {
float: none;
width: 100%;
}
- input, label {
+ input, label, img {
width:100%;
{
}
@@ -226,19 +236,23 @@ while($rows=$stats ->fetch_assoc())
while($rows = $specificstats->fetch_assoc()) {
$dbname = preg_replace('/ /', '_', $rows['Com_Name']);
$dbsciname = preg_replace('/ /', '_', $rows['Sci_Name']);
+ $imagelink = shell_exec("/home/pi/BirdNET-Pi/scripts/get_image.sh $dbname");
+ $imagecitation = shell_exec("/home/pi/BirdNET-Pi/scripts/get_citation.sh $dbname");
echo "<tr>
<td>";echo "<a href=\"../By_Common_Name/$dbname\"/>";echo $rows['Com_Name']; echo "</a></td>
<td>";echo "<a href=\"../By_Scientific_Name/$dbsciname\"/>";echo $rows['Sci_Name']; echo "</a></td>
<td>";echo $rows['COUNT(*)'];echo "</td>
<td>";echo $rows['MAX(Confidence)'];echo "</td>
- <td><a href=\"https://wikipedia.org/wiki/$dbname\" target=\"top\"/>Wikipedia</a>, <a href=\"https://allaboutbirds.org/guide/$dbname\" target=\"top\"/>All About Birds</a></td>
- </tr>";
-}}
-?>
+ <td><a href=\"https://wikipedia.org/wiki/$dbsciname\" target=\"top\"/>Wikipedia</a>, <a href=\"https://allaboutbirds.org/guide/$dbname\" target=\"top\"/>All About Birds</a>
+ </tr>
</table>
+ <img class=\"center\" src=\"$imagelink\">
+ <pre>";echo $imagecitation;echo "</pre></td>
</div>
</div>
-</div>
+</div>";
+}}
+?>
</section>
</html>
diff --git a/scripts/viewdb.php b/scripts/viewdb.php
index 18672e07..d1bcc7d6 100644
--- a/scripts/viewdb.php
+++ b/scripts/viewdb.php
@@ -114,7 +114,7 @@ while($rows=$mosttable ->fetch_assoc())
<td><a href="/By_Scientific_Name/<?php echo $dbsciname;?>"/><?php echo $rows['Sci_Name'];?></a></td>
<td><a href="/By_Common_Name/<?php echo $dbname;?>"/><?php echo $rows['Com_Name'];?></a></td>
<td><?php echo $Confidence;?></td>
- <td><a class="a2" href="https://allaboutbirds.org/guide/<?php echo $dbname;?>" target="top">All About Birds</a>, <a class="a2" href="https://wikipedia.org/wiki/<?php echo $dbname;?>" target="top">Wikipedia</a></td>
+ <td><a class="a2" href="https://allaboutbirds.org/guide/<?php echo $dbname;?>" target="top">All About Birds</a>, <a class="a2" href="https://wikipedia.org/wiki/<?php echo $dbsciname;?>" target="top">Wikipedia</a></td>
</tr>
<?php
}