From 53843ec01340e181d3aeaa9d53325a2865225c65 Mon Sep 17 00:00:00 2001 From: Akul Goel Date: Sun, 30 Jul 2023 12:32:34 -0400 Subject: [PATCH] Add all default plugins to core repository and remove the plugin downloading from the scripts --- plugins/calendar/main.js | 26 +++++++++++++++++++++++ plugins/calendar/plugin.info | 3 +++ plugins/stock_prices/main.pl | 36 ++++++++++++++++++++++++++++++++ plugins/stock_prices/plugin.info | 3 +++ plugins/time_date/main.py | 12 +++++++++++ plugins/time_date/plugin.info | 3 +++ plugins/weather/main.pl | 11 ++++++++++ plugins/weather/plugin.info | 3 +++ setup/setup.bat | 6 ------ setup/setup.py | 15 ------------- setup/setup.sh | 6 ------ 11 files changed, 97 insertions(+), 27 deletions(-) create mode 100644 plugins/calendar/main.js create mode 100644 plugins/calendar/plugin.info create mode 100644 plugins/stock_prices/main.pl create mode 100644 plugins/stock_prices/plugin.info create mode 100644 plugins/time_date/main.py create mode 100644 plugins/time_date/plugin.info create mode 100644 plugins/weather/main.pl create mode 100644 plugins/weather/plugin.info diff --git a/plugins/calendar/main.js b/plugins/calendar/main.js new file mode 100644 index 0000000..f7078a1 --- /dev/null +++ b/plugins/calendar/main.js @@ -0,0 +1,26 @@ +const fs = require("fs"); +const events = []; + +const addEvent = (event, date) => { + events.push({event, date}); + fs.writeFileSync("events.json", JSON.stringify(events)); + console.log("Event added: " + event); +}; + +const checkEvents = () => { + setInterval(() => { + const now = new Date(); + events.forEach((event) => { + const eventDate = new Date(event.date); + if (now.getTime() >= eventDate.getTime()) { + console.log("Reminder: " + event.event); + akulAI.speak("Reminder: " + event.event); + } + }); + }, 60000); +}; + +module.exports = { + addEvent, + checkEvents +}; diff --git a/plugins/calendar/plugin.info b/plugins/calendar/plugin.info new file mode 100644 index 0000000..48b9af3 --- /dev/null +++ b/plugins/calendar/plugin.info @@ -0,0 +1,3 @@ +author: Akul Goel +dependencies: fs +description: This plugin asks for events and stores them in a JSON database. When the time comes, it will remind you to do your saved event. diff --git a/plugins/stock_prices/main.pl b/plugins/stock_prices/main.pl new file mode 100644 index 0000000..7e8c815 --- /dev/null +++ b/plugins/stock_prices/main.pl @@ -0,0 +1,36 @@ +#!/usr/bin/perl + +use LWP::UserAgent; + +sub fetch_stock_price { + my $ticker = shift; + + # Get stock information from Google Finance + my $url = "https://www.google.com/finance?q=$ticker"; + my $ua = LWP::UserAgent->new; + my $response = $ua->get($url); + + # Check if request was successful + if ($response->is_success) { + my $html = $response->decoded_content; + + # Extract the stock price + if ($html =~ /ref_.*_l">(.*?)<\/span>/i) { + return "The current stock price for $ticker is $1."; + } else { + return "Unable to find stock price for $ticker."; + } + } else { + return "Error fetching stock price for $ticker: " . $response->status_line; + } +} + +sub handle { + my $command = shift; + if ($command =~ /stock price for (.*)/i) { + return fetch_stock_price($1); + } + return "Invalid command."; +} + +1; diff --git a/plugins/stock_prices/plugin.info b/plugins/stock_prices/plugin.info new file mode 100644 index 0000000..3c1df57 --- /dev/null +++ b/plugins/stock_prices/plugin.info @@ -0,0 +1,3 @@ +author: Akul Goel +dependencies: LWP::UserAgent +description: This plugin tells you the stock prices when you ask it to. diff --git a/plugins/time_date/main.py b/plugins/time_date/main.py new file mode 100644 index 0000000..c6c5382 --- /dev/null +++ b/plugins/time_date/main.py @@ -0,0 +1,12 @@ +import datetime + +# define all commonly used variables here +now = datetime.datetime.now() + +def handle(command): + if "time" in command: + time_now = now.strftime("%H:%M:%S") + akulai.speak(f"The current time is{time_now}") + if "date" in command: + date_now = now.strftime("%Y-%m-%d") + akulai.speak(f"The current date is{date_now}") diff --git a/plugins/time_date/plugin.info b/plugins/time_date/plugin.info new file mode 100644 index 0000000..70ec124 --- /dev/null +++ b/plugins/time_date/plugin.info @@ -0,0 +1,3 @@ +author: Akul Goel +dependencies: datetime +description: This plugin tells you the time/date when you ask it to. diff --git a/plugins/weather/main.pl b/plugins/weather/main.pl new file mode 100644 index 0000000..ac22b98 --- /dev/null +++ b/plugins/weather/main.pl @@ -0,0 +1,11 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use Weather::Google; + +my $location = shift; + +my $weather = Weather::Google->new($location); + +print "The weather in $location is currently " . $weather->condition->temp . "F and " . $weather->condition->text . "\n"; diff --git a/plugins/weather/plugin.info b/plugins/weather/plugin.info new file mode 100644 index 0000000..69134d8 --- /dev/null +++ b/plugins/weather/plugin.info @@ -0,0 +1,3 @@ +author: Akul Goel +dependencies: Weather::Google +description: This plugin checks Google for the weather around you. diff --git a/setup/setup.bat b/setup/setup.bat index 94554af..8cd81c4 100644 --- a/setup/setup.bat +++ b/setup/setup.bat @@ -1,12 +1,6 @@ @echo off cd ".." -SET repo_url=https://github.com/Akul-AI/akulai-plugins -SET subdir=plugins -git "submodule" "add" "%repo_url%" -git "submodule" "update" "--init" "--recursive" -mv "akulai-plugins/%subdir%" "akulai/" -DEL /S "akulai-plugins" SET vosk_url=https://alphacephei.com/vosk/models/vosk-model-small-en-us-0.15.zip curl "-o" "vosk-model-small-en-us-0.15.zip" "%vosk_url%" unzip "vosk-model-small-en-us-0.15.zip" "-d" "akulai" diff --git a/setup/setup.py b/setup/setup.py index 708b15f..123d150 100644 --- a/setup/setup.py +++ b/setup/setup.py @@ -1,6 +1,5 @@ # If using this script on Windows, just keep in mind that this script needs to be run with administrator permissions. import os -import shutil import zipfile import requests import platform @@ -8,20 +7,6 @@ # Change directory to the parent directory of the script os.chdir("..") -# Define the GitHub repository URL and subdirectory -repo_url = "https://github.com/Akul-AI/akulai-plugins" -subdir = "plugins" - -# Use git submodules to fetch the plugins subdir in the akulai plugins repo -os.system("git submodule add {} --name akulai-plugins".format(repo_url)) -os.system("git submodule update --init --recursive") - -# Move the files from the subdirectory to the local "akulai/plugins" folder -shutil.move("{}/".format(f"akulai-plugins/{subdir}"), "akulai/") - -# Delete the files after copying them -shutil.rmtree("akulai-plugins") - # Use requests library to download vosk vosk_url = "https://alphacephei.com/vosk/models/vosk-model-small-en-us-0.15.zip" response = requests.get(vosk_url) diff --git a/setup/setup.sh b/setup/setup.sh index 418cf22..f4fae26 100644 --- a/setup/setup.sh +++ b/setup/setup.sh @@ -1,12 +1,6 @@ #!/bin/bash cd .. -repo_url="https://github.com/Akul-AI/akulai-plugins" -subdir="plugins" -git submodule add $repo_url -git submodule update --init --recursive -mv "akulai-plugins/$subdir" "akulai/" -rm -r "akulai-plugins" vosk_url="https://alphacephei.com/vosk/models/vosk-model-small-en-us-0.15.zip" curl -o "vosk-model-small-en-us-0.15.zip" $vosk_url unzip "vosk-model-small-en-us-0.15.zip" -d "akulai"