From 1489b2d92d1030daa6f3720d3d05f70b4467d1bc Mon Sep 17 00:00:00 2001 From: Bit Second Tech Date: Thu, 27 Jul 2017 16:55:47 -0500 Subject: [PATCH] 1.2 release (#9) * Added function to generate the configuration file * Added comments to functions definitions. Related to #6. * Header updated in README. Updated Windows steps as shell script does not work on Windows. Updated setup steps. Added URL to bitsecondtech.com in More Information section. Updated missing output to generate configuration file. Updated if condition in script main. * Updated the directory for rules. Updated README to include how to import rules. * Resolve #2 and #6. Added blank lines to generated config file for readability. --- README.md | 40 +++++++++++++------ get_weather.sh | 40 +++++++++++++++++-- .../create_cut_grass_activity.txt | 0 .../create_water_grass_action.txt | 0 .../increment_grass_counter.txt | 0 .../increment_rain_counter.txt | 0 .../reset_grass_counter_variable.txt | 0 .../reset_rain_counter.txt | 0 8 files changed, 65 insertions(+), 15 deletions(-) rename {rules => rules_import}/create_cut_grass_activity.txt (100%) rename {rules => rules_import}/create_water_grass_action.txt (100%) rename {rules => rules_import}/increment_grass_counter.txt (100%) rename {rules => rules_import}/increment_rain_counter.txt (100%) rename {rules => rules_import}/reset_grass_counter_variable.txt (100%) rename {rules => rules_import}/reset_rain_counter.txt (100%) diff --git a/README.md b/README.md index da06e4d..600dcc6 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# farmosnws +# FarmOS NWS Automated importing of National Weather Service (NWS) data into FarmOS. ## Purpose @@ -22,7 +22,7 @@ investment. ## Setup ### Clone the Repository -Clone this repository by running the command below +To get the latest release, clone this repository by running the command below ```shell git clone https://github.com/bitsecondal/farmosnws.git ``` @@ -31,6 +31,10 @@ git clone https://github.com/bitsecondal/farmosnws.git Make a copy of the get_weather_config_ex.sh file. Update the variables located in the configuration script file. +```shell +get_weather.sh genconfig +``` + The *feedsdir* location will need to be updated to the file system location that Drupal is checking to see if data files are available. @@ -56,38 +60,50 @@ file respectively. If you want to log the output of the script, also update the ```shell 24 * * * * (/path/to/drupal/sites/all/modules/farmosnws/get_weather.sh /path/to/drupal/sites/all/modules/farmosnws/config.sh) >> /var/log/get_weather.log 2>&1 ``` +If you don't want to log the output of the command, then use the command below. +```shell +24 * * * * (/path/to/drupal/sites/all/modules/farmosnws/get_weather.sh /path/to/drupal/sites/all/modules/farmosnws/config.sh) >> /dev/null 2>&1 +``` #### Windows with Task Scheduler -You will need to install software that is capable of downloading files in Windows. Powershell -script should be capable of peforming this task. -Open the Task Scheduler, located in the Control Panel. Create a new scheduled task. When prompted -for the command to run, enter the path to the script in your Drupal directory and the configuration -file as an argument in the script. +This script is not designed to work on Windows. + +## Rules +Rules for automating some tasks, such as cutting grass based on frequency are included in this module. +To import the rules, do the following: +1) Install the Rules and Rules UI modules. +2) Copy and paste the text of the rule that you wish to import. The text for each of the rules are located in the rules_import directory of this module. +3) Go to Adminstration > Configuration > Workflow > Rules > Import Rule. +4) Paste the text of the rule that you copied into the box and then click Import. ## Code Updates To get the latest version of this code, pull the latest release from the [FarmOS NWS GitHub Page](https://github.com/bitsecondal/farmosnws). -Alternatively you can get the latest code by going to the directory that contains the code and running the command below: +Alternatively you can get the latest code by going to the directory that contains the code and running the commands below: ```shell +git checkout master git pull origin master ``` ## Author -Kenny Robinson, Bit Second Tech (www.bitsecondtech.com) +Kenny Robinson, [Bit Second Tech](www.bitsecondtech.com) ## Bug Reports and Feature Enhancements Bugs and enhancements will be tracked using the Issue tracker on the [project repo](https://github.com/bitsecondal/farmosnws/issues). If you need to report a bug, please open a new issue on this repo. Include -as much detail as possible so that the issue can be replicated. +as much detail as possible including error messages or screenshots so that the issue can be replicated. ## License Project is available under the MIT License. See LICENSE for more information. ## Additional Information +For more information about Bit Second Tech, please visit the [Bit Second Tech](http://www.bitsecondtech.com) website. + For more information about FarmOS, please visit the [FarmOS](http://www.farmos.org) website. -For more information about the National Weather Service (NWS), please visit the -[NWS](http://www.weather.gov) website. +For more information about the National Weather Service (NWS), please visit the [NWS](http://www.weather.gov) website. + + diff --git a/get_weather.sh b/get_weather.sh index d114ab0..0b48334 100644 --- a/get_weather.sh +++ b/get_weather.sh @@ -18,6 +18,8 @@ function log_message() { function show_help() { # Show the help documentation +# accepts no arguments + log_message "" log_message "Usage:" log_message "get_weather.sh " @@ -28,19 +30,48 @@ function show_help() { log_message "" log_message "For more information, visit https://github.com/bitsecondal/farmosnws" } + +function generate_config_file() { +# generates the configuration file by answering questions. Resolves Issue #6. +# accepts no arguments + + echo "Please answer the questions below to have a configuration file generated." + echo -n "Full path to save configuration file:" + read CONFIGFILENAME + echo -n "Path of the feeds directory:" + read FEEDSPATH + echo -n "Location Code: " + read LOCATIONCODE + + log_message "Generating configuration file." + + touch ${CONFIGFILENAME} + + echo "feedsdir=${FEEDSPATH}" >> ${CONFIGFILENAME} + echo "location=${LOCATIONCODE}" >> ${CONFIGFILENAME} + echo "export feedsdir" >> ${CONFIGFILENAME} + echo "export location" >> ${CONFIGFILENAME} + echo "" >> ${CONFIGFILENAME} + echo "# Config file generated on $(date)" >> ${CONFIGFILENAME} + echo "" >> ${CONFIGFILENAME} + + log_message "Done generating configuration file." +} ## SCRIPT MAIN ## SCRIPT MAIN ## SCRIPT MAIN ## ## SCRIPT MAIN ## SCRIPT MAIN ## SCRIPT MAIN ## -FILENAME="${1}" +# check the argument passed +if [[ "${1}" == "genconfig" ]]; then + generate_config_file # verify that the configuration file exists -if [[ -f ${FILENAME} ]]; then +elif [[ -f ${1} ]]; then log_message "Loading the configuration" # load the configuration file - source $1 + source ${1} log_message "Done loading the configuration" @@ -50,8 +81,11 @@ if [[ -f ${FILENAME} ]]; then /usr/bin/wget -O ${feedsdir}/${location}_$(/bin/date +%Y%m%d%H%M%S).xml http://w1.weather.gov/xml/current_obs/${location}.xml log_message "Done getting the weather data" + +# no value or invalid value passed, then show help else log_message "Configuration file does not exist." show_help fi + diff --git a/rules/create_cut_grass_activity.txt b/rules_import/create_cut_grass_activity.txt similarity index 100% rename from rules/create_cut_grass_activity.txt rename to rules_import/create_cut_grass_activity.txt diff --git a/rules/create_water_grass_action.txt b/rules_import/create_water_grass_action.txt similarity index 100% rename from rules/create_water_grass_action.txt rename to rules_import/create_water_grass_action.txt diff --git a/rules/increment_grass_counter.txt b/rules_import/increment_grass_counter.txt similarity index 100% rename from rules/increment_grass_counter.txt rename to rules_import/increment_grass_counter.txt diff --git a/rules/increment_rain_counter.txt b/rules_import/increment_rain_counter.txt similarity index 100% rename from rules/increment_rain_counter.txt rename to rules_import/increment_rain_counter.txt diff --git a/rules/reset_grass_counter_variable.txt b/rules_import/reset_grass_counter_variable.txt similarity index 100% rename from rules/reset_grass_counter_variable.txt rename to rules_import/reset_grass_counter_variable.txt diff --git a/rules/reset_rain_counter.txt b/rules_import/reset_rain_counter.txt similarity index 100% rename from rules/reset_rain_counter.txt rename to rules_import/reset_rain_counter.txt