From 1a5da40cb460174835f22d89f8e6ada66ffe45bd Mon Sep 17 00:00:00 2001 From: Bit Second Date: Fri, 7 Jul 2017 19:12:00 -0500 Subject: [PATCH 01/75] Created the info file. Added the module configuration form. Added code to pull the XML feed from the NWS. --- farmosnws.info | 7 +++++ farmosnws.module | 82 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 farmosnws.info create mode 100644 farmosnws.module diff --git a/farmosnws.info b/farmosnws.info new file mode 100644 index 0000000..d8026a0 --- /dev/null +++ b/farmosnws.info @@ -0,0 +1,7 @@ +name = FarmOS NWS +description = Imports data from the National Weather Service into FarmOS. +core = 7.x +dependenies[] = rules +files[] = farmosnws.install +files[] = farmosnws.module + diff --git a/farmosnws.module b/farmosnws.module new file mode 100644 index 0000000..899847d --- /dev/null +++ b/farmosnws.module @@ -0,0 +1,82 @@ + t('FarmOS NWS Settings'), + 'page callback' => 'drupal_get_form', + 'page arguments' => 'farmosnws_admin_form', + 'access arguments' => 'administer users', + 'type' => MENU_NORMAL_ITEM, + ); + + return $items; +} + +/** + * + * Implements hook_cron() + */ +function farmosnws_cron() { + farmosnws_get_xml(); +} + +/** + * + * get the weather data from the NWS + */ +function farmosnws_get_xml($location) { + // http://w1.weather.gov/xml/current_obs/${location}.xml + + + $weatherfeedsdir = variable_get('farmosnws_weather_feeds_dir', 'public://'); + + $locations = variable_get('farmosnws_locations', ''); + $locations_array = explode("\n", $locations); + $locations_count = count($locations_array); + + foreach ($locations_array as $loc) { + $weather_feed_name = $weather_feed_dir . '/' . $loc . '_' . date(); + $url = "http://w1.weather.gov/xml/current_obs/" . $loc . ".xml" + + $response = drupal_http_request($url, array()); + + file_put_contents($weather_feed_name, $response->data); + } +} + +/** + * + * Module configuration form + */ +function farmosnws_admin_form() { + $form = array(); + + $form['head'] = array( + '#type' => 'fieldset', + '#title' => 'Weather Data', + '#description' => t('Enter the locations that you would like weather data pulled for. Each location must be entered on a separate line.'), + ); + $form['head']['farmosnws_locations'] = array( + '#type' => 'textarea', + '#title' => t('Locations'), + '#description' => t('Enter the locations that you would like weather data pulled for. Each location must be entered on a separate line.'), + '#required' => TRUE, + '#default_value' => variable_get('farmosnws_locations', ''), + ); + $form['farmosnws_weather_feeds_dir'] = array( + '#type' => 'textfield', + '#title' => t('Feeds Directory'), + '#required' => TRUE, + '#description' => t('The server location were feeds will be pulled from'), + '#default_value' => variable_get('farmosnws_weather_feeds_dir'); + ); + + return system_settings_form($form); +} + From bea7c33c716522eee4e9dccefd0d47fdaba621b8 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Sat, 8 Jul 2017 12:45:40 -0500 Subject: [PATCH 02/75] Updated dependencies for module. --- farmosnws.info | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/farmosnws.info b/farmosnws.info index d8026a0..0e908ec 100644 --- a/farmosnws.info +++ b/farmosnws.info @@ -1,7 +1,7 @@ name = FarmOS NWS description = Imports data from the National Weather Service into FarmOS. core = 7.x -dependenies[] = rules +dependenies[] = rules, feeds files[] = farmosnws.install files[] = farmosnws.module From 4142a0b79489c31cfe4b025d0658bba93ebdb360 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Sat, 8 Jul 2017 12:58:45 -0500 Subject: [PATCH 03/75] Updated cron weather feed function call. Updated locations variable. Removed fieldset from admin form. Updated descriptions and default value calls in admin form. --- farmosnws.module | 47 +++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/farmosnws.module b/farmosnws.module index 899847d..48a2a6b 100644 --- a/farmosnws.module +++ b/farmosnws.module @@ -30,25 +30,41 @@ function farmosnws_cron() { * * get the weather data from the NWS */ -function farmosnws_get_xml($location) { +function farmosnws_get_xml() { // http://w1.weather.gov/xml/current_obs/${location}.xml - $weatherfeedsdir = variable_get('farmosnws_weather_feeds_dir', 'public://'); $locations = variable_get('farmosnws_locations', ''); - $locations_array = explode("\n", $locations); - $locations_count = count($locations_array); + $location_array = explode("\n", $locations); + $location_count = count($location_array); - foreach ($locations_array as $loc) { - $weather_feed_name = $weather_feed_dir . '/' . $loc . '_' . date(); + foreach ($location_array as $loc) { + // $weather_feed_name = $weather_feed_dir . '/' . $loc . '.' . date("Ymd.His"); + $weather_feed_name = $weather_feed_dir . '/' . $uniqid($loc, FALSE) . '.xml'; $url = "http://w1.weather.gov/xml/current_obs/" . $loc . ".xml" $response = drupal_http_request($url, array()); - - file_put_contents($weather_feed_name, $response->data); - } -} + + watchdog('farmosnws', 'Response code: ' . $response->code, array(), WATCHDOG_INFO, NULL); + + // if error occurs when performing the request + if ( $response->error ) { + watchdog('farmosnws', $response->error, array(), WATCHDOG_ERROR, NULL); + drupal_set_message($response->error, 'error', FALSE); + } + else{ + // if the directory doesnt exist, then create it + if ( is_dir($weatherfeedsdir) == FALSE ) { + mkdir($weatherfeedsdir, 775); + watchdog('farmosnws', 'Created weather feed directory.', array(), WATCHDOG_INFO, NULL); + } // end if + + // save the contents retrieved + file_put_contents($weather_feed_name, $response->data); + } + } // end foreach +} // end function /** * @@ -57,23 +73,18 @@ function farmosnws_get_xml($location) { function farmosnws_admin_form() { $form = array(); - $form['head'] = array( - '#type' => 'fieldset', - '#title' => 'Weather Data', - '#description' => t('Enter the locations that you would like weather data pulled for. Each location must be entered on a separate line.'), - ); - $form['head']['farmosnws_locations'] = array( + $form['farmosnws_locations'] = array( '#type' => 'textarea', '#title' => t('Locations'), '#description' => t('Enter the locations that you would like weather data pulled for. Each location must be entered on a separate line.'), '#required' => TRUE, - '#default_value' => variable_get('farmosnws_locations', ''), + '#default_value' => variable_get('farmosnws_locations'), ); $form['farmosnws_weather_feeds_dir'] = array( '#type' => 'textfield', '#title' => t('Feeds Directory'), '#required' => TRUE, - '#description' => t('The server location were feeds will be pulled from'), + '#description' => t('The directory where weather feeds should be saved to.'), '#default_value' => variable_get('farmosnws_weather_feeds_dir'); ); From 86d639858894b38495ee1ba3343e1393d0b3ac73 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Sat, 8 Jul 2017 13:08:25 -0500 Subject: [PATCH 04/75] Added additional logging via watchdog. --- farmosnws.module | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/farmosnws.module b/farmosnws.module index 48a2a6b..af1c0de 100644 --- a/farmosnws.module +++ b/farmosnws.module @@ -31,9 +31,7 @@ function farmosnws_cron() { * get the weather data from the NWS */ function farmosnws_get_xml() { - // http://w1.weather.gov/xml/current_obs/${location}.xml - - $weatherfeedsdir = variable_get('farmosnws_weather_feeds_dir', 'public://'); + $weatherfeedsdir = variable_get('farmosnws_weather_feeds_dir'); $locations = variable_get('farmosnws_locations', ''); $location_array = explode("\n", $locations); @@ -44,6 +42,8 @@ function farmosnws_get_xml() { $weather_feed_name = $weather_feed_dir . '/' . $uniqid($loc, FALSE) . '.xml'; $url = "http://w1.weather.gov/xml/current_obs/" . $loc . ".xml" + watchdog('farmosnws', 'Getting weather data for ' . $loc, array(), WATCHDOG_INFO, NULL); + $response = drupal_http_request($url, array()); watchdog('farmosnws', 'Response code: ' . $response->code, array(), WATCHDOG_INFO, NULL); @@ -53,6 +53,7 @@ function farmosnws_get_xml() { watchdog('farmosnws', $response->error, array(), WATCHDOG_ERROR, NULL); drupal_set_message($response->error, 'error', FALSE); } + // if no errors occur when performing the request else{ // if the directory doesnt exist, then create it if ( is_dir($weatherfeedsdir) == FALSE ) { @@ -62,6 +63,7 @@ function farmosnws_get_xml() { // save the contents retrieved file_put_contents($weather_feed_name, $response->data); + watchdog('farmosnws', 'Weather data saved to ' . $weather_feed_name, array(), WATCHDOG_INFO, NULL); } } // end foreach } // end function From 50a36d9533a2d2635f362aebfc6d212a093a9258 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Sat, 8 Jul 2017 20:22:57 -0500 Subject: [PATCH 05/75] Updated README with steps for setting up module within Drupal. Added configuration and dependencies to the module info file. --- README.md | 34 +++++++++++++++++++++++++++++----- farmosnws.info | 7 ++++++- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index da06e4d..7cead12 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,31 @@ Clone this repository by running the command below git clone https://github.com/bitsecondal/farmosnws.git ``` -### Create Configuration File +### Get Weather Data via Drupal +* Install the module in Drupal +* Go to the module configuration page. +* Go to the [XML data feeds](http://w1.weather.gov/xml/current_obs/) page on the NWS website. +* Select the state and click Find +* Find the location taht is closest to the area that you want to pull data for. +* In the parenthesis next to the location, you will see a 4-character code. Copy this code. +* Place the 4-character code on a line in the text box. If you have multiple locations that you +want to pull the data for, then enter each one on a separate line. +* Enter the path where the weather files are to be saved on the server. This will be the same location +that the Feeds module will import the files from. +* Click *Save configuration* on the form. +* Go to the *Feeds importer* (Structure > Feeds importer) page +* Create a new importer and name it. +* Select the *XPath XML Parser* as the parser. +* Enter each of the elementst that you want to capture in the Parser Settings. +* Configure the remainder of the settings for the Feeds Importer. + +#### Schedule Script +No scheduling has to be done. Weather data will be automatically be pulled when Drupal cron run. If +necessary, adjust Drupal cron frequency or use [Elysia Cron][https://www.drupal.org/project/elysia_cron] +to run module specific cron. + +### Get Weather Data via Shell Script (Advanced) +#### Create Configuration File Make a copy of the get_weather_config_ex.sh file. Update the variables located in the configuration script file. @@ -38,7 +62,7 @@ The *location* variable will need to be updated to the location code for the loc that you want data for. * Go to the [XML data feeds](http://w1.weather.gov/xml/current_obs/) page on the NWS website. * Select the state and click Find -* Find the location that is cloest to the area that you want to pull data for. +* Find the location that is closest to the area that you want to pull data for. * In the parenthesis next to the location, you will see a 4-character code. Copy this code. * Place the 4-character code in the configuration file inside quotes. * Save the configuration file. @@ -46,18 +70,18 @@ that you want data for. If you have multiple locations that you want to pull data for, you'll need to create a configuration file for each location and set up a scheduled task for each configuration file. -### Schedule Script +#### Schedule Script To set up a cron job to run to automatically pull the latest weather data, you use the details and steps below. The National Weather Service updates the data hourly. -#### Linux/Ubuntu with Crontab +##### Linux/Ubuntu with Crontab Update the paths mentioned to the location of your script and the location of your configuration file respectively. If you want to log the output of the script, also update the log location. ```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 ``` -#### Windows with Task Scheduler +##### 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 diff --git a/farmosnws.info b/farmosnws.info index 0e908ec..688f618 100644 --- a/farmosnws.info +++ b/farmosnws.info @@ -1,7 +1,12 @@ name = FarmOS NWS description = Imports data from the National Weather Service into FarmOS. +package = FarmOS core = 7.x -dependenies[] = rules, feeds +configure=admin/config/farmosnws +dependencies[] = feeds +dependencies[] = feeds_fetcher_directory +dependencies[] = feeds_xpathparser +dependencies[] = rules files[] = farmosnws.install files[] = farmosnws.module From 17635848faec076695005f6d92571ccc0d877bbf Mon Sep 17 00:00:00 2001 From: Bit Second Date: Sun, 9 Jul 2017 10:09:14 -0500 Subject: [PATCH 06/75] Updated readme with addtional information. --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7cead12..d784c91 100644 --- a/README.md +++ b/README.md @@ -104,14 +104,18 @@ Kenny Robinson, Bit Second Tech (www.bitsecondtech.com) 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. +If you need to report a bug, please open a new issue. Include +as much detail as possible, including screenshots and error messages, 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. + From 4a3699f8a010ad22189c0c4085725fd8dbf8ad47 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Sun, 9 Jul 2017 10:30:43 -0500 Subject: [PATCH 07/75] Added checking of last cron run to ensure that multiple feeds are not pulled within an hour. --- farmosnws.module | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/farmosnws.module b/farmosnws.module index af1c0de..df80fa3 100644 --- a/farmosnws.module +++ b/farmosnws.module @@ -15,6 +15,17 @@ function farmosnws_menu() { 'type' => MENU_NORMAL_ITEM, ); + // TO DO: add call to bypass cron ron + /* + $items['admin/config/farmosnws/weather_force'] = array( + 'title' => t('FarmOS NWS Data Pull'), + 'description' => 'Pull weather data more frequently that then hourly limit.', + 'page callback' => 'farmosnws_get_xml', + 'access arguments' => 'administer users', + 'type' => MENU_CALLBACK, + ); + */ + return $items; } @@ -23,7 +34,30 @@ function farmosnws_menu() { * Implements hook_cron() */ function farmosnws_cron() { - farmosnws_get_xml(); + $pullfeed = farmosnws_get_new_feed(); + if ($pullfeed == TRUE) { + farmosnws_get_xml(); + } + else { + watchdog('farmosnws', 'Skipping pulling weather feed.', array(), WATCHDOG_INFO, NULL); + } +} + +/** + * + * Determine whether to pull the data feed from the NWS based on when cron was last run + */ +function farmosnws_get_new_feed() { + $cron_last = variable_get('cron_last'); + $time_diff = REQUEST_TIME - $cron_last; + + if ($time_diff >= 3600) { + $returnval = TRUE; + } + else { + $returnval = FALSE; + } + return $returnval; } /** @@ -38,7 +72,6 @@ function farmosnws_get_xml() { $location_count = count($location_array); foreach ($location_array as $loc) { - // $weather_feed_name = $weather_feed_dir . '/' . $loc . '.' . date("Ymd.His"); $weather_feed_name = $weather_feed_dir . '/' . $uniqid($loc, FALSE) . '.xml'; $url = "http://w1.weather.gov/xml/current_obs/" . $loc . ".xml" From 2cd233b8c3d58570de967b7463b62cf639c2e443 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Tue, 18 Jul 2017 19:33:13 -0500 Subject: [PATCH 08/75] Updated README removing spelling mistakes, bad links, and sections that are no longer valid. --- README.md | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index d784c91..892729e 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # farmosnws -Automated importing of National Weather Service (NWS) data into FarmOS. +A Drupal module to allow automated importing of National Weather Service (NWS) data into FarmOS. ## Purpose The purpose of this project is to allow FarmOS to use data from the National @@ -42,12 +42,12 @@ that the Feeds module will import the files from. * Go to the *Feeds importer* (Structure > Feeds importer) page * Create a new importer and name it. * Select the *XPath XML Parser* as the parser. -* Enter each of the elementst that you want to capture in the Parser Settings. +* Enter each of the elements that you want to capture in the Parser Settings. * Configure the remainder of the settings for the Feeds Importer. #### Schedule Script No scheduling has to be done. Weather data will be automatically be pulled when Drupal cron run. If -necessary, adjust Drupal cron frequency or use [Elysia Cron][https://www.drupal.org/project/elysia_cron] +necessary, adjust Drupal cron frequency or use [Elysia Cron](https://www.drupal.org/project/elysia_cron) to run module specific cron. ### Get Weather Data via Shell Script (Advanced) @@ -81,13 +81,6 @@ file respectively. If you want to log the output of the script, also update the 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 ``` -##### 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. - ## 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). From e6f418204b0dd3fcbb7d6b8370ba8264ee682ac8 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Tue, 18 Jul 2017 19:56:52 -0500 Subject: [PATCH 09/75] Updated README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 892729e..8a0ff00 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ as much detail as possible, including screenshots and error messages, so that th Project is available under the MIT License. See LICENSE for more information. ## Additional Information -For more information about Bit Second Tech, please visit the +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. From d1689574cecee8a3b9cf2dee8d8466103f6a3ed6 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Tue, 18 Jul 2017 19:57:49 -0500 Subject: [PATCH 10/75] Updated the module description in the info file. --- farmosnws.info | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/farmosnws.info b/farmosnws.info index 688f618..9c66611 100644 --- a/farmosnws.info +++ b/farmosnws.info @@ -1,5 +1,5 @@ name = FarmOS NWS -description = Imports data from the National Weather Service into FarmOS. +description = Imports data from the National Weather Service into Drupal for use by FarmOS. package = FarmOS core = 7.x configure=admin/config/farmosnws From be0c7677dda341e2eeace994e37e5db8833722f0 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Tue, 18 Jul 2017 20:49:03 -0500 Subject: [PATCH 11/75] Updated README. Resolving #2. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8a0ff00..4870b4f 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,8 @@ investment. ## System Requirements * Drupal 7 * FarmOS -* Ubuntu Linux (May run on other Linux versions, but has only be tested with Ubuntu Linux 14.04) -* PHP +* Ubuntu Linux (May run on other Linux versions, but has only be tested with Ubuntu Linux 14.04 LTS) +* PHP 5 * Crontab or other task scheduler capable of running shell scripts ## Setup From 7b83ef526a4e77a8dba8f26e77582008c3aa9ac1 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Tue, 18 Jul 2017 20:51:15 -0500 Subject: [PATCH 12/75] Updated menu function items. Added function to create the feed directory if it doesnt exist. Added module settings validation form. --- farmosnws.module | 83 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 69 insertions(+), 14 deletions(-) diff --git a/farmosnws.module b/farmosnws.module index df80fa3..a5c73bf 100644 --- a/farmosnws.module +++ b/farmosnws.module @@ -9,9 +9,10 @@ function farmosnws_menu() { $items['admin/config/farmosnws'] = array( 'title' => t('FarmOS NWS Settings'), + 'description' => 'Add and remove additional feeds to be pulled by FarmOS NWS', 'page callback' => 'drupal_get_form', - 'page arguments' => 'farmosnws_admin_form', - 'access arguments' => 'administer users', + 'page arguments' => array('farmosnws_admin_form'), + 'access arguments' => array('access administration pages'), 'type' => MENU_NORMAL_ITEM, ); @@ -19,9 +20,9 @@ function farmosnws_menu() { /* $items['admin/config/farmosnws/weather_force'] = array( 'title' => t('FarmOS NWS Data Pull'), - 'description' => 'Pull weather data more frequently that then hourly limit.', + 'description' => 'Pull weather data more frequently than the hourly limit.', 'page callback' => 'farmosnws_get_xml', - 'access arguments' => 'administer users', + 'access arguments' => array('access administration pages'), 'type' => MENU_CALLBACK, ); */ @@ -29,6 +30,13 @@ function farmosnws_menu() { return $items; } +/** + * + * Writes messages to the log as well as the screen based on the message type. + */ +function farmosnws_log($message, $type) { +} + /** * * Implements hook_cron() @@ -50,7 +58,8 @@ function farmosnws_cron() { function farmosnws_get_new_feed() { $cron_last = variable_get('cron_last'); $time_diff = REQUEST_TIME - $cron_last; - + + // if the feed was last pulled over an hour ago, then set value to true. if ($time_diff >= 3600) { $returnval = TRUE; } @@ -60,6 +69,33 @@ function farmosnws_get_new_feed() { return $returnval; } +/** + * + * Check and create if necessary the path where the weather feeds will be stored. + */ +function farmosnws_create_feed_dir($feedpath) { + $mkdirsuccess = NULL; + + // check to see if the feeds directory exists. If not attempt to create it. + if ( is_dir($feedpath == FALSE ) { + $mkdirsuccess = mkdir($weatherfeedsdir, 755); + + // verify directory exists + if ( $feedpath == FALSE ){ + watchdog('farmosnws', 'Unable to create the weather feed directory.', array(), WATCHDOG_ERROR, NULL); + } + else { + watchdog('farmosnws', Created weather feed directory.', array(), WATCHDOG_INFO, NULL); + } // end if + } + else { + // skipping actions + $mkdirsuccess = TRUE; + } // end if + + return $mkdirsuccess; +} + /** * * get the weather data from the NWS @@ -88,15 +124,16 @@ function farmosnws_get_xml() { } // if no errors occur when performing the request else{ - // if the directory doesnt exist, then create it - if ( is_dir($weatherfeedsdir) == FALSE ) { - mkdir($weatherfeedsdir, 775); - watchdog('farmosnws', 'Created weather feed directory.', array(), WATCHDOG_INFO, NULL); - } // end if + // if the directory doesnt exist, then create it with 755 permissions + $direxist = farmosnws_create_feed_dir($weatherfeedsdir); - // save the contents retrieved - file_put_contents($weather_feed_name, $response->data); - watchdog('farmosnws', 'Weather data saved to ' . $weather_feed_name, array(), WATCHDOG_INFO, NULL); + if ( $direxist == FALSE ) { + drupal_set_message("Feed could not be downloaded because the directory does not exist. Please verify that Drupal has write access and try again.", 'error', FALSE); + } // end if + else { + // save the contents retrieved + file_put_contents($weather_feed_name, $response->data); + watchdog('farmosnws', 'Weather data saved to ' . $weather_feed_name, array(), WATCHDOG_INFO, NULL); } } // end foreach } // end function @@ -119,10 +156,28 @@ function farmosnws_admin_form() { '#type' => 'textfield', '#title' => t('Feeds Directory'), '#required' => TRUE, - '#description' => t('The directory where weather feeds should be saved to.'), + '#description' => t('The full directory path to where weather feeds should be saved to.'), '#default_value' => variable_get('farmosnws_weather_feeds_dir'); ); return system_settings_form($form); } +/** + * + * Validate the module settings + */ +function farmosnws_admin_form_validate($form, &$form_state) { + $weatherfeedsdir = $form_state['values']['farmosnws_weather_feeds_dir']; + + $direxist = farmosnws_create_feed_dir($weatherfeedsdir); + if ( $direxist == FALSE ){ + watchdog('farmosnws', 'Unable to create the weather feed directory.', array(), WATCHDOG_ERROR, NULL); + form_set_error('farmosnws_weather_feeds_dir', 'The weather feed directory cannot be created. Please verify that Drupal as write permissions and try again.'); + } + else { + watchdog('farmosnws', Created weather feed directory.', array(), WATCHDOG_INFO, NULL); + } // end if +} // end if + + From 5d8a552c2b20019037eaf55cf1c8be371a52eed9 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Thu, 20 Jul 2017 23:21:19 -0500 Subject: [PATCH 13/75] Updated indentation to Drupal specifications. Created module variable for last time feed was pulled. Removed empty function. Fixed multiple syntax errors. --- farmosnws.module | 59 ++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/farmosnws.module b/farmosnws.module index a5c73bf..f3df5b1 100644 --- a/farmosnws.module +++ b/farmosnws.module @@ -30,21 +30,16 @@ function farmosnws_menu() { return $items; } -/** - * - * Writes messages to the log as well as the screen based on the message type. - */ -function farmosnws_log($message, $type) { -} - /** * * Implements hook_cron() */ function farmosnws_cron() { $pullfeed = farmosnws_get_new_feed(); + if ($pullfeed == TRUE) { farmosnws_get_xml(); + variable_set('farmosnws_cron_last', REQUEST_TIME); } else { watchdog('farmosnws', 'Skipping pulling weather feed.', array(), WATCHDOG_INFO, NULL); @@ -56,7 +51,7 @@ function farmosnws_cron() { * Determine whether to pull the data feed from the NWS based on when cron was last run */ function farmosnws_get_new_feed() { - $cron_last = variable_get('cron_last'); + $cron_last = variable_get('farmosnws_cron_last'); $time_diff = REQUEST_TIME - $cron_last; // if the feed was last pulled over an hour ago, then set value to true. @@ -77,15 +72,15 @@ function farmosnws_create_feed_dir($feedpath) { $mkdirsuccess = NULL; // check to see if the feeds directory exists. If not attempt to create it. - if ( is_dir($feedpath == FALSE ) { + if ( is_dir($feedpath) == FALSE ) { $mkdirsuccess = mkdir($weatherfeedsdir, 755); // verify directory exists if ( $feedpath == FALSE ){ - watchdog('farmosnws', 'Unable to create the weather feed directory.', array(), WATCHDOG_ERROR, NULL); + watchdog('farmosnws', 'Unable to create the weather feed directory.', array(), WATCHDOG_ERROR, NULL); } else { - watchdog('farmosnws', Created weather feed directory.', array(), WATCHDOG_INFO, NULL); + watchdog('farmosnws', 'Created weather feed directory.', array(), WATCHDOG_INFO, NULL); } // end if } else { @@ -109,7 +104,7 @@ function farmosnws_get_xml() { foreach ($location_array as $loc) { $weather_feed_name = $weather_feed_dir . '/' . $uniqid($loc, FALSE) . '.xml'; - $url = "http://w1.weather.gov/xml/current_obs/" . $loc . ".xml" + $url = "http://w1.weather.gov/xml/current_obs/" . $loc . ".xml"; watchdog('farmosnws', 'Getting weather data for ' . $loc, array(), WATCHDOG_INFO, NULL); @@ -119,32 +114,33 @@ function farmosnws_get_xml() { // if error occurs when performing the request if ( $response->error ) { - watchdog('farmosnws', $response->error, array(), WATCHDOG_ERROR, NULL); - drupal_set_message($response->error, 'error', FALSE); + watchdog('farmosnws', $response->error, array(), WATCHDOG_ERROR, NULL); + drupal_set_message($response->error, 'error', FALSE); } // if no errors occur when performing the request else{ - // if the directory doesnt exist, then create it with 755 permissions - $direxist = farmosnws_create_feed_dir($weatherfeedsdir); - - if ( $direxist == FALSE ) { - drupal_set_message("Feed could not be downloaded because the directory does not exist. Please verify that Drupal has write access and try again.", 'error', FALSE); - } // end if - else { - // save the contents retrieved - file_put_contents($weather_feed_name, $response->data); - watchdog('farmosnws', 'Weather data saved to ' . $weather_feed_name, array(), WATCHDOG_INFO, NULL); + // if the directory doesnt exist, then create it with 755 permissions + $direxist = farmosnws_create_feed_dir($weatherfeedsdir); + + if ( $direxist == FALSE ) { + drupal_set_message("Feed could not be downloaded because the directory does not exist. Please verify that Drupal has write access and try again.", 'error', FALSE); + } // end if + else { + // save the contents retrieved + file_put_contents($weather_feed_name, $response->data); + watchdog('farmosnws', 'Weather data saved to ' . $weather_feed_name, array(), WATCHDOG_INFO, NULL); } + } // end else } // end foreach } // end function /** - * + * * Module configuration form */ function farmosnws_admin_form() { $form = array(); - + $form['farmosnws_locations'] = array( '#type' => 'textarea', '#title' => t('Locations'), @@ -157,27 +153,26 @@ function farmosnws_admin_form() { '#title' => t('Feeds Directory'), '#required' => TRUE, '#description' => t('The full directory path to where weather feeds should be saved to.'), - '#default_value' => variable_get('farmosnws_weather_feeds_dir'); + '#default_value' => variable_get('farmosnws_weather_feeds_dir'), ); - + return system_settings_form($form); } /** - * + * * Validate the module settings */ function farmosnws_admin_form_validate($form, &$form_state) { $weatherfeedsdir = $form_state['values']['farmosnws_weather_feeds_dir']; - + $direxist = farmosnws_create_feed_dir($weatherfeedsdir); if ( $direxist == FALSE ){ watchdog('farmosnws', 'Unable to create the weather feed directory.', array(), WATCHDOG_ERROR, NULL); form_set_error('farmosnws_weather_feeds_dir', 'The weather feed directory cannot be created. Please verify that Drupal as write permissions and try again.'); } else { - watchdog('farmosnws', Created weather feed directory.', array(), WATCHDOG_INFO, NULL); + watchdog('farmosnws', 'Created weather feed directory.', array(), WATCHDOG_INFO, NULL); } // end if } // end if - From f187e94c801d712f5ddf7d97459ab0e4764213c6 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Fri, 21 Jul 2017 13:39:45 -0500 Subject: [PATCH 14/75] Added creation of variables on install. Added removal of variables on uninstall. --- farmosnws.install | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 farmosnws.install diff --git a/farmosnws.install b/farmosnws.install new file mode 100644 index 0000000..e998add --- /dev/null +++ b/farmosnws.install @@ -0,0 +1,26 @@ + db_like('farmosnws') . '%')); + + foreach($result as $row) { + variable_del($row->name); + } // end foreach +} // end function + From fe994bc729f4007f3ffb0f9a7305f376c115a25b Mon Sep 17 00:00:00 2001 From: Bit Second Date: Fri, 21 Jul 2017 13:54:57 -0500 Subject: [PATCH 15/75] added version number to info file. --- farmosnws.info | 1 + 1 file changed, 1 insertion(+) diff --git a/farmosnws.info b/farmosnws.info index 9c66611..53f4f8e 100644 --- a/farmosnws.info +++ b/farmosnws.info @@ -2,6 +2,7 @@ name = FarmOS NWS description = Imports data from the National Weather Service into Drupal for use by FarmOS. package = FarmOS core = 7.x +version = 7.x-2.0.alpha1 configure=admin/config/farmosnws dependencies[] = feeds dependencies[] = feeds_fetcher_directory From dcf989ad2bba4a3f373cf23a6d7415b2cbca42d4 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Fri, 21 Jul 2017 14:01:59 -0500 Subject: [PATCH 16/75] Removed creating variables from install hook. Added displaying status message. --- farmosnws.install | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/farmosnws.install b/farmosnws.install index e998add..0b6b05e 100644 --- a/farmosnws.install +++ b/farmosnws.install @@ -5,9 +5,8 @@ * implements hook_install() */ function farmosnws_install() { - variable_set('farmosnws_cron_last', 0); - variable_set('farmosnws_weather_feeds_dir', ''); - variable_set('farmosnws_locations', ''); + // Display message that module needs to be configured. + drupal_set_message('Visit the FarmOS NWS ' . l('settings page', 'admin/config/farmosnws') . ' to configure the module.', 'warning', FALSE); } /** From 2a5a092352977b5d75ce89efc1caaf08824f40c0 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Fri, 21 Jul 2017 14:53:33 -0500 Subject: [PATCH 17/75] Added watchdog for logging --- farmosnws.install | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/farmosnws.install b/farmosnws.install index 0b6b05e..de2d28d 100644 --- a/farmosnws.install +++ b/farmosnws.install @@ -7,6 +7,8 @@ function farmosnws_install() { // Display message that module needs to be configured. drupal_set_message('Visit the FarmOS NWS ' . l('settings page', 'admin/config/farmosnws') . ' to configure the module.', 'warning', FALSE); + + watchdog('farmosnws', 'Installed module.', array(), WATCHDOG_NOTICE, NULL); } /** @@ -21,5 +23,9 @@ function farmosnws_uninstall() { foreach($result as $row) { variable_del($row->name); } // end foreach + + watchdog('farmosnws', 'Deleted ' . $result->rowCount() . ' variable(s).', array(), WATCHDOG_INFO, NULL); + + watchdog('farmosnws', 'Uninstalled module.', array(), WATCHDOG_NOTICE, NULL); } // end function From cd444b0724738bb30ca0c3e1296832c285beac02 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Fri, 21 Jul 2017 15:29:55 -0500 Subject: [PATCH 18/75] Updated indenting --- farmosnws.module | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/farmosnws.module b/farmosnws.module index f3df5b1..c8cf841 100644 --- a/farmosnws.module +++ b/farmosnws.module @@ -77,10 +77,10 @@ function farmosnws_create_feed_dir($feedpath) { // verify directory exists if ( $feedpath == FALSE ){ - watchdog('farmosnws', 'Unable to create the weather feed directory.', array(), WATCHDOG_ERROR, NULL); + watchdog('farmosnws', 'Unable to create the weather feed directory.', array(), WATCHDOG_ERROR, NULL); } else { - watchdog('farmosnws', 'Created weather feed directory.', array(), WATCHDOG_INFO, NULL); + watchdog('farmosnws', 'Created weather feed directory.', array(), WATCHDOG_INFO, NULL); } // end if } else { @@ -114,22 +114,22 @@ function farmosnws_get_xml() { // if error occurs when performing the request if ( $response->error ) { - watchdog('farmosnws', $response->error, array(), WATCHDOG_ERROR, NULL); - drupal_set_message($response->error, 'error', FALSE); + watchdog('farmosnws', $response->error, array(), WATCHDOG_ERROR, NULL); + drupal_set_message($response->error, 'error', FALSE); } // if no errors occur when performing the request else{ - // if the directory doesnt exist, then create it with 755 permissions - $direxist = farmosnws_create_feed_dir($weatherfeedsdir); - - if ( $direxist == FALSE ) { - drupal_set_message("Feed could not be downloaded because the directory does not exist. Please verify that Drupal has write access and try again.", 'error', FALSE); - } // end if - else { - // save the contents retrieved - file_put_contents($weather_feed_name, $response->data); - watchdog('farmosnws', 'Weather data saved to ' . $weather_feed_name, array(), WATCHDOG_INFO, NULL); - } + // if the directory doesnt exist, then create it with 755 permissions + $direxist = farmosnws_create_feed_dir($weatherfeedsdir); + + if ( $direxist == FALSE ) { + drupal_set_message("Feed could not be downloaded because the directory does not exist. Please verify that Drupal has write access and try again.", 'error', FALSE); + } // end if + else { + // save the contents retrieved + file_put_contents($weather_feed_name, $response->data); + watchdog('farmosnws', 'Weather data saved to ' . $weather_feed_name, array(), WATCHDOG_INFO, NULL); + } } // end else } // end foreach } // end function From a6d1b4425064df946ca9cafd74c6a956b600ca71 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Fri, 8 Sep 2017 20:14:38 -0500 Subject: [PATCH 19/75] Added importing weather feed. --- farmosnws.features.field_base.inc | 155 ++++++++++++ farmosnws.features.field_instance.inc | 337 ++++++++++++++++++++++++++ farmosnws.features.inc | 35 +++ farmosnws.features.menu_custom.inc | 25 ++ farmosnws.features.menu_links.inc | 55 +++++ farmosnws.feeds_importer_default.inc | 159 ++++++++++++ farmosnws.info | 42 +++- farmosnws.install | 31 --- farmosnws.module | 177 +------------- farmosnws.strongarm.inc | 69 ++++++ 10 files changed, 873 insertions(+), 212 deletions(-) create mode 100644 farmosnws.features.field_base.inc create mode 100644 farmosnws.features.field_instance.inc create mode 100644 farmosnws.features.inc create mode 100644 farmosnws.features.menu_custom.inc create mode 100644 farmosnws.features.menu_links.inc create mode 100644 farmosnws.feeds_importer_default.inc delete mode 100644 farmosnws.install create mode 100644 farmosnws.strongarm.inc diff --git a/farmosnws.features.field_base.inc b/farmosnws.features.field_base.inc new file mode 100644 index 0000000..6a6f1b1 --- /dev/null +++ b/farmosnws.features.field_base.inc @@ -0,0 +1,155 @@ + 1, + 'cardinality' => 1, + 'deleted' => 0, + 'entity_types' => array(), + 'field_name' => 'field_wthr_location', + 'indexes' => array( + 'format' => array( + 0 => 'format', + ), + ), + 'locked' => 0, + 'module' => 'text', + 'settings' => array( + 'max_length' => 255, + ), + 'translatable' => 0, + 'type' => 'text', + ); + + // Exported field_base: 'field_wthr_rel_humidity'. + $field_bases['field_wthr_rel_humidity'] = array( + 'active' => 1, + 'cardinality' => 1, + 'deleted' => 0, + 'entity_types' => array(), + 'field_name' => 'field_wthr_rel_humidity', + 'indexes' => array(), + 'locked' => 0, + 'module' => 'number', + 'settings' => array( + 'decimal_separator' => '.', + 'precision' => 10, + 'scale' => 5, + ), + 'translatable' => 0, + 'type' => 'number_decimal', + ); + + // Exported field_base: 'field_wthr_temp_f'. + $field_bases['field_wthr_temp_f'] = array( + 'active' => 1, + 'cardinality' => 1, + 'deleted' => 0, + 'entity_types' => array(), + 'field_name' => 'field_wthr_temp_f', + 'indexes' => array(), + 'locked' => 0, + 'module' => 'number', + 'settings' => array( + 'decimal_separator' => '.', + 'precision' => 10, + 'scale' => 4, + ), + 'translatable' => 0, + 'type' => 'number_decimal', + ); + + // Exported field_base: 'field_wthr_time_string'. + $field_bases['field_wthr_time_string'] = array( + 'active' => 1, + 'cardinality' => 1, + 'deleted' => 0, + 'entity_types' => array(), + 'field_name' => 'field_wthr_time_string', + 'indexes' => array( + 'format' => array( + 0 => 'format', + ), + ), + 'locked' => 0, + 'module' => 'text', + 'settings' => array( + 'max_length' => 255, + ), + 'translatable' => 0, + 'type' => 'text', + ); + + // Exported field_base: 'field_wthr_weather'. + $field_bases['field_wthr_weather'] = array( + 'active' => 1, + 'cardinality' => 1, + 'deleted' => 0, + 'entity_types' => array(), + 'field_name' => 'field_wthr_weather', + 'indexes' => array( + 'format' => array( + 0 => 'format', + ), + ), + 'locked' => 0, + 'module' => 'text', + 'settings' => array( + 'max_length' => 255, + ), + 'translatable' => 0, + 'type' => 'text', + ); + + // Exported field_base: 'field_wthr_wind_dir'. + $field_bases['field_wthr_wind_dir'] = array( + 'active' => 1, + 'cardinality' => 1, + 'deleted' => 0, + 'entity_types' => array(), + 'field_name' => 'field_wthr_wind_dir', + 'indexes' => array( + 'format' => array( + 0 => 'format', + ), + ), + 'locked' => 0, + 'module' => 'text', + 'settings' => array( + 'max_length' => 255, + ), + 'translatable' => 0, + 'type' => 'text', + ); + + // Exported field_base: 'field_wthr_wind_mph'. + $field_bases['field_wthr_wind_mph'] = array( + 'active' => 1, + 'cardinality' => 1, + 'deleted' => 0, + 'entity_types' => array(), + 'field_name' => 'field_wthr_wind_mph', + 'indexes' => array(), + 'locked' => 0, + 'module' => 'number', + 'settings' => array( + 'decimal_separator' => '.', + 'precision' => 10, + 'scale' => 5, + ), + 'translatable' => 0, + 'type' => 'number_decimal', + ); + + return $field_bases; +} diff --git a/farmosnws.features.field_instance.inc b/farmosnws.features.field_instance.inc new file mode 100644 index 0000000..1780343 --- /dev/null +++ b/farmosnws.features.field_instance.inc @@ -0,0 +1,337 @@ + 'imported_weather_conditions', + 'default_value' => NULL, + 'deleted' => 0, + 'description' => '', + 'display' => array( + 'default' => array( + 'label' => 'above', + 'module' => 'text', + 'settings' => array(), + 'type' => 'text_default', + 'weight' => 8, + ), + 'teaser' => array( + 'label' => 'above', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 0, + ), + ), + 'entity_type' => 'node', + 'field_name' => 'field_wthr_location', + 'label' => 'Location', + 'required' => 0, + 'settings' => array( + 'text_processing' => 0, + 'user_register_form' => FALSE, + ), + 'widget' => array( + 'active' => 1, + 'module' => 'text', + 'settings' => array( + 'size' => 60, + ), + 'type' => 'text_textfield', + 'weight' => 40, + ), + ); + + // Exported field_instance: + // 'node-imported_weather_conditions-field_wthr_rel_humidity'. + $field_instances['node-imported_weather_conditions-field_wthr_rel_humidity'] = array( + 'bundle' => 'imported_weather_conditions', + 'default_value' => array( + 0 => array( + 'value' => 0, + ), + ), + 'deleted' => 0, + 'description' => '', + 'display' => array( + 'default' => array( + 'label' => 'above', + 'module' => 'number', + 'settings' => array( + 'decimal_separator' => '.', + 'prefix_suffix' => TRUE, + 'scale' => 2, + 'thousand_separator' => '', + ), + 'type' => 'number_decimal', + 'weight' => 2, + ), + 'teaser' => array( + 'label' => 'above', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 0, + ), + ), + 'entity_type' => 'node', + 'field_name' => 'field_wthr_rel_humidity', + 'label' => 'Humidity', + 'required' => 0, + 'settings' => array( + 'max' => 100, + 'min' => 0, + 'prefix' => '', + 'suffix' => '%', + 'user_register_form' => FALSE, + ), + 'widget' => array( + 'active' => 0, + 'module' => 'number', + 'settings' => array(), + 'type' => 'number', + 'weight' => 33, + ), + ); + + // Exported field_instance: + // 'node-imported_weather_conditions-field_wthr_temp_f'. + $field_instances['node-imported_weather_conditions-field_wthr_temp_f'] = array( + 'bundle' => 'imported_weather_conditions', + 'default_value' => NULL, + 'deleted' => 0, + 'description' => '', + 'display' => array( + 'default' => array( + 'label' => 'above', + 'module' => 'number', + 'settings' => array( + 'decimal_separator' => '.', + 'prefix_suffix' => TRUE, + 'scale' => 2, + 'thousand_separator' => '', + ), + 'type' => 'number_decimal', + 'weight' => 1, + ), + 'teaser' => array( + 'label' => 'above', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 0, + ), + ), + 'entity_type' => 'node', + 'field_name' => 'field_wthr_temp_f', + 'label' => 'Temperature F', + 'required' => 0, + 'settings' => array( + 'max' => '', + 'min' => '', + 'prefix' => '', + 'suffix' => 'F', + 'user_register_form' => FALSE, + ), + 'widget' => array( + 'active' => 0, + 'module' => 'number', + 'settings' => array(), + 'type' => 'number', + 'weight' => 32, + ), + ); + + // Exported field_instance: + // 'node-imported_weather_conditions-field_wthr_time_string'. + $field_instances['node-imported_weather_conditions-field_wthr_time_string'] = array( + 'bundle' => 'imported_weather_conditions', + 'default_value' => NULL, + 'deleted' => 0, + 'description' => '', + 'display' => array( + 'default' => array( + 'label' => 'above', + 'module' => 'text', + 'settings' => array(), + 'type' => 'text_default', + 'weight' => 4, + ), + 'teaser' => array( + 'label' => 'above', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 0, + ), + ), + 'entity_type' => 'node', + 'field_name' => 'field_wthr_time_string', + 'label' => 'Time String', + 'required' => 0, + 'settings' => array( + 'text_processing' => 0, + 'user_register_form' => FALSE, + ), + 'widget' => array( + 'active' => 1, + 'module' => 'text', + 'settings' => array( + 'size' => 60, + ), + 'type' => 'text_textfield', + 'weight' => 35, + ), + ); + + // Exported field_instance: + // 'node-imported_weather_conditions-field_wthr_weather'. + $field_instances['node-imported_weather_conditions-field_wthr_weather'] = array( + 'bundle' => 'imported_weather_conditions', + 'default_value' => NULL, + 'deleted' => 0, + 'description' => '', + 'display' => array( + 'default' => array( + 'label' => 'above', + 'module' => 'text', + 'settings' => array(), + 'type' => 'text_default', + 'weight' => 3, + ), + 'teaser' => array( + 'label' => 'above', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 0, + ), + ), + 'entity_type' => 'node', + 'field_name' => 'field_wthr_weather', + 'label' => 'Weather', + 'required' => 0, + 'settings' => array( + 'text_processing' => 0, + 'user_register_form' => FALSE, + ), + 'widget' => array( + 'active' => 1, + 'module' => 'text', + 'settings' => array( + 'size' => 60, + ), + 'type' => 'text_textfield', + 'weight' => 34, + ), + ); + + // Exported field_instance: + // 'node-imported_weather_conditions-field_wthr_wind_dir'. + $field_instances['node-imported_weather_conditions-field_wthr_wind_dir'] = array( + 'bundle' => 'imported_weather_conditions', + 'default_value' => NULL, + 'deleted' => 0, + 'description' => '', + 'display' => array( + 'default' => array( + 'label' => 'above', + 'module' => 'text', + 'settings' => array(), + 'type' => 'text_default', + 'weight' => 5, + ), + 'teaser' => array( + 'label' => 'above', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 0, + ), + ), + 'entity_type' => 'node', + 'field_name' => 'field_wthr_wind_dir', + 'label' => 'Wind Direction', + 'required' => 0, + 'settings' => array( + 'text_processing' => 0, + 'user_register_form' => FALSE, + ), + 'widget' => array( + 'active' => 1, + 'module' => 'text', + 'settings' => array( + 'size' => 60, + ), + 'type' => 'text_textfield', + 'weight' => 36, + ), + ); + + // Exported field_instance: + // 'node-imported_weather_conditions-field_wthr_wind_mph'. + $field_instances['node-imported_weather_conditions-field_wthr_wind_mph'] = array( + 'bundle' => 'imported_weather_conditions', + 'default_value' => array( + 0 => array( + 'value' => 0, + ), + ), + 'deleted' => 0, + 'description' => '', + 'display' => array( + 'default' => array( + 'label' => 'above', + 'module' => 'number', + 'settings' => array( + 'decimal_separator' => '.', + 'prefix_suffix' => TRUE, + 'scale' => 2, + 'thousand_separator' => '', + ), + 'type' => 'number_decimal', + 'weight' => 6, + ), + 'teaser' => array( + 'label' => 'above', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 0, + ), + ), + 'entity_type' => 'node', + 'field_name' => 'field_wthr_wind_mph', + 'label' => 'Wind MPH', + 'required' => 0, + 'settings' => array( + 'max' => '', + 'min' => 0, + 'prefix' => '', + 'suffix' => 'MPH', + 'user_register_form' => FALSE, + ), + 'widget' => array( + 'active' => 0, + 'module' => 'number', + 'settings' => array(), + 'type' => 'number', + 'weight' => 37, + ), + ); + + // Translatables + // Included for use with string extractors like potx. + t('Humidity'); + t('Location'); + t('Temperature F'); + t('Time String'); + t('Weather'); + t('Wind Direction'); + t('Wind MPH'); + + return $field_instances; +} diff --git a/farmosnws.features.inc b/farmosnws.features.inc new file mode 100644 index 0000000..157fa0f --- /dev/null +++ b/farmosnws.features.inc @@ -0,0 +1,35 @@ + "1"); + } + if ($module == "strongarm" && $api == "strongarm") { + return array("version" => "1"); + } +} + +/** + * Implements hook_node_info(). + */ +function farmosnws_node_info() { + $items = array( + 'imported_weather_conditions' => array( + 'name' => t('Imported Weather Conditions'), + 'base' => 'node_content', + 'description' => '', + 'has_title' => '1', + 'title_label' => t('Title'), + 'help' => '', + ), + ); + drupal_alter('node_info', $items); + return $items; +} diff --git a/farmosnws.features.menu_custom.inc b/farmosnws.features.menu_custom.inc new file mode 100644 index 0000000..90b7bb5 --- /dev/null +++ b/farmosnws.features.menu_custom.inc @@ -0,0 +1,25 @@ + 'farm', + 'title' => 'Farm', + 'description' => 'Farm management links', + ); + // Translatables + // Included for use with string extractors like potx. + t('Farm'); + t('Farm management links'); + + return $menus; +} diff --git a/farmosnws.features.menu_links.inc b/farmosnws.features.menu_links.inc new file mode 100644 index 0000000..6b329b1 --- /dev/null +++ b/farmosnws.features.menu_links.inc @@ -0,0 +1,55 @@ + 'farm', + 'link_path' => 'weather-history', + 'router_path' => 'weather-history', + 'link_title' => 'Weather', + 'options' => array( + 'identifier' => 'farm_weather:weather-history', + ), + 'module' => 'system', + 'hidden' => 0, + 'external' => 0, + 'has_children' => 0, + 'expanded' => 0, + 'weight' => 0, + 'customized' => 0, + ); + // Exported menu link: navigation_imported-weather-conditions:node/add/imported-weather-conditions. + $menu_links['navigation_imported-weather-conditions:node/add/imported-weather-conditions'] = array( + 'menu_name' => 'navigation', + 'link_path' => 'node/add/imported-weather-conditions', + 'router_path' => 'node/add/imported-weather-conditions', + 'link_title' => 'Imported Weather Conditions', + 'options' => array( + 'identifier' => 'navigation_imported-weather-conditions:node/add/imported-weather-conditions', + ), + 'module' => 'system', + 'hidden' => 0, + 'external' => 0, + 'has_children' => 0, + 'expanded' => 0, + 'weight' => 0, + 'customized' => 0, + 'parent_identifier' => 'navigation_add-content:node/add', + ); + + // Translatables + // Included for use with string extractors like potx. + t('Imported Weather Conditions'); + t('Weather'); + + return $menu_links; +} diff --git a/farmosnws.feeds_importer_default.inc b/farmosnws.feeds_importer_default.inc new file mode 100644 index 0000000..ea7f98b --- /dev/null +++ b/farmosnws.feeds_importer_default.inc @@ -0,0 +1,159 @@ +disabled = FALSE; /* Edit this to true to make a default feeds_importer disabled initially */ + $feeds_importer->api_version = 1; + $feeds_importer->id = 'import_weather_conditions_kmgm'; + $feeds_importer->config = array( + 'name' => 'Import Weather Conditions', + 'description' => 'Import weather conditions from the National Weather Service', + 'fetcher' => array( + 'plugin_key' => 'feeds_fetcher_directory_fetcher', + 'config' => array( + 'recursive' => 1, + 'directory' => 'public://curweather', + 'filemask' => '/\\.xml$/', + 'updated_files' => 1, + 'after_processed' => '0', + 'move_to_folder' => '', + ), + ), + 'parser' => array( + 'plugin_key' => 'FeedsXPathParserXML', + 'config' => array( + 'sources' => array( + 'xpathparser:0' => 'location', + 'xpathparser:1' => 'observation_time_rfc822', + 'xpathparser:2' => 'relative_humidity', + 'xpathparser:3' => 'temp_f', + 'xpathparser:4' => 'observation_time_rfc822', + 'xpathparser:5' => 'wind_dir', + 'xpathparser:6' => 'wind_mph', + 'xpathparser:7' => 'weather', + 'xpathparser:8' => 'observation_time_rfc822', + 'xpathparser:9' => 'location', + ), + 'rawXML' => array( + 'xpathparser:0' => 0, + 'xpathparser:1' => 0, + 'xpathparser:2' => 0, + 'xpathparser:3' => 0, + 'xpathparser:4' => 0, + 'xpathparser:5' => 0, + 'xpathparser:6' => 0, + 'xpathparser:7' => 0, + 'xpathparser:8' => 0, + 'xpathparser:9' => 0, + ), + 'context' => '/current_observation', + 'exp' => array( + 'errors' => 0, + 'debug' => array( + 'context' => 0, + 'xpathparser:0' => 0, + 'xpathparser:1' => 0, + 'xpathparser:2' => 0, + 'xpathparser:3' => 0, + 'xpathparser:4' => 0, + 'xpathparser:5' => 0, + 'xpathparser:6' => 0, + 'xpathparser:7' => 0, + 'xpathparser:8' => 0, + 'xpathparser:9' => 0, + ), + ), + 'allow_override' => 1, + ), + ), + 'processor' => array( + 'plugin_key' => 'FeedsNodeProcessor', + 'config' => array( + 'expire' => '-1', + 'author' => '47', + 'authorize' => 0, + 'mappings' => array( + 0 => array( + 'source' => 'xpathparser:1', + 'target' => 'created', + 'unique' => FALSE, + 'language' => 'und', + ), + 1 => array( + 'source' => 'xpathparser:2', + 'target' => 'field_wthr_rel_humidity', + 'unique' => FALSE, + 'language' => 'und', + ), + 2 => array( + 'source' => 'xpathparser:3', + 'target' => 'field_wthr_temp_f', + 'unique' => FALSE, + 'language' => 'und', + ), + 3 => array( + 'source' => 'xpathparser:4', + 'target' => 'field_wthr_time_string', + 'unique' => FALSE, + 'language' => 'und', + ), + 4 => array( + 'source' => 'xpathparser:5', + 'target' => 'field_wthr_wind_dir', + 'unique' => FALSE, + 'language' => 'und', + ), + 5 => array( + 'source' => 'xpathparser:6', + 'target' => 'field_wthr_wind_mph', + 'unique' => FALSE, + 'language' => 'und', + ), + 6 => array( + 'source' => 'xpathparser:7', + 'target' => 'field_wthr_weather', + 'unique' => FALSE, + 'language' => 'und', + ), + 7 => array( + 'source' => 'xpathparser:8', + 'target' => 'title', + 'unique' => FALSE, + 'language' => 'und', + ), + 8 => array( + 'source' => 'xpathparser:9', + 'target' => 'field_wthr_location', + 'unique' => FALSE, + 'language' => 'und', + ), + ), + 'insert_new' => '1', + 'update_existing' => '1', + 'update_non_existent' => 'skip', + 'input_format' => 'plain_text', + 'skip_hash_check' => 0, + 'bundle' => 'imported_weather_conditions', + 'language' => 'und', + ), + ), + 'content_type' => '', + 'update' => 0, + 'import_period' => '3600', + 'expire_period' => 3600, + 'import_on_create' => 1, + 'process_in_background' => 0, + ); + $export['import_weather_conditions_kmgm'] = $feeds_importer; + + return $export; +} diff --git a/farmosnws.info b/farmosnws.info index 53f4f8e..b9d8f6d 100644 --- a/farmosnws.info +++ b/farmosnws.info @@ -1,13 +1,41 @@ name = FarmOS NWS description = Imports data from the National Weather Service into Drupal for use by FarmOS. -package = FarmOS core = 7.x -version = 7.x-2.0.alpha1 -configure=admin/config/farmosnws +package = farmOS (beta) +version = 7.x-2.0-beta2 +dependencies[] = ctools +dependencies[] = features dependencies[] = feeds dependencies[] = feeds_fetcher_directory dependencies[] = feeds_xpathparser -dependencies[] = rules -files[] = farmosnws.install -files[] = farmosnws.module - +dependencies[] = menu +dependencies[] = number +dependencies[] = strongarm +dependencies[] = text +features[ctools][] = feeds:feeds_importer_default:1 +features[ctools][] = strongarm:strongarm:1 +features[features_api][] = api:2 +features[feeds_importer][] = import_weather_conditions_kmgm +features[field_base][] = field_wthr_location +features[field_base][] = field_wthr_rel_humidity +features[field_base][] = field_wthr_temp_f +features[field_base][] = field_wthr_time_string +features[field_base][] = field_wthr_weather +features[field_base][] = field_wthr_wind_dir +features[field_base][] = field_wthr_wind_mph +features[field_instance][] = node-imported_weather_conditions-field_wthr_location +features[field_instance][] = node-imported_weather_conditions-field_wthr_rel_humidity +features[field_instance][] = node-imported_weather_conditions-field_wthr_temp_f +features[field_instance][] = node-imported_weather_conditions-field_wthr_time_string +features[field_instance][] = node-imported_weather_conditions-field_wthr_weather +features[field_instance][] = node-imported_weather_conditions-field_wthr_wind_dir +features[field_instance][] = node-imported_weather_conditions-field_wthr_wind_mph +features[menu_custom][] = farm +features[node][] = imported_weather_conditions +features[variable][] = field_bundle_settings_node__imported_weather_conditions +features[variable][] = menu_options_imported_weather_conditions +features[variable][] = menu_parent_imported_weather_conditions +features[variable][] = node_options_imported_weather_conditions +features[variable][] = node_preview_imported_weather_conditions +features[variable][] = node_submitted_imported_weather_conditions +project path = sites/all/modules/custom diff --git a/farmosnws.install b/farmosnws.install deleted file mode 100644 index de2d28d..0000000 --- a/farmosnws.install +++ /dev/null @@ -1,31 +0,0 @@ - db_like('farmosnws') . '%')); - - foreach($result as $row) { - variable_del($row->name); - } // end foreach - - watchdog('farmosnws', 'Deleted ' . $result->rowCount() . ' variable(s).', array(), WATCHDOG_INFO, NULL); - - watchdog('farmosnws', 'Uninstalled module.', array(), WATCHDOG_NOTICE, NULL); -} // end function - diff --git a/farmosnws.module b/farmosnws.module index c8cf841..6d16263 100644 --- a/farmosnws.module +++ b/farmosnws.module @@ -1,178 +1,7 @@ t('FarmOS NWS Settings'), - 'description' => 'Add and remove additional feeds to be pulled by FarmOS NWS', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('farmosnws_admin_form'), - 'access arguments' => array('access administration pages'), - 'type' => MENU_NORMAL_ITEM, - ); - - // TO DO: add call to bypass cron ron - /* - $items['admin/config/farmosnws/weather_force'] = array( - 'title' => t('FarmOS NWS Data Pull'), - 'description' => 'Pull weather data more frequently than the hourly limit.', - 'page callback' => 'farmosnws_get_xml', - 'access arguments' => array('access administration pages'), - 'type' => MENU_CALLBACK, - ); - */ - - return $items; -} - -/** - * - * Implements hook_cron() - */ -function farmosnws_cron() { - $pullfeed = farmosnws_get_new_feed(); - - if ($pullfeed == TRUE) { - farmosnws_get_xml(); - variable_set('farmosnws_cron_last', REQUEST_TIME); - } - else { - watchdog('farmosnws', 'Skipping pulling weather feed.', array(), WATCHDOG_INFO, NULL); - } -} - -/** - * - * Determine whether to pull the data feed from the NWS based on when cron was last run - */ -function farmosnws_get_new_feed() { - $cron_last = variable_get('farmosnws_cron_last'); - $time_diff = REQUEST_TIME - $cron_last; - - // if the feed was last pulled over an hour ago, then set value to true. - if ($time_diff >= 3600) { - $returnval = TRUE; - } - else { - $returnval = FALSE; - } - return $returnval; -} - -/** - * - * Check and create if necessary the path where the weather feeds will be stored. - */ -function farmosnws_create_feed_dir($feedpath) { - $mkdirsuccess = NULL; - - // check to see if the feeds directory exists. If not attempt to create it. - if ( is_dir($feedpath) == FALSE ) { - $mkdirsuccess = mkdir($weatherfeedsdir, 755); - - // verify directory exists - if ( $feedpath == FALSE ){ - watchdog('farmosnws', 'Unable to create the weather feed directory.', array(), WATCHDOG_ERROR, NULL); - } - else { - watchdog('farmosnws', 'Created weather feed directory.', array(), WATCHDOG_INFO, NULL); - } // end if - } - else { - // skipping actions - $mkdirsuccess = TRUE; - } // end if - - return $mkdirsuccess; -} - -/** - * - * get the weather data from the NWS - */ -function farmosnws_get_xml() { - $weatherfeedsdir = variable_get('farmosnws_weather_feeds_dir'); - - $locations = variable_get('farmosnws_locations', ''); - $location_array = explode("\n", $locations); - $location_count = count($location_array); - - foreach ($location_array as $loc) { - $weather_feed_name = $weather_feed_dir . '/' . $uniqid($loc, FALSE) . '.xml'; - $url = "http://w1.weather.gov/xml/current_obs/" . $loc . ".xml"; - - watchdog('farmosnws', 'Getting weather data for ' . $loc, array(), WATCHDOG_INFO, NULL); - - $response = drupal_http_request($url, array()); - - watchdog('farmosnws', 'Response code: ' . $response->code, array(), WATCHDOG_INFO, NULL); - - // if error occurs when performing the request - if ( $response->error ) { - watchdog('farmosnws', $response->error, array(), WATCHDOG_ERROR, NULL); - drupal_set_message($response->error, 'error', FALSE); - } - // if no errors occur when performing the request - else{ - // if the directory doesnt exist, then create it with 755 permissions - $direxist = farmosnws_create_feed_dir($weatherfeedsdir); - - if ( $direxist == FALSE ) { - drupal_set_message("Feed could not be downloaded because the directory does not exist. Please verify that Drupal has write access and try again.", 'error', FALSE); - } // end if - else { - // save the contents retrieved - file_put_contents($weather_feed_name, $response->data); - watchdog('farmosnws', 'Weather data saved to ' . $weather_feed_name, array(), WATCHDOG_INFO, NULL); - } - } // end else - } // end foreach -} // end function - -/** - * - * Module configuration form - */ -function farmosnws_admin_form() { - $form = array(); - - $form['farmosnws_locations'] = array( - '#type' => 'textarea', - '#title' => t('Locations'), - '#description' => t('Enter the locations that you would like weather data pulled for. Each location must be entered on a separate line.'), - '#required' => TRUE, - '#default_value' => variable_get('farmosnws_locations'), - ); - $form['farmosnws_weather_feeds_dir'] = array( - '#type' => 'textfield', - '#title' => t('Feeds Directory'), - '#required' => TRUE, - '#description' => t('The full directory path to where weather feeds should be saved to.'), - '#default_value' => variable_get('farmosnws_weather_feeds_dir'), - ); - - return system_settings_form($form); -} - /** - * - * Validate the module settings + * @file + * Code for the FarmOS NWS feature. */ -function farmosnws_admin_form_validate($form, &$form_state) { - $weatherfeedsdir = $form_state['values']['farmosnws_weather_feeds_dir']; - - $direxist = farmosnws_create_feed_dir($weatherfeedsdir); - if ( $direxist == FALSE ){ - watchdog('farmosnws', 'Unable to create the weather feed directory.', array(), WATCHDOG_ERROR, NULL); - form_set_error('farmosnws_weather_feeds_dir', 'The weather feed directory cannot be created. Please verify that Drupal as write permissions and try again.'); - } - else { - watchdog('farmosnws', 'Created weather feed directory.', array(), WATCHDOG_INFO, NULL); - } // end if -} // end if +include_once 'farmosnws.features.inc'; diff --git a/farmosnws.strongarm.inc b/farmosnws.strongarm.inc new file mode 100644 index 0000000..54b1e70 --- /dev/null +++ b/farmosnws.strongarm.inc @@ -0,0 +1,69 @@ +disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ + $strongarm->api_version = 1; + $strongarm->name = 'field_bundle_settings_node__imported_weather_conditions'; + $strongarm->value = array( + 'view_modes' => array(), + 'extra_fields' => array( + 'form' => array( + 'title' => array( + 'weight' => '-5', + ), + 'path' => array( + 'weight' => '30', + ), + ), + 'display' => array(), + ), + ); + $export['field_bundle_settings_node__imported_weather_conditions'] = $strongarm; + + $strongarm = new stdClass(); + $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ + $strongarm->api_version = 1; + $strongarm->name = 'menu_options_imported_weather_conditions'; + $strongarm->value = array(); + $export['menu_options_imported_weather_conditions'] = $strongarm; + + $strongarm = new stdClass(); + $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ + $strongarm->api_version = 1; + $strongarm->name = 'menu_parent_imported_weather_conditions'; + $strongarm->value = 'main-menu:0'; + $export['menu_parent_imported_weather_conditions'] = $strongarm; + + $strongarm = new stdClass(); + $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ + $strongarm->api_version = 1; + $strongarm->name = 'node_options_imported_weather_conditions'; + $strongarm->value = array(); + $export['node_options_imported_weather_conditions'] = $strongarm; + + $strongarm = new stdClass(); + $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ + $strongarm->api_version = 1; + $strongarm->name = 'node_preview_imported_weather_conditions'; + $strongarm->value = '0'; + $export['node_preview_imported_weather_conditions'] = $strongarm; + + $strongarm = new stdClass(); + $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ + $strongarm->api_version = 1; + $strongarm->name = 'node_submitted_imported_weather_conditions'; + $strongarm->value = 1; + $export['node_submitted_imported_weather_conditions'] = $strongarm; + + return $export; +} From 055b2d55eefb678a4aa333ffd61332f93308fdf2 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Fri, 8 Sep 2017 20:15:34 -0500 Subject: [PATCH 20/75] Created rule to pull data from NWS --- farmosnws.features.inc | 7 +++ farmosnws.info | 9 ++- farmosnws.rules_defaults.inc | 35 ++++++++++++ farmosnws.views_default.inc | 105 +++++++++++++++++++++++++++++++++++ 4 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 farmosnws.rules_defaults.inc create mode 100644 farmosnws.views_default.inc diff --git a/farmosnws.features.inc b/farmosnws.features.inc index 157fa0f..4bd9dc7 100644 --- a/farmosnws.features.inc +++ b/farmosnws.features.inc @@ -16,6 +16,13 @@ function farmosnws_ctools_plugin_api($module = NULL, $api = NULL) { } } +/** + * Implements hook_views_api(). + */ +function farmosnws_views_api($module = NULL, $api = NULL) { + return array("api" => "3.0"); +} + /** * Implements hook_node_info(). */ diff --git a/farmosnws.info b/farmosnws.info index b9d8f6d..5f47c65 100644 --- a/farmosnws.info +++ b/farmosnws.info @@ -2,7 +2,7 @@ name = FarmOS NWS description = Imports data from the National Weather Service into Drupal for use by FarmOS. core = 7.x package = farmOS (beta) -version = 7.x-2.0-beta2 +version = 7.x-2.0-beta3 dependencies[] = ctools dependencies[] = features dependencies[] = feeds @@ -10,10 +10,13 @@ dependencies[] = feeds_fetcher_directory dependencies[] = feeds_xpathparser dependencies[] = menu dependencies[] = number +dependencies[] = rules_download dependencies[] = strongarm dependencies[] = text +dependencies[] = views features[ctools][] = feeds:feeds_importer_default:1 features[ctools][] = strongarm:strongarm:1 +features[ctools][] = views:views_default:3.0 features[features_api][] = api:2 features[feeds_importer][] = import_weather_conditions_kmgm features[field_base][] = field_wthr_location @@ -32,10 +35,14 @@ features[field_instance][] = node-imported_weather_conditions-field_wthr_wind_di features[field_instance][] = node-imported_weather_conditions-field_wthr_wind_mph features[menu_custom][] = farm features[node][] = imported_weather_conditions +features[rules_config][] = rules_pull_data_from_nws features[variable][] = field_bundle_settings_node__imported_weather_conditions features[variable][] = menu_options_imported_weather_conditions features[variable][] = menu_parent_imported_weather_conditions features[variable][] = node_options_imported_weather_conditions features[variable][] = node_preview_imported_weather_conditions features[variable][] = node_submitted_imported_weather_conditions +features[views_view][] = weather_history +features_exclude[dependencies][entity] = entity +features_exclude[dependencies][rules] = rules project path = sites/all/modules/custom diff --git a/farmosnws.rules_defaults.inc b/farmosnws.rules_defaults.inc new file mode 100644 index 0000000..77c964d --- /dev/null +++ b/farmosnws.rules_defaults.inc @@ -0,0 +1,35 @@ +name = 'weather_history'; + $view->description = ''; + $view->tag = 'default'; + $view->base_table = 'node'; + $view->human_name = 'Weather History'; + $view->core = 7; + $view->api_version = '3.0'; + $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */ + + /* Display: Master */ + $handler = $view->new_display('default', 'Master', 'default'); + $handler->display->display_options['title'] = 'Weather History'; + $handler->display->display_options['use_more_always'] = FALSE; + $handler->display->display_options['access']['type'] = 'perm'; + $handler->display->display_options['cache']['type'] = 'none'; + $handler->display->display_options['query']['type'] = 'views_query'; + $handler->display->display_options['exposed_form']['type'] = 'basic'; + $handler->display->display_options['pager']['type'] = 'full'; + $handler->display->display_options['pager']['options']['items_per_page'] = '10'; + $handler->display->display_options['style_plugin'] = 'table'; + $handler->display->display_options['style_options']['columns'] = array( + 'title' => 'title', + ); + $handler->display->display_options['style_options']['default'] = '-1'; + $handler->display->display_options['style_options']['info'] = array( + 'title' => array( + 'sortable' => 0, + 'default_sort_order' => 'asc', + 'align' => '', + 'separator' => '', + 'empty_column' => 0, + ), + ); + /* Field: Content: Title */ + $handler->display->display_options['fields']['title']['id'] = 'title'; + $handler->display->display_options['fields']['title']['table'] = 'node'; + $handler->display->display_options['fields']['title']['field'] = 'title'; + $handler->display->display_options['fields']['title']['label'] = ''; + $handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE; + $handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE; + /* Field: Content: Temperature F */ + $handler->display->display_options['fields']['field_wthr_temp_f']['id'] = 'field_wthr_temp_f'; + $handler->display->display_options['fields']['field_wthr_temp_f']['table'] = 'field_data_field_wthr_temp_f'; + $handler->display->display_options['fields']['field_wthr_temp_f']['field'] = 'field_wthr_temp_f'; + $handler->display->display_options['fields']['field_wthr_temp_f']['label'] = 'Temp'; + $handler->display->display_options['fields']['field_wthr_temp_f']['settings'] = array( + 'thousand_separator' => '', + 'decimal_separator' => '.', + 'scale' => '2', + 'prefix_suffix' => 1, + ); + /* Field: Content: Weather */ + $handler->display->display_options['fields']['field_wthr_weather']['id'] = 'field_wthr_weather'; + $handler->display->display_options['fields']['field_wthr_weather']['table'] = 'field_data_field_wthr_weather'; + $handler->display->display_options['fields']['field_wthr_weather']['field'] = 'field_wthr_weather'; + /* Field: Content: Wind Direction */ + $handler->display->display_options['fields']['field_wthr_wind_dir']['id'] = 'field_wthr_wind_dir'; + $handler->display->display_options['fields']['field_wthr_wind_dir']['table'] = 'field_data_field_wthr_wind_dir'; + $handler->display->display_options['fields']['field_wthr_wind_dir']['field'] = 'field_wthr_wind_dir'; + /* Field: Content: Wind MPH */ + $handler->display->display_options['fields']['field_wthr_wind_mph']['id'] = 'field_wthr_wind_mph'; + $handler->display->display_options['fields']['field_wthr_wind_mph']['table'] = 'field_data_field_wthr_wind_mph'; + $handler->display->display_options['fields']['field_wthr_wind_mph']['field'] = 'field_wthr_wind_mph'; + $handler->display->display_options['fields']['field_wthr_wind_mph']['settings'] = array( + 'thousand_separator' => '', + 'decimal_separator' => '.', + 'scale' => '2', + 'prefix_suffix' => 1, + ); + /* Sort criterion: Content: Post date */ + $handler->display->display_options['sorts']['created']['id'] = 'created'; + $handler->display->display_options['sorts']['created']['table'] = 'node'; + $handler->display->display_options['sorts']['created']['field'] = 'created'; + $handler->display->display_options['sorts']['created']['order'] = 'DESC'; + /* Filter criterion: Content: Type */ + $handler->display->display_options['filters']['type']['id'] = 'type'; + $handler->display->display_options['filters']['type']['table'] = 'node'; + $handler->display->display_options['filters']['type']['field'] = 'type'; + $handler->display->display_options['filters']['type']['value'] = array( + 'imported_weather_conditions' => 'imported_weather_conditions', + ); + + /* Display: Page */ + $handler = $view->new_display('page', 'Page', 'page'); + $handler->display->display_options['path'] = 'weather-history'; + $handler->display->display_options['menu']['type'] = 'normal'; + $handler->display->display_options['menu']['title'] = 'Weather'; + $handler->display->display_options['menu']['name'] = 'farm'; + $export['weather_history'] = $view; + + return $export; +} From 7b1a9404570ff5ae162ff0403915bf8423a1fee2 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Fri, 8 Sep 2017 21:03:49 -0500 Subject: [PATCH 21/75] Setup MkDocs --- docs/index.md | 17 +++++++++++++++++ docs/index.md.bak | 17 +++++++++++++++++ mkdocs.yml | 1 + 3 files changed, 35 insertions(+) create mode 100644 docs/index.md create mode 100644 docs/index.md.bak create mode 100644 mkdocs.yml diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..da37213 --- /dev/null +++ b/docs/index.md @@ -0,0 +1,17 @@ +# Welcome to MkDocs + +For full documentation visit [mkdocs.org](http://mkdocs.org). + +## Commands + +* `mkdocs new [dir-name]` - Create a new project. +* `mkdocs serve` - Start the live-reloading docs server. +* `mkdocs build` - Build the documentation site. +* `mkdocs help` - Print this help message. + +## Project layout + + mkdocs.yml # The configuration file. + docs/ + index.md # The documentation homepage. + ... # Other markdown pages, images and other files. diff --git a/docs/index.md.bak b/docs/index.md.bak new file mode 100644 index 0000000..da37213 --- /dev/null +++ b/docs/index.md.bak @@ -0,0 +1,17 @@ +# Welcome to MkDocs + +For full documentation visit [mkdocs.org](http://mkdocs.org). + +## Commands + +* `mkdocs new [dir-name]` - Create a new project. +* `mkdocs serve` - Start the live-reloading docs server. +* `mkdocs build` - Build the documentation site. +* `mkdocs help` - Print this help message. + +## Project layout + + mkdocs.yml # The configuration file. + docs/ + index.md # The documentation homepage. + ... # Other markdown pages, images and other files. diff --git a/mkdocs.yml b/mkdocs.yml new file mode 100644 index 0000000..c97182f --- /dev/null +++ b/mkdocs.yml @@ -0,0 +1 @@ +site_name: My Docs From b55b2bcbb6b5e6bd948fe2b9b28b3c8bfc08c597 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Fri, 8 Sep 2017 21:10:17 -0500 Subject: [PATCH 22/75] Ignore sites file created by mkdocs --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index c8663d7..7a770bf 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,5 @@ xmlrpc.php .project* .settings* +# ignore mkdocs files +site/* From 61c7e4382e5c7beae9e2111c0113c23a1f8dcaad Mon Sep 17 00:00:00 2001 From: Bit Second Date: Fri, 8 Sep 2017 21:16:29 -0500 Subject: [PATCH 23/75] Updated mkdocs configuration --- mkdocs.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/mkdocs.yml b/mkdocs.yml index c97182f..9f2964e 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -1 +1,11 @@ -site_name: My Docs +site_name: FarmOS NWS +site_url: http://bitsecondal.github.io/farmosnws +repo_url: https://github.com/bitsecondal/farmosnws.git +site_author: Kenny Robinson +remote_branch: gh-pages +remote_name: origin +use_directory_urls: true +strict: true +dev_addr: 0.0.0.0:8000 +extra: + version: 7.0-2.0beta1 From f0402ec52176d884e9da01601ccd44ea7b665c59 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Fri, 8 Sep 2017 21:17:36 -0500 Subject: [PATCH 24/75] Updated mkdocs configuration as it would not compile. --- mkdocs.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/mkdocs.yml b/mkdocs.yml index 9f2964e..52e8249 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -7,5 +7,3 @@ remote_name: origin use_directory_urls: true strict: true dev_addr: 0.0.0.0:8000 -extra: - version: 7.0-2.0beta1 From d63fbc6e4e9d246acd76743c9e5fbfd4db3328f7 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Fri, 8 Sep 2017 21:19:41 -0500 Subject: [PATCH 25/75] Moved readme to mkdocs configuration --- README.md | 114 +---------------------------------------------- docs/index.md | 121 +++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 111 insertions(+), 124 deletions(-) diff --git a/README.md b/README.md index 4870b4f..80036c5 100644 --- a/README.md +++ b/README.md @@ -1,114 +1,4 @@ -# farmosnws -A Drupal module to allow automated importing of National Weather Service (NWS) data into FarmOS. +# FarmOS NWS -## Purpose -The purpose of this project is to allow FarmOS to use data from the National -Weather Service to allow it to make better decisions as well as to log -data from a trusted weather source. - -Bit Second noticed that some small farmers and gardeners do not have the -financial resources to deploy many sensors for their FarmOS installation. -However, by combining the data provide from the local NWS weather station and -using additional Drupal modules, FarmOS can be better automated with a lower -investment. - -## System Requirements -* Drupal 7 -* FarmOS -* Ubuntu Linux (May run on other Linux versions, but has only be tested with Ubuntu Linux 14.04 LTS) -* PHP 5 -* Crontab or other task scheduler capable of running shell scripts - -## Setup - -### Clone the Repository -Clone this repository by running the command below -```shell -git clone https://github.com/bitsecondal/farmosnws.git -``` - -### Get Weather Data via Drupal -* Install the module in Drupal -* Go to the module configuration page. -* Go to the [XML data feeds](http://w1.weather.gov/xml/current_obs/) page on the NWS website. -* Select the state and click Find -* Find the location taht is closest to the area that you want to pull data for. -* In the parenthesis next to the location, you will see a 4-character code. Copy this code. -* Place the 4-character code on a line in the text box. If you have multiple locations that you -want to pull the data for, then enter each one on a separate line. -* Enter the path where the weather files are to be saved on the server. This will be the same location -that the Feeds module will import the files from. -* Click *Save configuration* on the form. -* Go to the *Feeds importer* (Structure > Feeds importer) page -* Create a new importer and name it. -* Select the *XPath XML Parser* as the parser. -* Enter each of the elements that you want to capture in the Parser Settings. -* Configure the remainder of the settings for the Feeds Importer. - -#### Schedule Script -No scheduling has to be done. Weather data will be automatically be pulled when Drupal cron run. If -necessary, adjust Drupal cron frequency or use [Elysia Cron](https://www.drupal.org/project/elysia_cron) -to run module specific cron. - -### Get Weather Data via Shell Script (Advanced) -#### Create Configuration File -Make a copy of the get_weather_config_ex.sh file. Update the variables located in the configuration -script file. - -The *feedsdir* location will need to be updated to the file system location that -Drupal is checking to see if data files are available. - -The *location* variable will need to be updated to the location code for the location -that you want data for. -* Go to the [XML data feeds](http://w1.weather.gov/xml/current_obs/) page on the NWS website. -* Select the state and click Find -* Find the location that is closest to the area that you want to pull data for. -* In the parenthesis next to the location, you will see a 4-character code. Copy this code. -* Place the 4-character code in the configuration file inside quotes. -* Save the configuration file. - -If you have multiple locations that you want to pull data for, you'll need to create a configuration -file for each location and set up a scheduled task for each configuration file. - -#### Schedule Script -To set up a cron job to run to automatically pull the latest weather data, you use the details and -steps below. The National Weather Service updates the data hourly. - -##### Linux/Ubuntu with Crontab -Update the paths mentioned to the location of your script and the location of your configuration -file respectively. If you want to log the output of the script, also update the log location. -```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 -``` - -## 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: -```shell -git pull origin master -``` - -## Author -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. Include -as much detail as possible, including screenshots and error messages, 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. +Please visit https://bitsecondal.github.io/farmosnws/ for documentation. diff --git a/docs/index.md b/docs/index.md index da37213..4870b4f 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,17 +1,114 @@ -# Welcome to MkDocs +# farmosnws +A Drupal module to allow automated importing of National Weather Service (NWS) data into FarmOS. -For full documentation visit [mkdocs.org](http://mkdocs.org). +## Purpose +The purpose of this project is to allow FarmOS to use data from the National +Weather Service to allow it to make better decisions as well as to log +data from a trusted weather source. -## Commands +Bit Second noticed that some small farmers and gardeners do not have the +financial resources to deploy many sensors for their FarmOS installation. +However, by combining the data provide from the local NWS weather station and +using additional Drupal modules, FarmOS can be better automated with a lower +investment. -* `mkdocs new [dir-name]` - Create a new project. -* `mkdocs serve` - Start the live-reloading docs server. -* `mkdocs build` - Build the documentation site. -* `mkdocs help` - Print this help message. +## System Requirements +* Drupal 7 +* FarmOS +* Ubuntu Linux (May run on other Linux versions, but has only be tested with Ubuntu Linux 14.04 LTS) +* PHP 5 +* Crontab or other task scheduler capable of running shell scripts -## Project layout +## Setup + +### Clone the Repository +Clone this repository by running the command below +```shell +git clone https://github.com/bitsecondal/farmosnws.git +``` + +### Get Weather Data via Drupal +* Install the module in Drupal +* Go to the module configuration page. +* Go to the [XML data feeds](http://w1.weather.gov/xml/current_obs/) page on the NWS website. +* Select the state and click Find +* Find the location taht is closest to the area that you want to pull data for. +* In the parenthesis next to the location, you will see a 4-character code. Copy this code. +* Place the 4-character code on a line in the text box. If you have multiple locations that you +want to pull the data for, then enter each one on a separate line. +* Enter the path where the weather files are to be saved on the server. This will be the same location +that the Feeds module will import the files from. +* Click *Save configuration* on the form. +* Go to the *Feeds importer* (Structure > Feeds importer) page +* Create a new importer and name it. +* Select the *XPath XML Parser* as the parser. +* Enter each of the elements that you want to capture in the Parser Settings. +* Configure the remainder of the settings for the Feeds Importer. + +#### Schedule Script +No scheduling has to be done. Weather data will be automatically be pulled when Drupal cron run. If +necessary, adjust Drupal cron frequency or use [Elysia Cron](https://www.drupal.org/project/elysia_cron) +to run module specific cron. + +### Get Weather Data via Shell Script (Advanced) +#### Create Configuration File +Make a copy of the get_weather_config_ex.sh file. Update the variables located in the configuration +script file. + +The *feedsdir* location will need to be updated to the file system location that +Drupal is checking to see if data files are available. + +The *location* variable will need to be updated to the location code for the location +that you want data for. +* Go to the [XML data feeds](http://w1.weather.gov/xml/current_obs/) page on the NWS website. +* Select the state and click Find +* Find the location that is closest to the area that you want to pull data for. +* In the parenthesis next to the location, you will see a 4-character code. Copy this code. +* Place the 4-character code in the configuration file inside quotes. +* Save the configuration file. + +If you have multiple locations that you want to pull data for, you'll need to create a configuration +file for each location and set up a scheduled task for each configuration file. + +#### Schedule Script +To set up a cron job to run to automatically pull the latest weather data, you use the details and +steps below. The National Weather Service updates the data hourly. + +##### Linux/Ubuntu with Crontab +Update the paths mentioned to the location of your script and the location of your configuration +file respectively. If you want to log the output of the script, also update the log location. +```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 +``` + +## 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: +```shell +git pull origin master +``` + +## Author +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. Include +as much detail as possible, including screenshots and error messages, 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. - mkdocs.yml # The configuration file. - docs/ - index.md # The documentation homepage. - ... # Other markdown pages, images and other files. From 34271b8a3c67562e9885e52acaff7e04d0ec917d Mon Sep 17 00:00:00 2001 From: Bit Second Date: Fri, 8 Sep 2017 21:23:01 -0500 Subject: [PATCH 26/75] Updated title of mkdoc page --- docs/index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/index.md b/docs/index.md index 4870b4f..d354253 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,4 +1,4 @@ -# farmosnws +# FarmOS NWS A Drupal module to allow automated importing of National Weather Service (NWS) data into FarmOS. ## Purpose @@ -67,7 +67,7 @@ that you want data for. * Place the 4-character code in the configuration file inside quotes. * Save the configuration file. -If you have multiple locations that you want to pull data for, you'll need to create a configuration +If you have multiple locations that you want to pull data for, you will need to create a configuration file for each location and set up a scheduled task for each configuration file. #### Schedule Script From d85564bdcdf8e80cc0d994c0b4de5d9b7106bbd8 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Fri, 8 Sep 2017 21:46:05 -0500 Subject: [PATCH 27/75] Separated index file contents --- docs/credits.md | 17 ++++++++ docs/index.md | 100 ------------------------------------------------ docs/setup.md | 82 +++++++++++++++++++++++++++++++++++++++ docs/updates.md | 18 +++++++++ mkdocs.yml | 5 +++ 5 files changed, 122 insertions(+), 100 deletions(-) create mode 100644 docs/credits.md create mode 100644 docs/setup.md create mode 100644 docs/updates.md diff --git a/docs/credits.md b/docs/credits.md new file mode 100644 index 0000000..6e316e3 --- /dev/null +++ b/docs/credits.md @@ -0,0 +1,17 @@ +# Credits + +## Author +Kenny Robinson, Bit Second Tech (www.bitsecondtech.com) + +## 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. + +## License +Project is available under the MIT License. See LICENSE for more information. + diff --git a/docs/index.md b/docs/index.md index d354253..a90742b 100644 --- a/docs/index.md +++ b/docs/index.md @@ -12,103 +12,3 @@ However, by combining the data provide from the local NWS weather station and using additional Drupal modules, FarmOS can be better automated with a lower investment. -## System Requirements -* Drupal 7 -* FarmOS -* Ubuntu Linux (May run on other Linux versions, but has only be tested with Ubuntu Linux 14.04 LTS) -* PHP 5 -* Crontab or other task scheduler capable of running shell scripts - -## Setup - -### Clone the Repository -Clone this repository by running the command below -```shell -git clone https://github.com/bitsecondal/farmosnws.git -``` - -### Get Weather Data via Drupal -* Install the module in Drupal -* Go to the module configuration page. -* Go to the [XML data feeds](http://w1.weather.gov/xml/current_obs/) page on the NWS website. -* Select the state and click Find -* Find the location taht is closest to the area that you want to pull data for. -* In the parenthesis next to the location, you will see a 4-character code. Copy this code. -* Place the 4-character code on a line in the text box. If you have multiple locations that you -want to pull the data for, then enter each one on a separate line. -* Enter the path where the weather files are to be saved on the server. This will be the same location -that the Feeds module will import the files from. -* Click *Save configuration* on the form. -* Go to the *Feeds importer* (Structure > Feeds importer) page -* Create a new importer and name it. -* Select the *XPath XML Parser* as the parser. -* Enter each of the elements that you want to capture in the Parser Settings. -* Configure the remainder of the settings for the Feeds Importer. - -#### Schedule Script -No scheduling has to be done. Weather data will be automatically be pulled when Drupal cron run. If -necessary, adjust Drupal cron frequency or use [Elysia Cron](https://www.drupal.org/project/elysia_cron) -to run module specific cron. - -### Get Weather Data via Shell Script (Advanced) -#### Create Configuration File -Make a copy of the get_weather_config_ex.sh file. Update the variables located in the configuration -script file. - -The *feedsdir* location will need to be updated to the file system location that -Drupal is checking to see if data files are available. - -The *location* variable will need to be updated to the location code for the location -that you want data for. -* Go to the [XML data feeds](http://w1.weather.gov/xml/current_obs/) page on the NWS website. -* Select the state and click Find -* Find the location that is closest to the area that you want to pull data for. -* In the parenthesis next to the location, you will see a 4-character code. Copy this code. -* Place the 4-character code in the configuration file inside quotes. -* Save the configuration file. - -If you have multiple locations that you want to pull data for, you will need to create a configuration -file for each location and set up a scheduled task for each configuration file. - -#### Schedule Script -To set up a cron job to run to automatically pull the latest weather data, you use the details and -steps below. The National Weather Service updates the data hourly. - -##### Linux/Ubuntu with Crontab -Update the paths mentioned to the location of your script and the location of your configuration -file respectively. If you want to log the output of the script, also update the log location. -```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 -``` - -## 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: -```shell -git pull origin master -``` - -## Author -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. Include -as much detail as possible, including screenshots and error messages, 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. - diff --git a/docs/setup.md b/docs/setup.md new file mode 100644 index 0000000..bb856a0 --- /dev/null +++ b/docs/setup.md @@ -0,0 +1,82 @@ +# Setup + +## System Requirements +* Drupal 7 +* FarmOS +* Ubuntu Linux (May run on other Linux versions, but has only be tested with Ubuntu Linux 14.04 LTS) +* PHP 5 +* Crontab or other task scheduler capable of running shell scripts + +## Instructions + +1) Clone this repository by running the command below +```shell +git clone https://github.com/bitsecondal/farmosnws.git +``` + +2) Install the module in Drupal + +3) Go to the module configuration page. + +4) Go to the [XML data feeds](http://w1.weather.gov/xml/current_obs/) page on the NWS website. + +5) Select the state and click Find + +6) Find the location taht is closest to the area that you want to pull data for. + +7) In the parenthesis next to the location, you will see a 4-character code. Copy this code. + +8) Place the 4-character code on a line in the text box. If you have multiple locations that you +want to pull the data for, then enter each one on a separate line. + +9) Enter the path where the weather files are to be saved on the server. This will be the same location +that the Feeds module will import the files from. + +10) Click *Save configuration* on the form. + +11) Go to the *Feeds importer* (Structure > Feeds importer) page + +12) Create a new importer and name it. + +13) Select the *XPath XML Parser* as the parser. + +14) Enter each of the elements that you want to capture in the Parser Settings. + +15) Configure the remainder of the settings for the Feeds Importer. + +## Schedule Script +No scheduling has to be done. Weather data will be automatically be pulled when Drupal cron run. If +necessary, adjust Drupal cron frequency or use [Elysia Cron](https://www.drupal.org/project/elysia_cron) +to run module specific cron. + +## Get Weather Data via Shell Script (Advanced) +### Create Configuration File +Make a copy of the get_weather_config_ex.sh file. Update the variables located in the configuration +script file. + +The *feedsdir* location will need to be updated to the file system location that +Drupal is checking to see if data files are available. + +The *location* variable will need to be updated to the location code for the location +that you want data for. +* Go to the [XML data feeds](http://w1.weather.gov/xml/current_obs/) page on the NWS website. +* Select the state and click Find +* Find the location that is closest to the area that you want to pull data for. +* In the parenthesis next to the location, you will see a 4-character code. Copy this code. +* Place the 4-character code in the configuration file inside quotes. +* Save the configuration file. + +If you have multiple locations that you want to pull data for, you will need to create a configuration +file for each location and set up a scheduled task for each configuration file. + +## Schedule Script +To set up a cron job to run to automatically pull the latest weather data, you use the details and +steps below. The National Weather Service updates the data hourly. + +## Linux/Ubuntu with Crontab +Update the paths mentioned to the location of your script and the location of your configuration +file respectively. If you want to log the output of the script, also update the log location. +```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 +``` + diff --git a/docs/updates.md b/docs/updates.md new file mode 100644 index 0000000..fc5596f --- /dev/null +++ b/docs/updates.md @@ -0,0 +1,18 @@ +# Updates and Defects + +## 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: +```shell +git pull origin master +``` + +## 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. Include +as much detail as possible, including screenshots and error messages, so that the issue can be replicated. + diff --git a/mkdocs.yml b/mkdocs.yml index 52e8249..8f337db 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -7,3 +7,8 @@ remote_name: origin use_directory_urls: true strict: true dev_addr: 0.0.0.0:8000 +pages: +- Home: index.md +- Setup: setup.md +- Updates: updates.md +- Credits: credits.md From 11a50588b0c28094b7f15a590278658087ce9706 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Fri, 8 Sep 2017 21:54:50 -0500 Subject: [PATCH 28/75] Removed backup of index file. Completed #12 --- docs/index.md.bak | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 docs/index.md.bak diff --git a/docs/index.md.bak b/docs/index.md.bak deleted file mode 100644 index da37213..0000000 --- a/docs/index.md.bak +++ /dev/null @@ -1,17 +0,0 @@ -# Welcome to MkDocs - -For full documentation visit [mkdocs.org](http://mkdocs.org). - -## Commands - -* `mkdocs new [dir-name]` - Create a new project. -* `mkdocs serve` - Start the live-reloading docs server. -* `mkdocs build` - Build the documentation site. -* `mkdocs help` - Print this help message. - -## Project layout - - mkdocs.yml # The configuration file. - docs/ - index.md # The documentation homepage. - ... # Other markdown pages, images and other files. From 0870245af5e07af0b7d49f388942a0c1c8919614 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Fri, 8 Sep 2017 22:31:01 -0500 Subject: [PATCH 29/75] Added watchdog install and uninstall message. Added removing nodes and node type during uninstall. --- farmosnws.install | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 farmosnws.install diff --git a/farmosnws.install b/farmosnws.install new file mode 100644 index 0000000..1afa8a6 --- /dev/null +++ b/farmosnws.install @@ -0,0 +1,49 @@ + db_like('farmosnws') . '%')); + + foreach($result as $row) { + variable_del($row->name); + } // end foreach + + // delete all the nodes that have been created by the module + $query = "select nid where {node} where type = :ntype"; + $result = db_query($result, array(':ntype' => 'imported_weather_conditions')); + + foreach($result as $row) { + $nodes[] = $row->nid; + } + + if (!empty($nodes)) { + // delete the nodes + node_delete_multiple($nodes); + } + + // delete the content type + if ( node_type_load('imported_weather_conditions')) { + node_type_delete('imported_weather_conditions'); + drupal_set_message(t('%type content type has been deleted.', array('%type' => 'imported_weather_conditions'))); + } // end if + + node_types_rebuild(); + menu_rebuild(); + + watchdog('farmosnws', 'FarmOS NWS module has been uninstalled.', array(), WATCHDOG_INFO, NULL); +} // end function + + From 489079dd71dc43ff2e846fd58e40384cf3226588 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Fri, 20 Oct 2017 21:29:35 -0500 Subject: [PATCH 30/75] Added Rule for downloading file on cron run. Updated dependencies. Updated feed importer --- farmosnws.feeds_importer_default.inc | 6 +++--- farmosnws.info | 4 ++-- farmosnws.rules_defaults.inc | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/farmosnws.feeds_importer_default.inc b/farmosnws.feeds_importer_default.inc index ea7f98b..a803c7e 100644 --- a/farmosnws.feeds_importer_default.inc +++ b/farmosnws.feeds_importer_default.inc @@ -15,7 +15,7 @@ function farmosnws_feeds_importer_default() { $feeds_importer->api_version = 1; $feeds_importer->id = 'import_weather_conditions_kmgm'; $feeds_importer->config = array( - 'name' => 'Import Weather Conditions', + 'name' => 'Import Weather Conditions KMGM', 'description' => 'Import weather conditions from the National Weather Service', 'fetcher' => array( 'plugin_key' => 'feeds_fetcher_directory_fetcher', @@ -24,7 +24,7 @@ function farmosnws_feeds_importer_default() { 'directory' => 'public://curweather', 'filemask' => '/\\.xml$/', 'updated_files' => 1, - 'after_processed' => '0', + 'after_processed' => '1', 'move_to_folder' => '', ), ), @@ -79,7 +79,7 @@ function farmosnws_feeds_importer_default() { 'plugin_key' => 'FeedsNodeProcessor', 'config' => array( 'expire' => '-1', - 'author' => '47', + 'author' => '28', 'authorize' => 0, 'mappings' => array( 0 => array( diff --git a/farmosnws.info b/farmosnws.info index 5f47c65..0b8822d 100644 --- a/farmosnws.info +++ b/farmosnws.info @@ -2,7 +2,7 @@ name = FarmOS NWS description = Imports data from the National Weather Service into Drupal for use by FarmOS. core = 7.x package = farmOS (beta) -version = 7.x-2.0-beta3 +version = 7.x-2.0-beta4 dependencies[] = ctools dependencies[] = features dependencies[] = feeds @@ -35,7 +35,7 @@ features[field_instance][] = node-imported_weather_conditions-field_wthr_wind_di features[field_instance][] = node-imported_weather_conditions-field_wthr_wind_mph features[menu_custom][] = farm features[node][] = imported_weather_conditions -features[rules_config][] = rules_pull_data_from_nws +features[rules_config][] = rules_download_nws_weather_data features[variable][] = field_bundle_settings_node__imported_weather_conditions features[variable][] = menu_options_imported_weather_conditions features[variable][] = menu_parent_imported_weather_conditions diff --git a/farmosnws.rules_defaults.inc b/farmosnws.rules_defaults.inc index 77c964d..c0e9a51 100644 --- a/farmosnws.rules_defaults.inc +++ b/farmosnws.rules_defaults.inc @@ -9,10 +9,11 @@ */ function farmosnws_default_rules_configuration() { $items = array(); - $items['rules_pull_data_from_nws'] = entity_import('rules_config', '{ "rules_pull_data_from_nws" : { - "LABEL" : "Pull data from NWS", + $items['rules_download_nws_weather_data'] = entity_import('rules_config', '{ "rules_download_nws_weather_data" : { + "LABEL" : "Download NWS Weather Data", "PLUGIN" : "reaction rule", "OWNER" : "rules", + "TAGS" : [ "data", "nws", "weather" ], "REQUIRES" : [ "rules_download", "rules" ], "ON" : { "cron" : [] }, "DO" : [ @@ -21,7 +22,6 @@ function farmosnws_default_rules_configuration() { "path" : "http:\\/\\/w1.weather.gov\\/xml\\/current_obs\\/KMGM.xml", "cookie" : "0", "uri_scheme" : "public", - "file_directory" : "curweather", "temporary" : "0", "replace" : "0" }, From 4d3d8abf8329aea65847be1d12879497e8a15723 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Fri, 20 Oct 2017 21:34:30 -0500 Subject: [PATCH 31/75] Corrected misspelling --- docs/setup.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/setup.md b/docs/setup.md index bb856a0..c57921f 100644 --- a/docs/setup.md +++ b/docs/setup.md @@ -22,7 +22,7 @@ git clone https://github.com/bitsecondal/farmosnws.git 5) Select the state and click Find -6) Find the location taht is closest to the area that you want to pull data for. +6) Find the location that is closest to the area that you want to pull data for. 7) In the parenthesis next to the location, you will see a 4-character code. Copy this code. From b8a222f95763c79bfabc1cef68e2608d7870d4f7 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Sat, 21 Oct 2017 08:46:26 -0500 Subject: [PATCH 32/75] Created Admin form --- farmosnws.admin.inc | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 farmosnws.admin.inc diff --git a/farmosnws.admin.inc b/farmosnws.admin.inc new file mode 100644 index 0000000..fe373e9 --- /dev/null +++ b/farmosnws.admin.inc @@ -0,0 +1,27 @@ + 'textfield', + '#title' => t('Location Code'), + '#required' => TRUE, + '#maxlength' => 4, + '#default_value' => variable_get('farmosnws_loc_code',''), + ); + $form['farmosnws_file_loc'] = array( + '#type' => 'textfield', + '#title' => t('File Location'), + '#required' => TRUE, + '#description' => t('The location on the file system were the feed is to be saved.'), + '#default_value' => variable_get('farmosnws_file_loc', ''), + ); + + return system_settings_save($form); +} // end function + + + From a84b48e96cd8a4c245da49169f724643d6889d97 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Sat, 21 Oct 2017 14:03:58 -0500 Subject: [PATCH 33/75] Removed code created by features --- farmosnws.features.field_base.inc | 155 ------------ farmosnws.features.field_instance.inc | 337 -------------------------- farmosnws.features.inc | 42 ---- farmosnws.features.menu_custom.inc | 25 -- farmosnws.features.menu_links.inc | 55 ----- 5 files changed, 614 deletions(-) delete mode 100644 farmosnws.features.field_base.inc delete mode 100644 farmosnws.features.field_instance.inc delete mode 100644 farmosnws.features.inc delete mode 100644 farmosnws.features.menu_custom.inc delete mode 100644 farmosnws.features.menu_links.inc diff --git a/farmosnws.features.field_base.inc b/farmosnws.features.field_base.inc deleted file mode 100644 index 6a6f1b1..0000000 --- a/farmosnws.features.field_base.inc +++ /dev/null @@ -1,155 +0,0 @@ - 1, - 'cardinality' => 1, - 'deleted' => 0, - 'entity_types' => array(), - 'field_name' => 'field_wthr_location', - 'indexes' => array( - 'format' => array( - 0 => 'format', - ), - ), - 'locked' => 0, - 'module' => 'text', - 'settings' => array( - 'max_length' => 255, - ), - 'translatable' => 0, - 'type' => 'text', - ); - - // Exported field_base: 'field_wthr_rel_humidity'. - $field_bases['field_wthr_rel_humidity'] = array( - 'active' => 1, - 'cardinality' => 1, - 'deleted' => 0, - 'entity_types' => array(), - 'field_name' => 'field_wthr_rel_humidity', - 'indexes' => array(), - 'locked' => 0, - 'module' => 'number', - 'settings' => array( - 'decimal_separator' => '.', - 'precision' => 10, - 'scale' => 5, - ), - 'translatable' => 0, - 'type' => 'number_decimal', - ); - - // Exported field_base: 'field_wthr_temp_f'. - $field_bases['field_wthr_temp_f'] = array( - 'active' => 1, - 'cardinality' => 1, - 'deleted' => 0, - 'entity_types' => array(), - 'field_name' => 'field_wthr_temp_f', - 'indexes' => array(), - 'locked' => 0, - 'module' => 'number', - 'settings' => array( - 'decimal_separator' => '.', - 'precision' => 10, - 'scale' => 4, - ), - 'translatable' => 0, - 'type' => 'number_decimal', - ); - - // Exported field_base: 'field_wthr_time_string'. - $field_bases['field_wthr_time_string'] = array( - 'active' => 1, - 'cardinality' => 1, - 'deleted' => 0, - 'entity_types' => array(), - 'field_name' => 'field_wthr_time_string', - 'indexes' => array( - 'format' => array( - 0 => 'format', - ), - ), - 'locked' => 0, - 'module' => 'text', - 'settings' => array( - 'max_length' => 255, - ), - 'translatable' => 0, - 'type' => 'text', - ); - - // Exported field_base: 'field_wthr_weather'. - $field_bases['field_wthr_weather'] = array( - 'active' => 1, - 'cardinality' => 1, - 'deleted' => 0, - 'entity_types' => array(), - 'field_name' => 'field_wthr_weather', - 'indexes' => array( - 'format' => array( - 0 => 'format', - ), - ), - 'locked' => 0, - 'module' => 'text', - 'settings' => array( - 'max_length' => 255, - ), - 'translatable' => 0, - 'type' => 'text', - ); - - // Exported field_base: 'field_wthr_wind_dir'. - $field_bases['field_wthr_wind_dir'] = array( - 'active' => 1, - 'cardinality' => 1, - 'deleted' => 0, - 'entity_types' => array(), - 'field_name' => 'field_wthr_wind_dir', - 'indexes' => array( - 'format' => array( - 0 => 'format', - ), - ), - 'locked' => 0, - 'module' => 'text', - 'settings' => array( - 'max_length' => 255, - ), - 'translatable' => 0, - 'type' => 'text', - ); - - // Exported field_base: 'field_wthr_wind_mph'. - $field_bases['field_wthr_wind_mph'] = array( - 'active' => 1, - 'cardinality' => 1, - 'deleted' => 0, - 'entity_types' => array(), - 'field_name' => 'field_wthr_wind_mph', - 'indexes' => array(), - 'locked' => 0, - 'module' => 'number', - 'settings' => array( - 'decimal_separator' => '.', - 'precision' => 10, - 'scale' => 5, - ), - 'translatable' => 0, - 'type' => 'number_decimal', - ); - - return $field_bases; -} diff --git a/farmosnws.features.field_instance.inc b/farmosnws.features.field_instance.inc deleted file mode 100644 index 1780343..0000000 --- a/farmosnws.features.field_instance.inc +++ /dev/null @@ -1,337 +0,0 @@ - 'imported_weather_conditions', - 'default_value' => NULL, - 'deleted' => 0, - 'description' => '', - 'display' => array( - 'default' => array( - 'label' => 'above', - 'module' => 'text', - 'settings' => array(), - 'type' => 'text_default', - 'weight' => 8, - ), - 'teaser' => array( - 'label' => 'above', - 'settings' => array(), - 'type' => 'hidden', - 'weight' => 0, - ), - ), - 'entity_type' => 'node', - 'field_name' => 'field_wthr_location', - 'label' => 'Location', - 'required' => 0, - 'settings' => array( - 'text_processing' => 0, - 'user_register_form' => FALSE, - ), - 'widget' => array( - 'active' => 1, - 'module' => 'text', - 'settings' => array( - 'size' => 60, - ), - 'type' => 'text_textfield', - 'weight' => 40, - ), - ); - - // Exported field_instance: - // 'node-imported_weather_conditions-field_wthr_rel_humidity'. - $field_instances['node-imported_weather_conditions-field_wthr_rel_humidity'] = array( - 'bundle' => 'imported_weather_conditions', - 'default_value' => array( - 0 => array( - 'value' => 0, - ), - ), - 'deleted' => 0, - 'description' => '', - 'display' => array( - 'default' => array( - 'label' => 'above', - 'module' => 'number', - 'settings' => array( - 'decimal_separator' => '.', - 'prefix_suffix' => TRUE, - 'scale' => 2, - 'thousand_separator' => '', - ), - 'type' => 'number_decimal', - 'weight' => 2, - ), - 'teaser' => array( - 'label' => 'above', - 'settings' => array(), - 'type' => 'hidden', - 'weight' => 0, - ), - ), - 'entity_type' => 'node', - 'field_name' => 'field_wthr_rel_humidity', - 'label' => 'Humidity', - 'required' => 0, - 'settings' => array( - 'max' => 100, - 'min' => 0, - 'prefix' => '', - 'suffix' => '%', - 'user_register_form' => FALSE, - ), - 'widget' => array( - 'active' => 0, - 'module' => 'number', - 'settings' => array(), - 'type' => 'number', - 'weight' => 33, - ), - ); - - // Exported field_instance: - // 'node-imported_weather_conditions-field_wthr_temp_f'. - $field_instances['node-imported_weather_conditions-field_wthr_temp_f'] = array( - 'bundle' => 'imported_weather_conditions', - 'default_value' => NULL, - 'deleted' => 0, - 'description' => '', - 'display' => array( - 'default' => array( - 'label' => 'above', - 'module' => 'number', - 'settings' => array( - 'decimal_separator' => '.', - 'prefix_suffix' => TRUE, - 'scale' => 2, - 'thousand_separator' => '', - ), - 'type' => 'number_decimal', - 'weight' => 1, - ), - 'teaser' => array( - 'label' => 'above', - 'settings' => array(), - 'type' => 'hidden', - 'weight' => 0, - ), - ), - 'entity_type' => 'node', - 'field_name' => 'field_wthr_temp_f', - 'label' => 'Temperature F', - 'required' => 0, - 'settings' => array( - 'max' => '', - 'min' => '', - 'prefix' => '', - 'suffix' => 'F', - 'user_register_form' => FALSE, - ), - 'widget' => array( - 'active' => 0, - 'module' => 'number', - 'settings' => array(), - 'type' => 'number', - 'weight' => 32, - ), - ); - - // Exported field_instance: - // 'node-imported_weather_conditions-field_wthr_time_string'. - $field_instances['node-imported_weather_conditions-field_wthr_time_string'] = array( - 'bundle' => 'imported_weather_conditions', - 'default_value' => NULL, - 'deleted' => 0, - 'description' => '', - 'display' => array( - 'default' => array( - 'label' => 'above', - 'module' => 'text', - 'settings' => array(), - 'type' => 'text_default', - 'weight' => 4, - ), - 'teaser' => array( - 'label' => 'above', - 'settings' => array(), - 'type' => 'hidden', - 'weight' => 0, - ), - ), - 'entity_type' => 'node', - 'field_name' => 'field_wthr_time_string', - 'label' => 'Time String', - 'required' => 0, - 'settings' => array( - 'text_processing' => 0, - 'user_register_form' => FALSE, - ), - 'widget' => array( - 'active' => 1, - 'module' => 'text', - 'settings' => array( - 'size' => 60, - ), - 'type' => 'text_textfield', - 'weight' => 35, - ), - ); - - // Exported field_instance: - // 'node-imported_weather_conditions-field_wthr_weather'. - $field_instances['node-imported_weather_conditions-field_wthr_weather'] = array( - 'bundle' => 'imported_weather_conditions', - 'default_value' => NULL, - 'deleted' => 0, - 'description' => '', - 'display' => array( - 'default' => array( - 'label' => 'above', - 'module' => 'text', - 'settings' => array(), - 'type' => 'text_default', - 'weight' => 3, - ), - 'teaser' => array( - 'label' => 'above', - 'settings' => array(), - 'type' => 'hidden', - 'weight' => 0, - ), - ), - 'entity_type' => 'node', - 'field_name' => 'field_wthr_weather', - 'label' => 'Weather', - 'required' => 0, - 'settings' => array( - 'text_processing' => 0, - 'user_register_form' => FALSE, - ), - 'widget' => array( - 'active' => 1, - 'module' => 'text', - 'settings' => array( - 'size' => 60, - ), - 'type' => 'text_textfield', - 'weight' => 34, - ), - ); - - // Exported field_instance: - // 'node-imported_weather_conditions-field_wthr_wind_dir'. - $field_instances['node-imported_weather_conditions-field_wthr_wind_dir'] = array( - 'bundle' => 'imported_weather_conditions', - 'default_value' => NULL, - 'deleted' => 0, - 'description' => '', - 'display' => array( - 'default' => array( - 'label' => 'above', - 'module' => 'text', - 'settings' => array(), - 'type' => 'text_default', - 'weight' => 5, - ), - 'teaser' => array( - 'label' => 'above', - 'settings' => array(), - 'type' => 'hidden', - 'weight' => 0, - ), - ), - 'entity_type' => 'node', - 'field_name' => 'field_wthr_wind_dir', - 'label' => 'Wind Direction', - 'required' => 0, - 'settings' => array( - 'text_processing' => 0, - 'user_register_form' => FALSE, - ), - 'widget' => array( - 'active' => 1, - 'module' => 'text', - 'settings' => array( - 'size' => 60, - ), - 'type' => 'text_textfield', - 'weight' => 36, - ), - ); - - // Exported field_instance: - // 'node-imported_weather_conditions-field_wthr_wind_mph'. - $field_instances['node-imported_weather_conditions-field_wthr_wind_mph'] = array( - 'bundle' => 'imported_weather_conditions', - 'default_value' => array( - 0 => array( - 'value' => 0, - ), - ), - 'deleted' => 0, - 'description' => '', - 'display' => array( - 'default' => array( - 'label' => 'above', - 'module' => 'number', - 'settings' => array( - 'decimal_separator' => '.', - 'prefix_suffix' => TRUE, - 'scale' => 2, - 'thousand_separator' => '', - ), - 'type' => 'number_decimal', - 'weight' => 6, - ), - 'teaser' => array( - 'label' => 'above', - 'settings' => array(), - 'type' => 'hidden', - 'weight' => 0, - ), - ), - 'entity_type' => 'node', - 'field_name' => 'field_wthr_wind_mph', - 'label' => 'Wind MPH', - 'required' => 0, - 'settings' => array( - 'max' => '', - 'min' => 0, - 'prefix' => '', - 'suffix' => 'MPH', - 'user_register_form' => FALSE, - ), - 'widget' => array( - 'active' => 0, - 'module' => 'number', - 'settings' => array(), - 'type' => 'number', - 'weight' => 37, - ), - ); - - // Translatables - // Included for use with string extractors like potx. - t('Humidity'); - t('Location'); - t('Temperature F'); - t('Time String'); - t('Weather'); - t('Wind Direction'); - t('Wind MPH'); - - return $field_instances; -} diff --git a/farmosnws.features.inc b/farmosnws.features.inc deleted file mode 100644 index 4bd9dc7..0000000 --- a/farmosnws.features.inc +++ /dev/null @@ -1,42 +0,0 @@ - "1"); - } - if ($module == "strongarm" && $api == "strongarm") { - return array("version" => "1"); - } -} - -/** - * Implements hook_views_api(). - */ -function farmosnws_views_api($module = NULL, $api = NULL) { - return array("api" => "3.0"); -} - -/** - * Implements hook_node_info(). - */ -function farmosnws_node_info() { - $items = array( - 'imported_weather_conditions' => array( - 'name' => t('Imported Weather Conditions'), - 'base' => 'node_content', - 'description' => '', - 'has_title' => '1', - 'title_label' => t('Title'), - 'help' => '', - ), - ); - drupal_alter('node_info', $items); - return $items; -} diff --git a/farmosnws.features.menu_custom.inc b/farmosnws.features.menu_custom.inc deleted file mode 100644 index 90b7bb5..0000000 --- a/farmosnws.features.menu_custom.inc +++ /dev/null @@ -1,25 +0,0 @@ - 'farm', - 'title' => 'Farm', - 'description' => 'Farm management links', - ); - // Translatables - // Included for use with string extractors like potx. - t('Farm'); - t('Farm management links'); - - return $menus; -} diff --git a/farmosnws.features.menu_links.inc b/farmosnws.features.menu_links.inc deleted file mode 100644 index 6b329b1..0000000 --- a/farmosnws.features.menu_links.inc +++ /dev/null @@ -1,55 +0,0 @@ - 'farm', - 'link_path' => 'weather-history', - 'router_path' => 'weather-history', - 'link_title' => 'Weather', - 'options' => array( - 'identifier' => 'farm_weather:weather-history', - ), - 'module' => 'system', - 'hidden' => 0, - 'external' => 0, - 'has_children' => 0, - 'expanded' => 0, - 'weight' => 0, - 'customized' => 0, - ); - // Exported menu link: navigation_imported-weather-conditions:node/add/imported-weather-conditions. - $menu_links['navigation_imported-weather-conditions:node/add/imported-weather-conditions'] = array( - 'menu_name' => 'navigation', - 'link_path' => 'node/add/imported-weather-conditions', - 'router_path' => 'node/add/imported-weather-conditions', - 'link_title' => 'Imported Weather Conditions', - 'options' => array( - 'identifier' => 'navigation_imported-weather-conditions:node/add/imported-weather-conditions', - ), - 'module' => 'system', - 'hidden' => 0, - 'external' => 0, - 'has_children' => 0, - 'expanded' => 0, - 'weight' => 0, - 'customized' => 0, - 'parent_identifier' => 'navigation_add-content:node/add', - ); - - // Translatables - // Included for use with string extractors like potx. - t('Imported Weather Conditions'); - t('Weather'); - - return $menu_links; -} From 1849a06cbc3dffc466900eb5e9fe2b25fbb8159d Mon Sep 17 00:00:00 2001 From: Bit Second Date: Sat, 21 Oct 2017 14:04:39 -0500 Subject: [PATCH 34/75] Added displaying status message when enabling module --- farmosnws.install | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/farmosnws.install b/farmosnws.install index 1afa8a6..a570c55 100644 --- a/farmosnws.install +++ b/farmosnws.install @@ -8,6 +8,15 @@ function farmosnws_install() { watchdog('farmosnws', 'FarmOS NWS module has been installed.', array(), WATCHDOG_INFO, NULL); } +/** + * + * implements hook_enable() + */ +function hook_enable() { + // notice to visit configuration page to set initial values for variables + drupal_set_message("Visit the module configuration page to complete setup.", 'warning', FALSE); +} + /** * * implements hook_uninstall() @@ -45,5 +54,3 @@ function farmosnws_uninstall() { watchdog('farmosnws', 'FarmOS NWS module has been uninstalled.', array(), WATCHDOG_INFO, NULL); } // end function - - From 82edf99c54295cd025e7f781d3c7565a80254ce4 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Sat, 21 Oct 2017 14:06:37 -0500 Subject: [PATCH 35/75] Updated adminstration form --- farmosnws.admin.inc | 51 ++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/farmosnws.admin.inc b/farmosnws.admin.inc index fe373e9..20ddcc6 100644 --- a/farmosnws.admin.inc +++ b/farmosnws.admin.inc @@ -1,27 +1,44 @@ - 'textfield', - '#title' => t('Location Code'), + '#title' => t('Feeds Directory'), '#required' => TRUE, - '#maxlength' => 4, - '#default_value' => variable_get('farmosnws_loc_code',''), + '#description' => t('The full directory path to where weather feeds should be saved to.'), + '#default_value' => variable_get('farmosnws_weather_feeds_dir'), ); - $form['farmosnws_file_loc'] = array( - '#type' => 'textfield', - '#title' => t('File Location'), + + $form['farmosnws_locations'] = array( + '#type' => 'textarea', + '#title' => t('Locations'), + '#description' => t('Enter the locations that you would like weather data pulled for. Each location must be entered on a separate line.'), '#required' => TRUE, - '#description' => t('The location on the file system were the feed is to be saved.'), - '#default_value' => variable_get('farmosnws_file_loc', ''), + '#default_value' => variable_get('farmosnws_locations'), ); - return system_settings_save($form); -} // end function - - + return system_settings_form($form); +} +/** + * + * Validate the module settings + */ +function farmosnws_admin_form_validate($form, &$form_state) { + $weatherfeedsdir = $form_state['values']['farmosnws_weather_feeds_dir']; + + $direxist = farmosnws_create_feed_dir($weatherfeedsdir); + if ( $direxist == FALSE ){ + watchdog('farmosnws', 'Unable to create the weather feed directory.', array(), WATCHDOG_ERROR, NULL); + form_set_error('farmosnws_weather_feeds_dir', 'The weather feed directory cannot be created. Please verify that Drupal as write permissions and try again.'); + } + else { + // watchdog('farmosnws', 'Created weather feed directory.', array(), WATCHDOG_INFO, NULL); + } // end if +} // end if From 670fc20225d65cef7647810d4224459c6d30e009 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Sat, 21 Oct 2017 14:09:17 -0500 Subject: [PATCH 36/75] Removed Features code. Completed loading of XML file directly to Observation log --- farmosnws.info | 53 ++---------- farmosnws.module | 215 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 222 insertions(+), 46 deletions(-) diff --git a/farmosnws.info b/farmosnws.info index 0b8822d..0145323 100644 --- a/farmosnws.info +++ b/farmosnws.info @@ -1,48 +1,11 @@ name = FarmOS NWS description = Imports data from the National Weather Service into Drupal for use by FarmOS. core = 7.x -package = farmOS (beta) -version = 7.x-2.0-beta4 -dependencies[] = ctools -dependencies[] = features -dependencies[] = feeds -dependencies[] = feeds_fetcher_directory -dependencies[] = feeds_xpathparser -dependencies[] = menu -dependencies[] = number -dependencies[] = rules_download -dependencies[] = strongarm -dependencies[] = text -dependencies[] = views -features[ctools][] = feeds:feeds_importer_default:1 -features[ctools][] = strongarm:strongarm:1 -features[ctools][] = views:views_default:3.0 -features[features_api][] = api:2 -features[feeds_importer][] = import_weather_conditions_kmgm -features[field_base][] = field_wthr_location -features[field_base][] = field_wthr_rel_humidity -features[field_base][] = field_wthr_temp_f -features[field_base][] = field_wthr_time_string -features[field_base][] = field_wthr_weather -features[field_base][] = field_wthr_wind_dir -features[field_base][] = field_wthr_wind_mph -features[field_instance][] = node-imported_weather_conditions-field_wthr_location -features[field_instance][] = node-imported_weather_conditions-field_wthr_rel_humidity -features[field_instance][] = node-imported_weather_conditions-field_wthr_temp_f -features[field_instance][] = node-imported_weather_conditions-field_wthr_time_string -features[field_instance][] = node-imported_weather_conditions-field_wthr_weather -features[field_instance][] = node-imported_weather_conditions-field_wthr_wind_dir -features[field_instance][] = node-imported_weather_conditions-field_wthr_wind_mph -features[menu_custom][] = farm -features[node][] = imported_weather_conditions -features[rules_config][] = rules_download_nws_weather_data -features[variable][] = field_bundle_settings_node__imported_weather_conditions -features[variable][] = menu_options_imported_weather_conditions -features[variable][] = menu_parent_imported_weather_conditions -features[variable][] = node_options_imported_weather_conditions -features[variable][] = node_preview_imported_weather_conditions -features[variable][] = node_submitted_imported_weather_conditions -features[views_view][] = weather_history -features_exclude[dependencies][entity] = entity -features_exclude[dependencies][rules] = rules -project path = sites/all/modules/custom +package = farmOS +version = 7.x-2.0-beta5 +dependencies[] = farmos_log_observation + +files[] = farmosnws.module +files[] = farmosnws.admin.inc + +configure = admin/config/services/farmosnws diff --git a/farmosnws.module b/farmosnws.module index 6d16263..017308f 100644 --- a/farmosnws.module +++ b/farmosnws.module @@ -4,4 +4,217 @@ * Code for the FarmOS NWS feature. */ -include_once 'farmosnws.features.inc'; +/** + * + * Implements hook_menu() + * + * @return Array of menu links + */ +function farmosnws_menu() { + $items = array(); + + $items['admin/config/services/farmosnws'] = array( + 'title' => t('FarmOS NWS Settings'), + 'description' => 'Add and remove additional feeds to be pulled by FarmOS NWS', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('farmosnws_admin_form'), + 'access arguments' => array('access administration pages'), + 'file' => 'farmosnws.admin.inc', + ); + + return $items; +} + +/** + * + * Implements hook_cron() + */ +function farmosnws_cron() { + /* + $pullfeed = farmosnws_get_new_feed(); + + if ($pullfeed == TRUE) { + farmosnws_get_xml(); + variable_set('farmosnws_cron_last', REQUEST_TIME); + } + else { + watchdog('farmosnws', 'Skipping pulling weather feed.', array(), WATCHDOG_INFO, NULL); + } + */ + + farmosnws_get_xml(); + variable_set('farmosnws_cron_last', REQUEST_TIME); +} + +/** + * + * Determine whether to pull the data feed from the NWS based on when cron was last run + * + * @return + * Returns whether the feed should be pulled or not. + */ +function farmosnws_feed_limiter() { + $cron_last = variable_get('farmosnws_cron_last', 0); + $time_diff = REQUEST_TIME - $cron_last; + + // if the feed was last pulled over an hour ago, then set value to true. + if ($time_diff >= 3600) { + $returnval = TRUE; + } + else { + $returnval = FALSE; + } + return $returnval; +} + +/** + * + * Check and create if necessary the path where the weather feeds will be stored. + * + * @param string feedpath + * String to the path that contains the feeds + * + * @return Returns whether the directory exists or not. + */ +function farmosnws_create_feed_dir($feedpath) { + $mkdirsuccess = NULL; + + // check to see if the feeds directory exists. If not attempt to create it. + if ( is_dir($feedpath) == FALSE ) { + $mkdirsuccess = mkdir($weatherfeedsdir, 755); + + // verify directory exists + if ( $feedpath == FALSE ){ + watchdog('farmosnws', 'Unable to create the weather feed directory.', array(), WATCHDOG_ERROR, NULL); + } + else { + watchdog('farmosnws', 'Created weather feed directory.', array(), WATCHDOG_INFO, NULL); + } // end if + } + else { + // skipping actions + $mkdirsuccess = TRUE; + } // end if + + return $mkdirsuccess; +} + +/** + * + * Get the weather data from the NWS + */ +function farmosnws_get_xml() { + $weatherfeedsdir = variable_get('farmosnws_weather_feeds_dir'); + + $locations = variable_get('farmosnws_locations', ''); + $location_array = explode("\n", $locations); + $location_count = count($location_array); + + foreach ($location_array as $loc) { + $weather_feed_name = $weather_feed_dir . '/' . $uniqid($loc, FALSE) . '.xml'; + $url = "http://w1.weather.gov/xml/current_obs/" . $loc . ".xml"; + + watchdog('farmosnws', 'Getting weather data for ' . $loc, array(), WATCHDOG_INFO, NULL); + + $response = drupal_http_request($url, array()); + + watchdog('farmosnws', 'Response code: ' . $response->code, array(), WATCHDOG_INFO, NULL); + + // if error occurs when performing the request + if ( $response->error ) { + watchdog('farmosnws', $response->error, array(), WATCHDOG_ERROR, NULL); + drupal_set_message($response->error, 'error', FALSE); + } + // if no errors occur when performing the request + else{ + // if the directory doesnt exist, then create it with 755 permissions + $direxist = farmosnws_create_feed_dir($weatherfeedsdir); + + if ( $direxist == FALSE ) { + drupal_set_message("Feed could not be downloaded because the directory does not exist. Please verify that Drupal has write access and try again.", 'error', FALSE); + } // end if + else { + // save the contents retrieved + file_put_contents($weather_feed_name, $response->data); + watchdog('farmosnws', 'Weather data saved to ' . $weather_feed_name, array(), WATCHDOG_INFO, NULL); + } + } // end else + } // end foreach +} // end function + +/** + * + * @param unknown $feedfilename + */ +function farmosnws_save_feed_data($feedfilename) { + + // load the file + $xml = simplexml_load_file($feedfilename); + + // log the temperature f + $observation_log = log_type_load('farm_observation'); + $observation_log->name = $xml->location . " at " . $xml->observation_time_rfc822; + $observation_log->field_farm_quantity_value = $xml->temp_f; + $observation_log->field_farm_quantity_units = "Fahrenheit"; + // $observation_log->field_farm_observation_type = ""; + $observation_log->field_farm_log_owner = 0; + $observation_log->timestamp = $xml->observation_time_rfc822; + $observation_log->done = 1; + log_save($observation_log); + + // log the relative humidity + $observation_log = log_type_load('farm_observation'); + $observation_log->name = $xml->location . " at " . $xml->observation_time_rfc822; + $observation_log->field_farm_quantity_value = $xml->relative_humidity; + $observation_log->field_farm_quantity_units = "% Humidity"; + // $observation_log->field_farm_observation_type = ""; + $observation_log->field_farm_log_owner = 0; + $observation_log->timestamp = $xml->observation_time_rfc822; + $observation_log->done = 1; + log_save($observation_log); + + // log the wind speed + $observation_log = log_type_load('farm_observation'); + $observation_log->name = $xml->location . " at " . $xml->observation_time_rfc822; + $observation_log->field_farm_quantity_value = $xml->wind_mph; + $observation_log->field_farm_quantity_units = "MPH"; + // $observation_log->field_farm_observation_type = ""; + $observation_log->field_farm_log_owner = 0; + $observation_log->timestamp = $xml->observation_time_rfc822; + $observation_log->done = 1; + log_save($observation_log); + + // log the wind direction + $observation_log = log_type_load('farm_observation'); + $observation_log->name = $xml->location . " at " . $xml->observation_time_rfc822; + $observation_log->field_farm_quantity_value = $xml->wind_dir; + $observation_log->field_farm_quantity_units = "Direction"; + // $observation_log->field_farm_observation_type = ""; + $observation_log->field_farm_log_owner = 0; + $observation_log->timestamp = $xml->observation_time_rfc822; + $observation_log->done = 1; + log_save($observation_log); + + // log the barametric pressure + $observation_log = log_type_load('farm_observation'); + $observation_log->name = $xml->location . " at " . $xml->observation_time_rfc822; + $observation_log->field_farm_quantity_value = $xml->pressure_in; + $observation_log->field_farm_quantity_units = "Inches"; + // $observation_log->field_farm_observation_type = ""; + $observation_log->field_farm_log_owner = 0; + $observation_log->timestamp = $xml->observation_time_rfc822; + $observation_log->done = 1; + log_save($observation_log); + + // log the visibility + $observation_log = log_type_load('farm_observation'); + $observation_log->name = $xml->location . " at " . $xml->observation_time_rfc822; + $observation_log->field_farm_quantity_value = $xml->visibility_mi; + $observation_log->field_farm_quantity_units = "Miles"; + // $observation_log->field_farm_observation_type = ""; + $observation_log->field_farm_log_owner = 0; + $observation_log->timestamp = $xml->observation_time_rfc822; + $observation_log->done = 1; + log_save($observation_log); +} + From 741a55d376703c1490e2c06cadb337d452f9e1ab Mon Sep 17 00:00:00 2001 From: Bit Second Date: Sat, 21 Oct 2017 14:10:28 -0500 Subject: [PATCH 37/75] Removed additional files from Features --- farmosnws.feeds_importer_default.inc | 159 --------------------------- farmosnws.rules_defaults.inc | 35 ------ farmosnws.strongarm.inc | 69 ------------ farmosnws.views_default.inc | 105 ------------------ 4 files changed, 368 deletions(-) delete mode 100644 farmosnws.feeds_importer_default.inc delete mode 100644 farmosnws.rules_defaults.inc delete mode 100644 farmosnws.strongarm.inc delete mode 100644 farmosnws.views_default.inc diff --git a/farmosnws.feeds_importer_default.inc b/farmosnws.feeds_importer_default.inc deleted file mode 100644 index a803c7e..0000000 --- a/farmosnws.feeds_importer_default.inc +++ /dev/null @@ -1,159 +0,0 @@ -disabled = FALSE; /* Edit this to true to make a default feeds_importer disabled initially */ - $feeds_importer->api_version = 1; - $feeds_importer->id = 'import_weather_conditions_kmgm'; - $feeds_importer->config = array( - 'name' => 'Import Weather Conditions KMGM', - 'description' => 'Import weather conditions from the National Weather Service', - 'fetcher' => array( - 'plugin_key' => 'feeds_fetcher_directory_fetcher', - 'config' => array( - 'recursive' => 1, - 'directory' => 'public://curweather', - 'filemask' => '/\\.xml$/', - 'updated_files' => 1, - 'after_processed' => '1', - 'move_to_folder' => '', - ), - ), - 'parser' => array( - 'plugin_key' => 'FeedsXPathParserXML', - 'config' => array( - 'sources' => array( - 'xpathparser:0' => 'location', - 'xpathparser:1' => 'observation_time_rfc822', - 'xpathparser:2' => 'relative_humidity', - 'xpathparser:3' => 'temp_f', - 'xpathparser:4' => 'observation_time_rfc822', - 'xpathparser:5' => 'wind_dir', - 'xpathparser:6' => 'wind_mph', - 'xpathparser:7' => 'weather', - 'xpathparser:8' => 'observation_time_rfc822', - 'xpathparser:9' => 'location', - ), - 'rawXML' => array( - 'xpathparser:0' => 0, - 'xpathparser:1' => 0, - 'xpathparser:2' => 0, - 'xpathparser:3' => 0, - 'xpathparser:4' => 0, - 'xpathparser:5' => 0, - 'xpathparser:6' => 0, - 'xpathparser:7' => 0, - 'xpathparser:8' => 0, - 'xpathparser:9' => 0, - ), - 'context' => '/current_observation', - 'exp' => array( - 'errors' => 0, - 'debug' => array( - 'context' => 0, - 'xpathparser:0' => 0, - 'xpathparser:1' => 0, - 'xpathparser:2' => 0, - 'xpathparser:3' => 0, - 'xpathparser:4' => 0, - 'xpathparser:5' => 0, - 'xpathparser:6' => 0, - 'xpathparser:7' => 0, - 'xpathparser:8' => 0, - 'xpathparser:9' => 0, - ), - ), - 'allow_override' => 1, - ), - ), - 'processor' => array( - 'plugin_key' => 'FeedsNodeProcessor', - 'config' => array( - 'expire' => '-1', - 'author' => '28', - 'authorize' => 0, - 'mappings' => array( - 0 => array( - 'source' => 'xpathparser:1', - 'target' => 'created', - 'unique' => FALSE, - 'language' => 'und', - ), - 1 => array( - 'source' => 'xpathparser:2', - 'target' => 'field_wthr_rel_humidity', - 'unique' => FALSE, - 'language' => 'und', - ), - 2 => array( - 'source' => 'xpathparser:3', - 'target' => 'field_wthr_temp_f', - 'unique' => FALSE, - 'language' => 'und', - ), - 3 => array( - 'source' => 'xpathparser:4', - 'target' => 'field_wthr_time_string', - 'unique' => FALSE, - 'language' => 'und', - ), - 4 => array( - 'source' => 'xpathparser:5', - 'target' => 'field_wthr_wind_dir', - 'unique' => FALSE, - 'language' => 'und', - ), - 5 => array( - 'source' => 'xpathparser:6', - 'target' => 'field_wthr_wind_mph', - 'unique' => FALSE, - 'language' => 'und', - ), - 6 => array( - 'source' => 'xpathparser:7', - 'target' => 'field_wthr_weather', - 'unique' => FALSE, - 'language' => 'und', - ), - 7 => array( - 'source' => 'xpathparser:8', - 'target' => 'title', - 'unique' => FALSE, - 'language' => 'und', - ), - 8 => array( - 'source' => 'xpathparser:9', - 'target' => 'field_wthr_location', - 'unique' => FALSE, - 'language' => 'und', - ), - ), - 'insert_new' => '1', - 'update_existing' => '1', - 'update_non_existent' => 'skip', - 'input_format' => 'plain_text', - 'skip_hash_check' => 0, - 'bundle' => 'imported_weather_conditions', - 'language' => 'und', - ), - ), - 'content_type' => '', - 'update' => 0, - 'import_period' => '3600', - 'expire_period' => 3600, - 'import_on_create' => 1, - 'process_in_background' => 0, - ); - $export['import_weather_conditions_kmgm'] = $feeds_importer; - - return $export; -} diff --git a/farmosnws.rules_defaults.inc b/farmosnws.rules_defaults.inc deleted file mode 100644 index c0e9a51..0000000 --- a/farmosnws.rules_defaults.inc +++ /dev/null @@ -1,35 +0,0 @@ -disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ - $strongarm->api_version = 1; - $strongarm->name = 'field_bundle_settings_node__imported_weather_conditions'; - $strongarm->value = array( - 'view_modes' => array(), - 'extra_fields' => array( - 'form' => array( - 'title' => array( - 'weight' => '-5', - ), - 'path' => array( - 'weight' => '30', - ), - ), - 'display' => array(), - ), - ); - $export['field_bundle_settings_node__imported_weather_conditions'] = $strongarm; - - $strongarm = new stdClass(); - $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ - $strongarm->api_version = 1; - $strongarm->name = 'menu_options_imported_weather_conditions'; - $strongarm->value = array(); - $export['menu_options_imported_weather_conditions'] = $strongarm; - - $strongarm = new stdClass(); - $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ - $strongarm->api_version = 1; - $strongarm->name = 'menu_parent_imported_weather_conditions'; - $strongarm->value = 'main-menu:0'; - $export['menu_parent_imported_weather_conditions'] = $strongarm; - - $strongarm = new stdClass(); - $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ - $strongarm->api_version = 1; - $strongarm->name = 'node_options_imported_weather_conditions'; - $strongarm->value = array(); - $export['node_options_imported_weather_conditions'] = $strongarm; - - $strongarm = new stdClass(); - $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ - $strongarm->api_version = 1; - $strongarm->name = 'node_preview_imported_weather_conditions'; - $strongarm->value = '0'; - $export['node_preview_imported_weather_conditions'] = $strongarm; - - $strongarm = new stdClass(); - $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ - $strongarm->api_version = 1; - $strongarm->name = 'node_submitted_imported_weather_conditions'; - $strongarm->value = 1; - $export['node_submitted_imported_weather_conditions'] = $strongarm; - - return $export; -} diff --git a/farmosnws.views_default.inc b/farmosnws.views_default.inc deleted file mode 100644 index f12cef9..0000000 --- a/farmosnws.views_default.inc +++ /dev/null @@ -1,105 +0,0 @@ -name = 'weather_history'; - $view->description = ''; - $view->tag = 'default'; - $view->base_table = 'node'; - $view->human_name = 'Weather History'; - $view->core = 7; - $view->api_version = '3.0'; - $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */ - - /* Display: Master */ - $handler = $view->new_display('default', 'Master', 'default'); - $handler->display->display_options['title'] = 'Weather History'; - $handler->display->display_options['use_more_always'] = FALSE; - $handler->display->display_options['access']['type'] = 'perm'; - $handler->display->display_options['cache']['type'] = 'none'; - $handler->display->display_options['query']['type'] = 'views_query'; - $handler->display->display_options['exposed_form']['type'] = 'basic'; - $handler->display->display_options['pager']['type'] = 'full'; - $handler->display->display_options['pager']['options']['items_per_page'] = '10'; - $handler->display->display_options['style_plugin'] = 'table'; - $handler->display->display_options['style_options']['columns'] = array( - 'title' => 'title', - ); - $handler->display->display_options['style_options']['default'] = '-1'; - $handler->display->display_options['style_options']['info'] = array( - 'title' => array( - 'sortable' => 0, - 'default_sort_order' => 'asc', - 'align' => '', - 'separator' => '', - 'empty_column' => 0, - ), - ); - /* Field: Content: Title */ - $handler->display->display_options['fields']['title']['id'] = 'title'; - $handler->display->display_options['fields']['title']['table'] = 'node'; - $handler->display->display_options['fields']['title']['field'] = 'title'; - $handler->display->display_options['fields']['title']['label'] = ''; - $handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE; - $handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE; - /* Field: Content: Temperature F */ - $handler->display->display_options['fields']['field_wthr_temp_f']['id'] = 'field_wthr_temp_f'; - $handler->display->display_options['fields']['field_wthr_temp_f']['table'] = 'field_data_field_wthr_temp_f'; - $handler->display->display_options['fields']['field_wthr_temp_f']['field'] = 'field_wthr_temp_f'; - $handler->display->display_options['fields']['field_wthr_temp_f']['label'] = 'Temp'; - $handler->display->display_options['fields']['field_wthr_temp_f']['settings'] = array( - 'thousand_separator' => '', - 'decimal_separator' => '.', - 'scale' => '2', - 'prefix_suffix' => 1, - ); - /* Field: Content: Weather */ - $handler->display->display_options['fields']['field_wthr_weather']['id'] = 'field_wthr_weather'; - $handler->display->display_options['fields']['field_wthr_weather']['table'] = 'field_data_field_wthr_weather'; - $handler->display->display_options['fields']['field_wthr_weather']['field'] = 'field_wthr_weather'; - /* Field: Content: Wind Direction */ - $handler->display->display_options['fields']['field_wthr_wind_dir']['id'] = 'field_wthr_wind_dir'; - $handler->display->display_options['fields']['field_wthr_wind_dir']['table'] = 'field_data_field_wthr_wind_dir'; - $handler->display->display_options['fields']['field_wthr_wind_dir']['field'] = 'field_wthr_wind_dir'; - /* Field: Content: Wind MPH */ - $handler->display->display_options['fields']['field_wthr_wind_mph']['id'] = 'field_wthr_wind_mph'; - $handler->display->display_options['fields']['field_wthr_wind_mph']['table'] = 'field_data_field_wthr_wind_mph'; - $handler->display->display_options['fields']['field_wthr_wind_mph']['field'] = 'field_wthr_wind_mph'; - $handler->display->display_options['fields']['field_wthr_wind_mph']['settings'] = array( - 'thousand_separator' => '', - 'decimal_separator' => '.', - 'scale' => '2', - 'prefix_suffix' => 1, - ); - /* Sort criterion: Content: Post date */ - $handler->display->display_options['sorts']['created']['id'] = 'created'; - $handler->display->display_options['sorts']['created']['table'] = 'node'; - $handler->display->display_options['sorts']['created']['field'] = 'created'; - $handler->display->display_options['sorts']['created']['order'] = 'DESC'; - /* Filter criterion: Content: Type */ - $handler->display->display_options['filters']['type']['id'] = 'type'; - $handler->display->display_options['filters']['type']['table'] = 'node'; - $handler->display->display_options['filters']['type']['field'] = 'type'; - $handler->display->display_options['filters']['type']['value'] = array( - 'imported_weather_conditions' => 'imported_weather_conditions', - ); - - /* Display: Page */ - $handler = $view->new_display('page', 'Page', 'page'); - $handler->display->display_options['path'] = 'weather-history'; - $handler->display->display_options['menu']['type'] = 'normal'; - $handler->display->display_options['menu']['title'] = 'Weather'; - $handler->display->display_options['menu']['name'] = 'farm'; - $export['weather_history'] = $view; - - return $export; -} From 244118b4a587767951efa5e98e9b5d6cffabac5b Mon Sep 17 00:00:00 2001 From: Bit Second Date: Sat, 21 Oct 2017 14:20:48 -0500 Subject: [PATCH 38/75] Added additional logging --- farmosnws.module | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/farmosnws.module b/farmosnws.module index 017308f..00d0a35 100644 --- a/farmosnws.module +++ b/farmosnws.module @@ -132,6 +132,7 @@ function farmosnws_get_xml() { if ( $direxist == FALSE ) { drupal_set_message("Feed could not be downloaded because the directory does not exist. Please verify that Drupal has write access and try again.", 'error', FALSE); + watchdog('farmosnws', 'Feed could not be downloaded because the directory does not exist.', array(), WATCHDOG_ERROR, NULL); } // end if else { // save the contents retrieved @@ -161,6 +162,7 @@ function farmosnws_save_feed_data($feedfilename) { $observation_log->timestamp = $xml->observation_time_rfc822; $observation_log->done = 1; log_save($observation_log); + watchdog('farmosnws', 'Temperature data saved from ' . $feedfilename, array(), WATCHDOG_INFO, NULL); // log the relative humidity $observation_log = log_type_load('farm_observation'); @@ -172,6 +174,7 @@ function farmosnws_save_feed_data($feedfilename) { $observation_log->timestamp = $xml->observation_time_rfc822; $observation_log->done = 1; log_save($observation_log); + watchdog('farmosnws', 'Relative humidity data saved from ' . $feedfilename, array(), WATCHDOG_INFO, NULL); // log the wind speed $observation_log = log_type_load('farm_observation'); @@ -183,6 +186,7 @@ function farmosnws_save_feed_data($feedfilename) { $observation_log->timestamp = $xml->observation_time_rfc822; $observation_log->done = 1; log_save($observation_log); + watchdog('farmosnws', 'Wind speed data saved from ' . $feedfilename, array(), WATCHDOG_INFO, NULL); // log the wind direction $observation_log = log_type_load('farm_observation'); @@ -194,6 +198,7 @@ function farmosnws_save_feed_data($feedfilename) { $observation_log->timestamp = $xml->observation_time_rfc822; $observation_log->done = 1; log_save($observation_log); + watchdog('farmosnws', 'Wind direction data saved from ' . $feedfilename, array(), WATCHDOG_INFO, NULL); // log the barametric pressure $observation_log = log_type_load('farm_observation'); @@ -205,6 +210,7 @@ function farmosnws_save_feed_data($feedfilename) { $observation_log->timestamp = $xml->observation_time_rfc822; $observation_log->done = 1; log_save($observation_log); + watchdog('farmosnws', 'Barametric pressure data saved from ' . $feedfilename, array(), WATCHDOG_INFO, NULL); // log the visibility $observation_log = log_type_load('farm_observation'); @@ -216,5 +222,6 @@ function farmosnws_save_feed_data($feedfilename) { $observation_log->timestamp = $xml->observation_time_rfc822; $observation_log->done = 1; log_save($observation_log); + watchdog('farmosnws', 'Visibility data saved from ' . $feedfilename, array(), WATCHDOG_INFO, NULL); } From e4befce445919ed3d623c76e00bf38867fc6d23e Mon Sep 17 00:00:00 2001 From: Bit Second Date: Sat, 21 Oct 2017 14:40:39 -0500 Subject: [PATCH 39/75] Removed code related to node creation --- farmosnws.install | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/farmosnws.install b/farmosnws.install index a570c55..b4addc7 100644 --- a/farmosnws.install +++ b/farmosnws.install @@ -29,27 +29,7 @@ function farmosnws_uninstall() { foreach($result as $row) { variable_del($row->name); } // end foreach - - // delete all the nodes that have been created by the module - $query = "select nid where {node} where type = :ntype"; - $result = db_query($result, array(':ntype' => 'imported_weather_conditions')); - - foreach($result as $row) { - $nodes[] = $row->nid; - } - - if (!empty($nodes)) { - // delete the nodes - node_delete_multiple($nodes); - } - - // delete the content type - if ( node_type_load('imported_weather_conditions')) { - node_type_delete('imported_weather_conditions'); - drupal_set_message(t('%type content type has been deleted.', array('%type' => 'imported_weather_conditions'))); - } // end if - - node_types_rebuild(); + menu_rebuild(); watchdog('farmosnws', 'FarmOS NWS module has been uninstalled.', array(), WATCHDOG_INFO, NULL); From 24fa02598e479e8437981594b0cfc76a9cf4b2ef Mon Sep 17 00:00:00 2001 From: Bit Second Date: Sat, 21 Oct 2017 14:51:56 -0500 Subject: [PATCH 40/75] Updated comments --- farmosnws.admin.inc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/farmosnws.admin.inc b/farmosnws.admin.inc index 20ddcc6..dbcfd7e 100644 --- a/farmosnws.admin.inc +++ b/farmosnws.admin.inc @@ -3,6 +3,8 @@ /** * * Module configuration form + * + * @return Returns loaded form array object */ function farmosnws_admin_form() { $form = array(); From f49eb497d235995f52d77bfddc668d154aa1fe66 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Sat, 21 Oct 2017 15:32:55 -0500 Subject: [PATCH 41/75] Updated dependency name --- farmosnws.info | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/farmosnws.info b/farmosnws.info index 0145323..47bfc30 100644 --- a/farmosnws.info +++ b/farmosnws.info @@ -3,7 +3,7 @@ description = Imports data from the National Weather Service into Drupal for use core = 7.x package = farmOS version = 7.x-2.0-beta5 -dependencies[] = farmos_log_observation +dependencies[] = farm_log_observation files[] = farmosnws.module files[] = farmosnws.admin.inc From 97261804b92d2ca6e9b2c481a06179c5c2249a0a Mon Sep 17 00:00:00 2001 From: Bit Second Date: Sat, 21 Oct 2017 15:55:26 -0500 Subject: [PATCH 42/75] Added link to status message --- farmosnws.install | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/farmosnws.install b/farmosnws.install index b4addc7..3394525 100644 --- a/farmosnws.install +++ b/farmosnws.install @@ -12,9 +12,9 @@ function farmosnws_install() { * * implements hook_enable() */ -function hook_enable() { +function farmosnws_enable() { // notice to visit configuration page to set initial values for variables - drupal_set_message("Visit the module configuration page to complete setup.", 'warning', FALSE); + drupal_set_message(t("Visit the module " . l("configuration page", 'admin/config/services/farmosnws') . " to complete module setup."), 'warning', FALSE); } /** From 806d6e0607f10bf2997d3466c79a0e9bb5cc3fd0 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Sat, 21 Oct 2017 16:08:01 -0500 Subject: [PATCH 43/75] Corrected variable name --- farmosnws.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/farmosnws.module b/farmosnws.module index 00d0a35..ecd41f5 100644 --- a/farmosnws.module +++ b/farmosnws.module @@ -111,7 +111,7 @@ function farmosnws_get_xml() { $location_count = count($location_array); foreach ($location_array as $loc) { - $weather_feed_name = $weather_feed_dir . '/' . $uniqid($loc, FALSE) . '.xml'; + $weather_feed_name = $weatherfeedsdir . '/' . uniqid($loc, FALSE) . '.xml'; $url = "http://w1.weather.gov/xml/current_obs/" . $loc . ".xml"; watchdog('farmosnws', 'Getting weather data for ' . $loc, array(), WATCHDOG_INFO, NULL); From 6d665049b7c2af23e7aad98aecfe84b6041573b1 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Sat, 21 Oct 2017 17:02:33 -0500 Subject: [PATCH 44/75] Changed Locations from textarea to textfield --- farmosnws.admin.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/farmosnws.admin.inc b/farmosnws.admin.inc index dbcfd7e..c452751 100644 --- a/farmosnws.admin.inc +++ b/farmosnws.admin.inc @@ -18,9 +18,9 @@ function farmosnws_admin_form() { ); $form['farmosnws_locations'] = array( - '#type' => 'textarea', + '#type' => 'textfield', '#title' => t('Locations'), - '#description' => t('Enter the locations that you would like weather data pulled for. Each location must be entered on a separate line.'), + '#description' => t('Enter the locations that you would like weather data pulled for. Each location must be entered must be separated by commas.'), '#required' => TRUE, '#default_value' => variable_get('farmosnws_locations'), ); From 446c6648e67b236085dcbc3a9b9939dfd5f7703a Mon Sep 17 00:00:00 2001 From: Bit Second Date: Sat, 21 Oct 2017 17:06:33 -0500 Subject: [PATCH 45/75] Additional logging. Changed location string delimiter --- farmosnws.module | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/farmosnws.module b/farmosnws.module index ecd41f5..f4d9cd4 100644 --- a/farmosnws.module +++ b/farmosnws.module @@ -107,26 +107,36 @@ function farmosnws_get_xml() { $weatherfeedsdir = variable_get('farmosnws_weather_feeds_dir'); $locations = variable_get('farmosnws_locations', ''); - $location_array = explode("\n", $locations); + $location_array = explode(",", $locations); $location_count = count($location_array); foreach ($location_array as $loc) { + // remove carriage returns and new lines + $loc = str_replace(" ", "", str_replace("\r", "", str_replace("\n", "", $loc))); + // $loc = str_replace(" ", "", $loc); + $weather_feed_name = $weatherfeedsdir . '/' . uniqid($loc, FALSE) . '.xml'; $url = "http://w1.weather.gov/xml/current_obs/" . $loc . ".xml"; + + watchdog('farmosnws', $url, array(), WATCHDOG_DEBUG, NULL); watchdog('farmosnws', 'Getting weather data for ' . $loc, array(), WATCHDOG_INFO, NULL); $response = drupal_http_request($url, array()); - watchdog('farmosnws', 'Response code: ' . $response->code, array(), WATCHDOG_INFO, NULL); +// watchdog('farmosnws', 'Response code: ' . $response->code, array(), WATCHDOG_INFO, NULL); + + // watchdog('farmosnws', 'Response code: ' . $response->code . '. ' $response->error, array(), WATCHDOG_ERROR, NULL); // if error occurs when performing the request if ( $response->error ) { - watchdog('farmosnws', $response->error, array(), WATCHDOG_ERROR, NULL); - drupal_set_message($response->error, 'error', FALSE); + watchdog('farmosnws', 'Response code: ' . $response->code . '. ' . $response->error, array(), WATCHDOG_ERROR, NULL); + // drupal_set_message($response->error, 'error', FALSE); } // if no errors occur when performing the request else{ + watchdog('farmosnws', 'Response code: ' . $response->code, array(), WATCHDOG_INFO, NULL); + // if the directory doesnt exist, then create it with 755 permissions $direxist = farmosnws_create_feed_dir($weatherfeedsdir); @@ -138,6 +148,8 @@ function farmosnws_get_xml() { // save the contents retrieved file_put_contents($weather_feed_name, $response->data); watchdog('farmosnws', 'Weather data saved to ' . $weather_feed_name, array(), WATCHDOG_INFO, NULL); + + farmosnws_save_feed_data($weather_feed_name); } } // end else } // end foreach From 4c550063939eed663a053238ed990298492c4dc4 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Sat, 21 Oct 2017 17:18:57 -0500 Subject: [PATCH 46/75] Changed user fron anonymous to current user. Data is being pulled via cron. Related to #5 --- farmosnws.module | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/farmosnws.module b/farmosnws.module index f4d9cd4..0f28497 100644 --- a/farmosnws.module +++ b/farmosnws.module @@ -160,7 +160,8 @@ function farmosnws_get_xml() { * @param unknown $feedfilename */ function farmosnws_save_feed_data($feedfilename) { - + global $user; + // load the file $xml = simplexml_load_file($feedfilename); @@ -170,7 +171,7 @@ function farmosnws_save_feed_data($feedfilename) { $observation_log->field_farm_quantity_value = $xml->temp_f; $observation_log->field_farm_quantity_units = "Fahrenheit"; // $observation_log->field_farm_observation_type = ""; - $observation_log->field_farm_log_owner = 0; + $observation_log->field_farm_log_owner = $user->uid; $observation_log->timestamp = $xml->observation_time_rfc822; $observation_log->done = 1; log_save($observation_log); @@ -182,7 +183,7 @@ function farmosnws_save_feed_data($feedfilename) { $observation_log->field_farm_quantity_value = $xml->relative_humidity; $observation_log->field_farm_quantity_units = "% Humidity"; // $observation_log->field_farm_observation_type = ""; - $observation_log->field_farm_log_owner = 0; + $observation_log->field_farm_log_owner = $user->uid; $observation_log->timestamp = $xml->observation_time_rfc822; $observation_log->done = 1; log_save($observation_log); @@ -194,7 +195,7 @@ function farmosnws_save_feed_data($feedfilename) { $observation_log->field_farm_quantity_value = $xml->wind_mph; $observation_log->field_farm_quantity_units = "MPH"; // $observation_log->field_farm_observation_type = ""; - $observation_log->field_farm_log_owner = 0; + $observation_log->field_farm_log_owner = $user->uid; $observation_log->timestamp = $xml->observation_time_rfc822; $observation_log->done = 1; log_save($observation_log); @@ -206,7 +207,7 @@ function farmosnws_save_feed_data($feedfilename) { $observation_log->field_farm_quantity_value = $xml->wind_dir; $observation_log->field_farm_quantity_units = "Direction"; // $observation_log->field_farm_observation_type = ""; - $observation_log->field_farm_log_owner = 0; + $observation_log->field_farm_log_owner = $user->uid; $observation_log->timestamp = $xml->observation_time_rfc822; $observation_log->done = 1; log_save($observation_log); @@ -218,7 +219,7 @@ function farmosnws_save_feed_data($feedfilename) { $observation_log->field_farm_quantity_value = $xml->pressure_in; $observation_log->field_farm_quantity_units = "Inches"; // $observation_log->field_farm_observation_type = ""; - $observation_log->field_farm_log_owner = 0; + $observation_log->field_farm_log_owner = $user->uid; $observation_log->timestamp = $xml->observation_time_rfc822; $observation_log->done = 1; log_save($observation_log); @@ -230,7 +231,7 @@ function farmosnws_save_feed_data($feedfilename) { $observation_log->field_farm_quantity_value = $xml->visibility_mi; $observation_log->field_farm_quantity_units = "Miles"; // $observation_log->field_farm_observation_type = ""; - $observation_log->field_farm_log_owner = 0; + $observation_log->field_farm_log_owner = $user->uid; $observation_log->timestamp = $xml->observation_time_rfc822; $observation_log->done = 1; log_save($observation_log); From 74968afc1fd2dc913dc5c98da14b1a04f6ba167a Mon Sep 17 00:00:00 2001 From: Bit Second Date: Sat, 21 Oct 2017 18:14:08 -0500 Subject: [PATCH 47/75] Updated to use entity wrapper for saving data --- farmosnws.module | 145 ++++++++++++++++++++++++++--------------------- 1 file changed, 79 insertions(+), 66 deletions(-) diff --git a/farmosnws.module b/farmosnws.module index 0f28497..d4f2eb7 100644 --- a/farmosnws.module +++ b/farmosnws.module @@ -166,75 +166,88 @@ function farmosnws_save_feed_data($feedfilename) { $xml = simplexml_load_file($feedfilename); // log the temperature f - $observation_log = log_type_load('farm_observation'); - $observation_log->name = $xml->location . " at " . $xml->observation_time_rfc822; - $observation_log->field_farm_quantity_value = $xml->temp_f; - $observation_log->field_farm_quantity_units = "Fahrenheit"; - // $observation_log->field_farm_observation_type = ""; - $observation_log->field_farm_log_owner = $user->uid; - $observation_log->timestamp = $xml->observation_time_rfc822; - $observation_log->done = 1; - log_save($observation_log); +// $observation_log = log_type_load('farm_observation'); +// $observation_log->name = $xml->location . " at " . $xml->observation_time_rfc822; +// $observation_log->field_farm_quantity_value = $xml->temp_f; +// $observation_log->field_farm_quantity_units = "Fahrenheit"; +// // $observation_log->field_farm_observation_type = ""; +// $observation_log->field_farm_log_owner = $user->uid; +// $observation_log->timestamp = $xml->observation_time_rfc822; +// $observation_log->done = 1; +// log_save($observation_log); + + $log = entity_create('log', array('type' => 'farm_observation')); + $log_wrapper = entity_metadata_wrapper('log', $log); + $log_wrapper->name = $xml->location . " at " . $xml->observation_time_rfc822; + $log_wrapper->field_farm_quantity_value = $xml->temp_f; + $log_wrapper->field_farm_quantity_units = "Fahrenheit"; + // $log_wrapper->field_farm_observation_type = ""; + $log_wrapper->field_farm_log_owner = $user->uid; + $log_wrapper->timestamp = $xml->observation_time_rfc822; + $log_wrapper->done = 1; + + $log_wrapper->save(); + watchdog('farmosnws', 'Temperature data saved from ' . $feedfilename, array(), WATCHDOG_INFO, NULL); // log the relative humidity - $observation_log = log_type_load('farm_observation'); - $observation_log->name = $xml->location . " at " . $xml->observation_time_rfc822; - $observation_log->field_farm_quantity_value = $xml->relative_humidity; - $observation_log->field_farm_quantity_units = "% Humidity"; - // $observation_log->field_farm_observation_type = ""; - $observation_log->field_farm_log_owner = $user->uid; - $observation_log->timestamp = $xml->observation_time_rfc822; - $observation_log->done = 1; - log_save($observation_log); - watchdog('farmosnws', 'Relative humidity data saved from ' . $feedfilename, array(), WATCHDOG_INFO, NULL); +// $observation_log = log_type_load('farm_observation'); +// $observation_log->name = $xml->location . " at " . $xml->observation_time_rfc822; +// $observation_log->field_farm_quantity_value = $xml->relative_humidity; +// $observation_log->field_farm_quantity_units = "% Humidity"; +// // $observation_log->field_farm_observation_type = ""; +// $observation_log->field_farm_log_owner = $user->uid; +// $observation_log->timestamp = $xml->observation_time_rfc822; +// $observation_log->done = 1; +// log_save($observation_log); +// watchdog('farmosnws', 'Relative humidity data saved from ' . $feedfilename, array(), WATCHDOG_INFO, NULL); - // log the wind speed - $observation_log = log_type_load('farm_observation'); - $observation_log->name = $xml->location . " at " . $xml->observation_time_rfc822; - $observation_log->field_farm_quantity_value = $xml->wind_mph; - $observation_log->field_farm_quantity_units = "MPH"; - // $observation_log->field_farm_observation_type = ""; - $observation_log->field_farm_log_owner = $user->uid; - $observation_log->timestamp = $xml->observation_time_rfc822; - $observation_log->done = 1; - log_save($observation_log); - watchdog('farmosnws', 'Wind speed data saved from ' . $feedfilename, array(), WATCHDOG_INFO, NULL); - - // log the wind direction - $observation_log = log_type_load('farm_observation'); - $observation_log->name = $xml->location . " at " . $xml->observation_time_rfc822; - $observation_log->field_farm_quantity_value = $xml->wind_dir; - $observation_log->field_farm_quantity_units = "Direction"; - // $observation_log->field_farm_observation_type = ""; - $observation_log->field_farm_log_owner = $user->uid; - $observation_log->timestamp = $xml->observation_time_rfc822; - $observation_log->done = 1; - log_save($observation_log); - watchdog('farmosnws', 'Wind direction data saved from ' . $feedfilename, array(), WATCHDOG_INFO, NULL); - - // log the barametric pressure - $observation_log = log_type_load('farm_observation'); - $observation_log->name = $xml->location . " at " . $xml->observation_time_rfc822; - $observation_log->field_farm_quantity_value = $xml->pressure_in; - $observation_log->field_farm_quantity_units = "Inches"; - // $observation_log->field_farm_observation_type = ""; - $observation_log->field_farm_log_owner = $user->uid; - $observation_log->timestamp = $xml->observation_time_rfc822; - $observation_log->done = 1; - log_save($observation_log); - watchdog('farmosnws', 'Barametric pressure data saved from ' . $feedfilename, array(), WATCHDOG_INFO, NULL); - - // log the visibility - $observation_log = log_type_load('farm_observation'); - $observation_log->name = $xml->location . " at " . $xml->observation_time_rfc822; - $observation_log->field_farm_quantity_value = $xml->visibility_mi; - $observation_log->field_farm_quantity_units = "Miles"; - // $observation_log->field_farm_observation_type = ""; - $observation_log->field_farm_log_owner = $user->uid; - $observation_log->timestamp = $xml->observation_time_rfc822; - $observation_log->done = 1; - log_save($observation_log); - watchdog('farmosnws', 'Visibility data saved from ' . $feedfilename, array(), WATCHDOG_INFO, NULL); +// // log the wind speed +// $observation_log = log_type_load('farm_observation'); +// $observation_log->name = $xml->location . " at " . $xml->observation_time_rfc822; +// $observation_log->field_farm_quantity_value = $xml->wind_mph; +// $observation_log->field_farm_quantity_units = "MPH"; +// // $observation_log->field_farm_observation_type = ""; +// $observation_log->field_farm_log_owner = $user->uid; +// $observation_log->timestamp = $xml->observation_time_rfc822; +// $observation_log->done = 1; +// log_save($observation_log); +// watchdog('farmosnws', 'Wind speed data saved from ' . $feedfilename, array(), WATCHDOG_INFO, NULL); + +// // log the wind direction +// $observation_log = log_type_load('farm_observation'); +// $observation_log->name = $xml->location . " at " . $xml->observation_time_rfc822; +// $observation_log->field_farm_quantity_value = $xml->wind_dir; +// $observation_log->field_farm_quantity_units = "Direction"; +// // $observation_log->field_farm_observation_type = ""; +// $observation_log->field_farm_log_owner = $user->uid; +// $observation_log->timestamp = $xml->observation_time_rfc822; +// $observation_log->done = 1; +// log_save($observation_log); +// watchdog('farmosnws', 'Wind direction data saved from ' . $feedfilename, array(), WATCHDOG_INFO, NULL); + +// // log the barametric pressure +// $observation_log = log_type_load('farm_observation'); +// $observation_log->name = $xml->location . " at " . $xml->observation_time_rfc822; +// $observation_log->field_farm_quantity_value = $xml->pressure_in; +// $observation_log->field_farm_quantity_units = "Inches"; +// // $observation_log->field_farm_observation_type = ""; +// $observation_log->field_farm_log_owner = $user->uid; +// $observation_log->timestamp = $xml->observation_time_rfc822; +// $observation_log->done = 1; +// log_save($observation_log); +// watchdog('farmosnws', 'Barametric pressure data saved from ' . $feedfilename, array(), WATCHDOG_INFO, NULL); + +// // log the visibility +// $observation_log = log_type_load('farm_observation'); +// $observation_log->name = $xml->location . " at " . $xml->observation_time_rfc822; +// $observation_log->field_farm_quantity_value = $xml->visibility_mi; +// $observation_log->field_farm_quantity_units = "Miles"; +// // $observation_log->field_farm_observation_type = ""; +// $observation_log->field_farm_log_owner = $user->uid; +// $observation_log->timestamp = $xml->observation_time_rfc822; +// $observation_log->done = 1; +// log_save($observation_log); +// watchdog('farmosnws', 'Visibility data saved from ' . $feedfilename, array(), WATCHDOG_INFO, NULL); } From 7e5f48c7e8bc4c5e4d86f3377662f44039f90dbc Mon Sep 17 00:00:00 2001 From: Bit Second Date: Sat, 21 Oct 2017 21:54:31 -0500 Subject: [PATCH 48/75] Updated dependencies --- farmosnws.info | 1 + 1 file changed, 1 insertion(+) diff --git a/farmosnws.info b/farmosnws.info index 47bfc30..1b70fad 100644 --- a/farmosnws.info +++ b/farmosnws.info @@ -3,6 +3,7 @@ description = Imports data from the National Weather Service into Drupal for use core = 7.x package = farmOS version = 7.x-2.0-beta5 +dependencies[] = farm_quantity dependencies[] = farm_log_observation files[] = farmosnws.module From b9da0e31b8067b602a1840c205a4d46262734531 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Sat, 21 Oct 2017 21:56:46 -0500 Subject: [PATCH 49/75] Added using taxonomy terms --- farmosnws.install | 13 ++++++ farmosnws.module | 103 +++++++++++++--------------------------------- 2 files changed, 42 insertions(+), 74 deletions(-) diff --git a/farmosnws.install b/farmosnws.install index 3394525..130dfef 100644 --- a/farmosnws.install +++ b/farmosnws.install @@ -5,6 +5,19 @@ * implements hook_install() */ function farmosnws_install() { + // check for the Fahrenheit taxonomy type + $taxterm = taxonomy_get_term_by_name('Fahrenheit'); + + if (count($taxterm) == 0) { + $term = new stdClass(); + $term->name = "Fahrenheit"; + + $vocab = taxonomy_vocabulary_machine_name_load('Farm Quantity Units'); + + $term->vid = $vocab->vid; + taxonomy_term_save($term); + } + watchdog('farmosnws', 'FarmOS NWS module has been installed.', array(), WATCHDOG_INFO, NULL); } diff --git a/farmosnws.module b/farmosnws.module index d4f2eb7..781285f 100644 --- a/farmosnws.module +++ b/farmosnws.module @@ -166,88 +166,43 @@ function farmosnws_save_feed_data($feedfilename) { $xml = simplexml_load_file($feedfilename); // log the temperature f -// $observation_log = log_type_load('farm_observation'); -// $observation_log->name = $xml->location . " at " . $xml->observation_time_rfc822; -// $observation_log->field_farm_quantity_value = $xml->temp_f; -// $observation_log->field_farm_quantity_units = "Fahrenheit"; -// // $observation_log->field_farm_observation_type = ""; -// $observation_log->field_farm_log_owner = $user->uid; -// $observation_log->timestamp = $xml->observation_time_rfc822; -// $observation_log->done = 1; -// log_save($observation_log); + + $qty = entity_create('farm_quantity', array('type' => 'farm_quantity')); + $qty->value = $xml->temp_f; + entity_save('farm_quantity', $qty); $log = entity_create('log', array('type' => 'farm_observation')); - $log_wrapper = entity_metadata_wrapper('log', $log); - $log_wrapper->name = $xml->location . " at " . $xml->observation_time_rfc822; - $log_wrapper->field_farm_quantity_value = $xml->temp_f; - $log_wrapper->field_farm_quantity_units = "Fahrenheit"; - // $log_wrapper->field_farm_observation_type = ""; - $log_wrapper->field_farm_log_owner = $user->uid; - $log_wrapper->timestamp = $xml->observation_time_rfc822; - $log_wrapper->done = 1; - - $log_wrapper->save(); + # $log->field_farm_notes + // $log_wrapper = entity_metadata_wrapper('log', $log); + // $log_wrapper->name = $xml->location . " at " . $xml->observation_time_rfc822; + // $log->name = $xml->location . " at " . $xml->observation_time_rfc822; + // $log->done = 1; + // $log->timestamp = strtotime($xml->observation_time_rfc822); + + /* + $qty = entity_create('farm_quantity', array('type' => 'farm_quantity')); + $qty->value = strval($xml->temp_f); + $qty->units = 'Fahrenheit'; + entity_save('farm_quantity', $qty); + $log->field_farm_quantity = $qty; + */ + + $etl = entity_load('log', array('102')); + print_r($etl); + + print("Temperature " . $xml->temp_f . "\r\n"); + watchdog('farmosnws', 'Temperature data saved from ' . $feedfilename, array(), WATCHDOG_INFO, NULL); // log the relative humidity -// $observation_log = log_type_load('farm_observation'); -// $observation_log->name = $xml->location . " at " . $xml->observation_time_rfc822; -// $observation_log->field_farm_quantity_value = $xml->relative_humidity; -// $observation_log->field_farm_quantity_units = "% Humidity"; -// // $observation_log->field_farm_observation_type = ""; -// $observation_log->field_farm_log_owner = $user->uid; -// $observation_log->timestamp = $xml->observation_time_rfc822; -// $observation_log->done = 1; -// log_save($observation_log); -// watchdog('farmosnws', 'Relative humidity data saved from ' . $feedfilename, array(), WATCHDOG_INFO, NULL); -// // log the wind speed -// $observation_log = log_type_load('farm_observation'); -// $observation_log->name = $xml->location . " at " . $xml->observation_time_rfc822; -// $observation_log->field_farm_quantity_value = $xml->wind_mph; -// $observation_log->field_farm_quantity_units = "MPH"; -// // $observation_log->field_farm_observation_type = ""; -// $observation_log->field_farm_log_owner = $user->uid; -// $observation_log->timestamp = $xml->observation_time_rfc822; -// $observation_log->done = 1; -// log_save($observation_log); -// watchdog('farmosnws', 'Wind speed data saved from ' . $feedfilename, array(), WATCHDOG_INFO, NULL); - -// // log the wind direction -// $observation_log = log_type_load('farm_observation'); -// $observation_log->name = $xml->location . " at " . $xml->observation_time_rfc822; -// $observation_log->field_farm_quantity_value = $xml->wind_dir; -// $observation_log->field_farm_quantity_units = "Direction"; -// // $observation_log->field_farm_observation_type = ""; -// $observation_log->field_farm_log_owner = $user->uid; -// $observation_log->timestamp = $xml->observation_time_rfc822; -// $observation_log->done = 1; -// log_save($observation_log); -// watchdog('farmosnws', 'Wind direction data saved from ' . $feedfilename, array(), WATCHDOG_INFO, NULL); + // log the wind speed -// // log the barametric pressure -// $observation_log = log_type_load('farm_observation'); -// $observation_log->name = $xml->location . " at " . $xml->observation_time_rfc822; -// $observation_log->field_farm_quantity_value = $xml->pressure_in; -// $observation_log->field_farm_quantity_units = "Inches"; -// // $observation_log->field_farm_observation_type = ""; -// $observation_log->field_farm_log_owner = $user->uid; -// $observation_log->timestamp = $xml->observation_time_rfc822; -// $observation_log->done = 1; -// log_save($observation_log); -// watchdog('farmosnws', 'Barametric pressure data saved from ' . $feedfilename, array(), WATCHDOG_INFO, NULL); + // log the wind direction + + // log the barametric pressure -// // log the visibility -// $observation_log = log_type_load('farm_observation'); -// $observation_log->name = $xml->location . " at " . $xml->observation_time_rfc822; -// $observation_log->field_farm_quantity_value = $xml->visibility_mi; -// $observation_log->field_farm_quantity_units = "Miles"; -// // $observation_log->field_farm_observation_type = ""; -// $observation_log->field_farm_log_owner = $user->uid; -// $observation_log->timestamp = $xml->observation_time_rfc822; -// $observation_log->done = 1; -// log_save($observation_log); -// watchdog('farmosnws', 'Visibility data saved from ' . $feedfilename, array(), WATCHDOG_INFO, NULL); + // log the visibility } From d014121e0095fc577922e170a2c38848b1e2dd29 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Sat, 21 Oct 2017 23:00:36 -0500 Subject: [PATCH 50/75] Added measurement to admin form --- farmosnws.admin.inc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/farmosnws.admin.inc b/farmosnws.admin.inc index c452751..d063b56 100644 --- a/farmosnws.admin.inc +++ b/farmosnws.admin.inc @@ -25,6 +25,18 @@ function farmosnws_admin_form() { '#default_value' => variable_get('farmosnws_locations'), ); + $form['farmosnws_temp_units'] = array( + '#type' => 'select', + '#title' => t('Measurement Units'), + '#required' => TRUE, + '#options' => array( + 'us' => t('Fahrenheit'), + 'metric' => t('Celsius'), + ), + '#description' => t('Select the system of measurement that you would like to use.'), + '#default_value' => variable_get('farmosnws_temp_units'), + ); + return system_settings_form($form); } From 2df9c2fd15232aa90d1c12d7038bd4460e060acb Mon Sep 17 00:00:00 2001 From: Bit Second Date: Sat, 21 Oct 2017 23:01:29 -0500 Subject: [PATCH 51/75] Updated taxonomy usage for Units and Observartion types --- farmosnws.install | 60 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/farmosnws.install b/farmosnws.install index 130dfef..bbf5931 100644 --- a/farmosnws.install +++ b/farmosnws.install @@ -5,19 +5,55 @@ * implements hook_install() */ function farmosnws_install() { - // check for the Fahrenheit taxonomy type - $taxterm = taxonomy_get_term_by_name('Fahrenheit'); - - if (count($taxterm) == 0) { - $term = new stdClass(); - $term->name = "Fahrenheit"; - - $vocab = taxonomy_vocabulary_machine_name_load('Farm Quantity Units'); - - $term->vid = $vocab->vid; - taxonomy_term_save($term); + + // add the quantity types + + // get the vocabulary ID so that the terms can be properly associated + $vocab_qty_units = taxonomy_vocabulary_machine_name_load('farm_quantity_units'); + + $terms_qty_list = array( + 'Fahrenheit', + 'Celsius', + 'Percent Humdity', + 'Direction', + 'Inches', + 'MPH', + 'Miles', + ); + + // check if the term exists, if it does not then skip it + foreach($terms_qty_list as $term_qty_item) { + $taxterm = taxonomy_get_term_by_name($term_qty_item, 'farm_quantity_units'); + + if (count($taxterm) == 0) { + $tax_qty_term = new stdClass(); + $tax_qty_term->name = $term_qty_item; + $tax_qty_term->vid = $vocab_qty_units->vid; + taxonomy_term_save($tax_qty_term); + + watchdog('farmosnws', 'Created ' . $term_item . ' taxonomy term.', array(), WATCHDOG_INFO, NULL); + } } - + + // add the observation types + + $vocab_observ_types = taxonomy_vocabulary_machine_name_load('farm_observation_types'); + $terms_observ_list = array('Temperature'); + + foreach($terms_observ_list as $term_observ_item) { + $tax_observ_term = taxonomy_get_term_by_name($$term_observ_item, 'farm_observation_types'); + + if (count($tax_observ_term) == 0){ + $tax_observ_new = new stdClass(); + $tax_observ_new->name = $term_observ_item; + $tax_observ_new->vid = $vocab_observ_types->vid; + taxonomy_term_save($tax_observ_new); + } + } + + // set the default units to use + variable_set('farmosnws_temp_units', 'us'); + watchdog('farmosnws', 'FarmOS NWS module has been installed.', array(), WATCHDOG_INFO, NULL); } From 0888664caf3ebd820d5f6c149134fd256b83b1bd Mon Sep 17 00:00:00 2001 From: Bit Second Date: Sat, 21 Oct 2017 23:45:42 -0500 Subject: [PATCH 52/75] Updated entity creating --- farmosnws.module | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/farmosnws.module b/farmosnws.module index 781285f..8427d9f 100644 --- a/farmosnws.module +++ b/farmosnws.module @@ -158,6 +158,9 @@ function farmosnws_get_xml() { /** * * @param unknown $feedfilename + * + * @tutorial http://audiblecode.com/blog/programmatically-create-and-update-field-collection-item-node-entity-api + * @tutorial http://drupal.org/node/1842304 */ function farmosnws_save_feed_data($feedfilename) { global $user; @@ -165,33 +168,30 @@ function farmosnws_save_feed_data($feedfilename) { // load the file $xml = simplexml_load_file($feedfilename); - // log the temperature f - $qty = entity_create('farm_quantity', array('type' => 'farm_quantity')); $qty->value = $xml->temp_f; entity_save('farm_quantity', $qty); $log = entity_create('log', array('type' => 'farm_observation')); - # $log->field_farm_notes - // $log_wrapper = entity_metadata_wrapper('log', $log); - // $log_wrapper->name = $xml->location . " at " . $xml->observation_time_rfc822; - // $log->name = $xml->location . " at " . $xml->observation_time_rfc822; - // $log->done = 1; - // $log->timestamp = strtotime($xml->observation_time_rfc822); - - /* + $log_wrapper = entity_metadata_wrapper('log', $log); + $log_wrapper->field_farm_notes->set($xml); + $log_wrapper->done = 1; + $log_wrapper->name = $xml->location . " at " . $xml->observation_time_rfc822; + $log_wrapper->timestamp = strtotime($xml->observation_time_rfc822); + $log_wrapper->save(); + + $qty = entity_create('farm_quantity', array('type' => 'farm_quantity')); $qty->value = strval($xml->temp_f); $qty->units = 'Fahrenheit'; entity_save('farm_quantity', $qty); - $log->field_farm_quantity = $qty; - */ - - $etl = entity_load('log', array('102')); - print_r($etl); + // $etl = entity_load('log', array('102')); + // print_r($etl); - print("Temperature " . $xml->temp_f . "\r\n"); + // print("Temperature " . $xml->temp_f . "\r\n"); + + watchdog('farmosnws', 'Temperature data saved from ' . $feedfilename, array(), WATCHDOG_INFO, NULL); From 22c94d5b86aecaec568de1885c99afd0c9079955 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Thu, 21 Dec 2017 18:58:38 -0600 Subject: [PATCH 53/75] Removed MKDocs documentation --- docs/credits.md | 17 ---------- docs/index.md | 14 --------- docs/setup.md | 82 ------------------------------------------------- docs/updates.md | 18 ----------- mkdocs.yml | 14 --------- 5 files changed, 145 deletions(-) delete mode 100644 docs/credits.md delete mode 100644 docs/index.md delete mode 100644 docs/setup.md delete mode 100644 docs/updates.md delete mode 100644 mkdocs.yml diff --git a/docs/credits.md b/docs/credits.md deleted file mode 100644 index 6e316e3..0000000 --- a/docs/credits.md +++ /dev/null @@ -1,17 +0,0 @@ -# Credits - -## Author -Kenny Robinson, Bit Second Tech (www.bitsecondtech.com) - -## 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. - -## License -Project is available under the MIT License. See LICENSE for more information. - diff --git a/docs/index.md b/docs/index.md deleted file mode 100644 index a90742b..0000000 --- a/docs/index.md +++ /dev/null @@ -1,14 +0,0 @@ -# FarmOS NWS -A Drupal module to allow automated importing of National Weather Service (NWS) data into FarmOS. - -## Purpose -The purpose of this project is to allow FarmOS to use data from the National -Weather Service to allow it to make better decisions as well as to log -data from a trusted weather source. - -Bit Second noticed that some small farmers and gardeners do not have the -financial resources to deploy many sensors for their FarmOS installation. -However, by combining the data provide from the local NWS weather station and -using additional Drupal modules, FarmOS can be better automated with a lower -investment. - diff --git a/docs/setup.md b/docs/setup.md deleted file mode 100644 index c57921f..0000000 --- a/docs/setup.md +++ /dev/null @@ -1,82 +0,0 @@ -# Setup - -## System Requirements -* Drupal 7 -* FarmOS -* Ubuntu Linux (May run on other Linux versions, but has only be tested with Ubuntu Linux 14.04 LTS) -* PHP 5 -* Crontab or other task scheduler capable of running shell scripts - -## Instructions - -1) Clone this repository by running the command below -```shell -git clone https://github.com/bitsecondal/farmosnws.git -``` - -2) Install the module in Drupal - -3) Go to the module configuration page. - -4) Go to the [XML data feeds](http://w1.weather.gov/xml/current_obs/) page on the NWS website. - -5) Select the state and click Find - -6) Find the location that is closest to the area that you want to pull data for. - -7) In the parenthesis next to the location, you will see a 4-character code. Copy this code. - -8) Place the 4-character code on a line in the text box. If you have multiple locations that you -want to pull the data for, then enter each one on a separate line. - -9) Enter the path where the weather files are to be saved on the server. This will be the same location -that the Feeds module will import the files from. - -10) Click *Save configuration* on the form. - -11) Go to the *Feeds importer* (Structure > Feeds importer) page - -12) Create a new importer and name it. - -13) Select the *XPath XML Parser* as the parser. - -14) Enter each of the elements that you want to capture in the Parser Settings. - -15) Configure the remainder of the settings for the Feeds Importer. - -## Schedule Script -No scheduling has to be done. Weather data will be automatically be pulled when Drupal cron run. If -necessary, adjust Drupal cron frequency or use [Elysia Cron](https://www.drupal.org/project/elysia_cron) -to run module specific cron. - -## Get Weather Data via Shell Script (Advanced) -### Create Configuration File -Make a copy of the get_weather_config_ex.sh file. Update the variables located in the configuration -script file. - -The *feedsdir* location will need to be updated to the file system location that -Drupal is checking to see if data files are available. - -The *location* variable will need to be updated to the location code for the location -that you want data for. -* Go to the [XML data feeds](http://w1.weather.gov/xml/current_obs/) page on the NWS website. -* Select the state and click Find -* Find the location that is closest to the area that you want to pull data for. -* In the parenthesis next to the location, you will see a 4-character code. Copy this code. -* Place the 4-character code in the configuration file inside quotes. -* Save the configuration file. - -If you have multiple locations that you want to pull data for, you will need to create a configuration -file for each location and set up a scheduled task for each configuration file. - -## Schedule Script -To set up a cron job to run to automatically pull the latest weather data, you use the details and -steps below. The National Weather Service updates the data hourly. - -## Linux/Ubuntu with Crontab -Update the paths mentioned to the location of your script and the location of your configuration -file respectively. If you want to log the output of the script, also update the log location. -```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 -``` - diff --git a/docs/updates.md b/docs/updates.md deleted file mode 100644 index fc5596f..0000000 --- a/docs/updates.md +++ /dev/null @@ -1,18 +0,0 @@ -# Updates and Defects - -## 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: -```shell -git pull origin master -``` - -## 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. Include -as much detail as possible, including screenshots and error messages, so that the issue can be replicated. - diff --git a/mkdocs.yml b/mkdocs.yml deleted file mode 100644 index 8f337db..0000000 --- a/mkdocs.yml +++ /dev/null @@ -1,14 +0,0 @@ -site_name: FarmOS NWS -site_url: http://bitsecondal.github.io/farmosnws -repo_url: https://github.com/bitsecondal/farmosnws.git -site_author: Kenny Robinson -remote_branch: gh-pages -remote_name: origin -use_directory_urls: true -strict: true -dev_addr: 0.0.0.0:8000 -pages: -- Home: index.md -- Setup: setup.md -- Updates: updates.md -- Credits: credits.md From 38f2966bd1b926f0125b9cc425d82755cd370698 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Thu, 21 Dec 2017 20:15:57 -0600 Subject: [PATCH 54/75] Updated admin form. Quantity collection updated --- farmosnws.admin.inc | 5 +--- farmosnws.module | 68 ++++++++++++--------------------------------- 2 files changed, 18 insertions(+), 55 deletions(-) diff --git a/farmosnws.admin.inc b/farmosnws.admin.inc index d063b56..cfed97e 100644 --- a/farmosnws.admin.inc +++ b/farmosnws.admin.inc @@ -49,10 +49,7 @@ function farmosnws_admin_form_validate($form, &$form_state) { $direxist = farmosnws_create_feed_dir($weatherfeedsdir); if ( $direxist == FALSE ){ - watchdog('farmosnws', 'Unable to create the weather feed directory.', array(), WATCHDOG_ERROR, NULL); + // watchdog('farmosnws', 'Unable to create the weather feed directory.', array(), WATCHDOG_ERROR, NULL); form_set_error('farmosnws_weather_feeds_dir', 'The weather feed directory cannot be created. Please verify that Drupal as write permissions and try again.'); } - else { - // watchdog('farmosnws', 'Created weather feed directory.', array(), WATCHDOG_INFO, NULL); - } // end if } // end if diff --git a/farmosnws.module b/farmosnws.module index 8427d9f..b1a811f 100644 --- a/farmosnws.module +++ b/farmosnws.module @@ -21,7 +21,7 @@ function farmosnws_menu() { 'access arguments' => array('access administration pages'), 'file' => 'farmosnws.admin.inc', ); - + return $items; } @@ -30,41 +30,8 @@ function farmosnws_menu() { * Implements hook_cron() */ function farmosnws_cron() { - /* - $pullfeed = farmosnws_get_new_feed(); - - if ($pullfeed == TRUE) { - farmosnws_get_xml(); - variable_set('farmosnws_cron_last', REQUEST_TIME); - } - else { - watchdog('farmosnws', 'Skipping pulling weather feed.', array(), WATCHDOG_INFO, NULL); - } - */ - farmosnws_get_xml(); - variable_set('farmosnws_cron_last', REQUEST_TIME); -} - -/** - * - * Determine whether to pull the data feed from the NWS based on when cron was last run - * - * @return - * Returns whether the feed should be pulled or not. - */ -function farmosnws_feed_limiter() { - $cron_last = variable_get('farmosnws_cron_last', 0); - $time_diff = REQUEST_TIME - $cron_last; - - // if the feed was last pulled over an hour ago, then set value to true. - if ($time_diff >= 3600) { - $returnval = TRUE; - } - else { - $returnval = FALSE; - } - return $returnval; + // farmosnws_load_xml(); } /** @@ -108,7 +75,6 @@ function farmosnws_get_xml() { $locations = variable_get('farmosnws_locations', ''); $location_array = explode(",", $locations); - $location_count = count($location_array); foreach ($location_array as $loc) { // remove carriage returns and new lines @@ -131,25 +97,25 @@ function farmosnws_get_xml() { // if error occurs when performing the request if ( $response->error ) { watchdog('farmosnws', 'Response code: ' . $response->code . '. ' . $response->error, array(), WATCHDOG_ERROR, NULL); - // drupal_set_message($response->error, 'error', FALSE); + drupal_set_message($response->error, 'error', FALSE); } - // if no errors occur when performing the request else{ + // if no errors occur when performing the request watchdog('farmosnws', 'Response code: ' . $response->code, array(), WATCHDOG_INFO, NULL); // if the directory doesnt exist, then create it with 755 permissions $direxist = farmosnws_create_feed_dir($weatherfeedsdir); - if ( $direxist == FALSE ) { - drupal_set_message("Feed could not be downloaded because the directory does not exist. Please verify that Drupal has write access and try again.", 'error', FALSE); - watchdog('farmosnws', 'Feed could not be downloaded because the directory does not exist.', array(), WATCHDOG_ERROR, NULL); - } // end if - else { + if ( $direxist == TRUE ) { // save the contents retrieved file_put_contents($weather_feed_name, $response->data); watchdog('farmosnws', 'Weather data saved to ' . $weather_feed_name, array(), WATCHDOG_INFO, NULL); - - farmosnws_save_feed_data($weather_feed_name); + + farmosnws_load_xml($weather_feed_name); + } + else { + drupal_set_message("Feed could not be downloaded because the directory does not exist. Please verify that Drupal has write access and try again.", 'error', FALSE); + watchdog('farmosnws', 'Feed could not be downloaded because the directory does not exist.', array(), WATCHDOG_ERROR, NULL); } } // end else } // end foreach @@ -162,16 +128,18 @@ function farmosnws_get_xml() { * @tutorial http://audiblecode.com/blog/programmatically-create-and-update-field-collection-item-node-entity-api * @tutorial http://drupal.org/node/1842304 */ -function farmosnws_save_feed_data($feedfilename) { +function farmosnws_load_xml($feedfilename) { global $user; // load the file $xml = simplexml_load_file($feedfilename); + /* $qty = entity_create('farm_quantity', array('type' => 'farm_quantity')); $qty->value = $xml->temp_f; entity_save('farm_quantity', $qty); - +*/ + $log = entity_create('log', array('type' => 'farm_observation')); $log_wrapper = entity_metadata_wrapper('log', $log); $log_wrapper->field_farm_notes->set($xml); @@ -179,11 +147,11 @@ function farmosnws_save_feed_data($feedfilename) { $log_wrapper->name = $xml->location . " at " . $xml->observation_time_rfc822; $log_wrapper->timestamp = strtotime($xml->observation_time_rfc822); $log_wrapper->save(); - - + $qty = entity_create('farm_quantity', array('type' => 'farm_quantity')); $qty->value = strval($xml->temp_f); $qty->units = 'Fahrenheit'; + $qty->id = $log_wrapper->id; entity_save('farm_quantity', $qty); // $etl = entity_load('log', array('102')); @@ -191,8 +159,6 @@ function farmosnws_save_feed_data($feedfilename) { // print("Temperature " . $xml->temp_f . "\r\n"); - - watchdog('farmosnws', 'Temperature data saved from ' . $feedfilename, array(), WATCHDOG_INFO, NULL); // log the relative humidity From ab0a8bda4e99592dc8163a05f573f5c4d57a6be5 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Thu, 21 Dec 2017 20:16:50 -0600 Subject: [PATCH 55/75] Updated version number --- farmosnws.info | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/farmosnws.info b/farmosnws.info index 1b70fad..0b97ba8 100644 --- a/farmosnws.info +++ b/farmosnws.info @@ -2,7 +2,7 @@ name = FarmOS NWS description = Imports data from the National Weather Service into Drupal for use by FarmOS. core = 7.x package = farmOS -version = 7.x-2.0-beta5 +version = 7.x-2.0-beta6 dependencies[] = farm_quantity dependencies[] = farm_log_observation From 20e73670a6608fa6a2d5e38420f19171d9d49f25 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Thu, 21 Dec 2017 20:45:14 -0600 Subject: [PATCH 56/75] Saving numeric temperature --- farmosnws.module | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/farmosnws.module b/farmosnws.module index b1a811f..667e912 100644 --- a/farmosnws.module +++ b/farmosnws.module @@ -142,7 +142,8 @@ function farmosnws_load_xml($feedfilename) { $log = entity_create('log', array('type' => 'farm_observation')); $log_wrapper = entity_metadata_wrapper('log', $log); - $log_wrapper->field_farm_notes->set($xml); + $log_wrapper->field_farm_notes->set($xml->temp_c); + $log_wrapper->field_farm_quantity = intval($xml->temp_f); $log_wrapper->done = 1; $log_wrapper->name = $xml->location . " at " . $xml->observation_time_rfc822; $log_wrapper->timestamp = strtotime($xml->observation_time_rfc822); From a7bef74cb3df458ed3c03590c3a1476719e0bd1a Mon Sep 17 00:00:00 2001 From: Bit Second Date: Thu, 21 Dec 2017 22:10:00 -0600 Subject: [PATCH 57/75] Created Feeds importer --- .../farmosnws_importer.features.inc | 14 ++++ ...mosnws_importer.feeds_importer_default.inc | 77 +++++++++++++++++++ farmosnws_importer/farmosnws_importer.info | 14 ++++ farmosnws_importer/farmosnws_importer.module | 7 ++ 4 files changed, 112 insertions(+) create mode 100644 farmosnws_importer/farmosnws_importer.features.inc create mode 100644 farmosnws_importer/farmosnws_importer.feeds_importer_default.inc create mode 100644 farmosnws_importer/farmosnws_importer.info create mode 100644 farmosnws_importer/farmosnws_importer.module diff --git a/farmosnws_importer/farmosnws_importer.features.inc b/farmosnws_importer/farmosnws_importer.features.inc new file mode 100644 index 0000000..1685b53 --- /dev/null +++ b/farmosnws_importer/farmosnws_importer.features.inc @@ -0,0 +1,14 @@ + "1"); + } +} diff --git a/farmosnws_importer/farmosnws_importer.feeds_importer_default.inc b/farmosnws_importer/farmosnws_importer.feeds_importer_default.inc new file mode 100644 index 0000000..65eb978 --- /dev/null +++ b/farmosnws_importer/farmosnws_importer.feeds_importer_default.inc @@ -0,0 +1,77 @@ +disabled = FALSE; /* Edit this to true to make a default feeds_importer disabled initially */ + $feeds_importer->api_version = 1; + $feeds_importer->id = 'log_nws_observation'; + $feeds_importer->config = array( + 'name' => 'Log: NWS Observation', + 'description' => 'Weather observation from the National Weather Service.', + 'fetcher' => array( + 'plugin_key' => 'feeds_fetcher_directory_fetcher', + 'config' => array( + 'recursive' => 1, + 'directory' => 'public://feeds/curweather', + 'filemask' => '/\\.xml$/', + 'updated_files' => 0, + 'after_processed' => '0', + 'move_to_folder' => '', + ), + ), + 'parser' => array( + 'plugin_key' => 'FeedsXPathParserXML', + 'config' => array( + 'sources' => array(), + 'rawXML' => array(), + 'context' => '', + 'exp' => array( + 'errors' => FALSE, + 'tidy' => FALSE, + 'debug' => array(), + 'tidy_encoding' => 'UTF8', + ), + 'allow_override' => TRUE, + ), + ), + 'processor' => array( + 'plugin_key' => 'LogProcessor', + 'config' => array( + 'author' => '0', + 'authorize' => 0, + 'mappings' => array( + 0 => array( + 'source' => 'xpathparser:0', + 'target' => 'field_farm_quantity:field_farm_quantity_value', + 'unique' => FALSE, + ), + ), + 'insert_new' => '1', + 'update_existing' => '0', + 'update_non_existent' => 'skip', + 'input_format' => 'plain_text', + 'skip_hash_check' => 0, + 'bundle' => 'farm_observation', + 'language' => 'und', + ), + ), + 'content_type' => '', + 'update' => 0, + 'import_period' => '1800', + 'expire_period' => 3600, + 'import_on_create' => 1, + 'process_in_background' => 1, + ); + $export['log_nws_observation'] = $feeds_importer; + + return $export; +} diff --git a/farmosnws_importer/farmosnws_importer.info b/farmosnws_importer/farmosnws_importer.info new file mode 100644 index 0000000..3e203eb --- /dev/null +++ b/farmosnws_importer/farmosnws_importer.info @@ -0,0 +1,14 @@ +name = FarmOS NWS Feeds Importer +description = Import National Weather Service (NWS) data into FarmOS. +core = 7.x +package = farmOS Addons +version = 7.x-2.0-beta7 +dependencies[] = ctools +dependencies[] = feeds +dependencies[] = feeds_fetcher_directory +dependencies[] = feeds_xpathparser +dependencies[] = log +features[ctools][] = feeds:feeds_importer_default:1 +features[features_api][] = api:2 +features[feeds_importer][] = log_nws_observation +project path = sites/all/modules/custom/farmosnws diff --git a/farmosnws_importer/farmosnws_importer.module b/farmosnws_importer/farmosnws_importer.module new file mode 100644 index 0000000..942f466 --- /dev/null +++ b/farmosnws_importer/farmosnws_importer.module @@ -0,0 +1,7 @@ + Date: Thu, 21 Dec 2017 22:28:12 -0600 Subject: [PATCH 58/75] Added split function. --- farmosnws.module | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/farmosnws.module b/farmosnws.module index 667e912..d714c4f 100644 --- a/farmosnws.module +++ b/farmosnws.module @@ -111,7 +111,8 @@ function farmosnws_get_xml() { file_put_contents($weather_feed_name, $response->data); watchdog('farmosnws', 'Weather data saved to ' . $weather_feed_name, array(), WATCHDOG_INFO, NULL); - farmosnws_load_xml($weather_feed_name); + // farmosnws_load_xml($weather_feed_name); + // farmosnws_split_xml($weather_feed_name); } else { drupal_set_message("Feed could not be downloaded because the directory does not exist. Please verify that Drupal has write access and try again.", 'error', FALSE); @@ -121,6 +122,17 @@ function farmosnws_get_xml() { } // end foreach } // end function +/** + * + * @feedfilename string File name that will be split into smaller feeds + * + */ +function farmosnws_split_xml($feedfilename) { + $xml = simplexml_load_file($feedfilename); + + +} + /** * * @param unknown $feedfilename @@ -142,8 +154,10 @@ function farmosnws_load_xml($feedfilename) { $log = entity_create('log', array('type' => 'farm_observation')); $log_wrapper = entity_metadata_wrapper('log', $log); - $log_wrapper->field_farm_notes->set($xml->temp_c); - $log_wrapper->field_farm_quantity = intval($xml->temp_f); + print "Temp F: " . $xml->temp_f . "\r\n"; + $log_wrapper->field_farm_notes = $xml->temp_f; + print "Temp F int: " . intval($xml->temp_f); + $log_wrapper->field_farm_quantity->value = intval($xml->temp_f); $log_wrapper->done = 1; $log_wrapper->name = $xml->location . " at " . $xml->observation_time_rfc822; $log_wrapper->timestamp = strtotime($xml->observation_time_rfc822); From 343ce76cbd4af91d94f620b6aea4fc7e2ba37598 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Fri, 22 Dec 2017 00:06:31 -0600 Subject: [PATCH 59/75] XML to CSV conversion added --- farmosnws.module | 137 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 134 insertions(+), 3 deletions(-) diff --git a/farmosnws.module b/farmosnws.module index d714c4f..db771df 100644 --- a/farmosnws.module +++ b/farmosnws.module @@ -127,10 +127,141 @@ function farmosnws_get_xml() { * @feedfilename string File name that will be split into smaller feeds * */ -function farmosnws_split_xml($feedfilename) { - $xml = simplexml_load_file($feedfilename); - +function farmosnws_convert_xml_2_csv($feedfilename) { + // read the files in the unprocessed directory + // $rawfiles = scandir('filename'); + $csvfilename = $feedfilename . '.csv'; + + try{ + $csvfile = fopen($feedfilename, "w"); + + if ($csvfile === FALSE) { + throw new Exception("Could open CSV file writing"); + } + + // write header + fputcsv($csvfile, array("Done", "Date", "Name", "Notes", "Categories", "Quantity value", "Quantity unit")); + + // load the xml file + $xml = simplexml_load_file($filename); + if ( variable_get('farmosnws_temp_units','') == 'metric' ){ + // temperature in C + fputcsv($csvfile, + array("1", + $xml->observation_time_rfc822, + $xml->location . ' Temperature', // name + $xml->location, + "Temperature", + $xml->temp_c, + "Celsius", + )); + + // log the barametric pressure + fputcsv($csvfile, + array("1", + $xml->observation_time_rfc822, + $xml->location . ' Barometric Pressure', // name + $xml->location, + "Pressure", + $xml->pressure_mb, + "Millibars", + )); + } + else{ + // temperature in F + fputcsv($csvfile, + array("1", + $xml->observation_time_rfc822, + $xml->location . ' Temperature', // name + $xml->location, + "Temperature", + $xml->temp_f, + "Fahrenheit", + )); + + // log the barametric pressure + fputcsv($csvfile, + array("1", + $xml->observation_time_rfc822, + $xml->location . ' Barometric Pressure', // name + $xml->location, + "Pressure", + $xml->pressure_in, + "Inches", + )); + } + + // log the relative humidity + fputcsv($csvfile, + array("1", + $xml->observation_time_rfc822, + $xml->location . ' Humidity', // name + $xml->location, + "Humidity", + $xml->relative_humidity, + "Humidity", + )); + + // log the wind speed + fputcsv($csvfile, + array("1", + $xml->observation_time_rfc822, + $xml->location . ' Wind Speed', // name + $xml->location, + "Wind", + $xml->wind_mph, + "MPH", + )); + + // log the wind direction + fputcsv($csvfile, + array("1", + $xml->observation_time_rfc822, + $xml->location . ' Wind Direction', // name + $xml->location, + "Wind", + $xml->wind_dir, + "Direction", + )); + + // log the weather string + fputcsv($csvfile, + array("1", + $xml->observation_time_rfc822, + $xml->location . ' Weather', // name + $xml->location, + "Weather", + $xml->weather, + "Weather", + )); + + // log the visibility + fputcsv($csvfile, + array("1", + $xml->observation_time_rfc822, + $xml->location . ' Visibility', // name + $xml->location, + "Visibility", + $xml->visibility_mi, + "Miles", + )); + + // close the file + fclose($csvfile); + + // remove feed file + if ( variable_get('farmosnws_del_process_feed', 'n') == "y" ) { + $removefeed = unlink($feedfilename); + if ($removefeed == FALSE){ + throw new Exception("Unable to remove XML feed file " . $feedfilename); + } + } + } + catch(Exception $e) { + watchdog('farmosnws', $e->getMessage(), array(), WATCHDOG_ERROR, NULL); + drupal_set_message($e->getMessage(), 'error'); + } } /** From 0a07d116a1662a1bd30c112e61a5544b9cdcb6c7 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Fri, 22 Dec 2017 09:03:17 -0600 Subject: [PATCH 60/75] Added Delete XML field to admin form --- farmosnws.admin.inc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/farmosnws.admin.inc b/farmosnws.admin.inc index cfed97e..d3b1014 100644 --- a/farmosnws.admin.inc +++ b/farmosnws.admin.inc @@ -34,7 +34,18 @@ function farmosnws_admin_form() { 'metric' => t('Celsius'), ), '#description' => t('Select the system of measurement that you would like to use.'), - '#default_value' => variable_get('farmosnws_temp_units'), + '#default_value' => variable_get('farmosnws_temp_units'), + ); + $form['farmosnws_delete_xml'] = array( + '#type' => 'select', + '#title' => t('Delete Processed XML'), + '#required' => TRUE, + '#options' => array( + 'Yes', + 'No', + ), + '#description' => t('Delete the National Weather Service XML feed after it has been processed.'), + '#default_value' => variable_get('farmosnws_delete_xml', 'Yes'), ); return system_settings_form($form); From 8ecda9fefee24c78784fb96b7df0802b3ae637ab Mon Sep 17 00:00:00 2001 From: Bit Second Date: Fri, 22 Dec 2017 12:49:11 -0600 Subject: [PATCH 61/75] Removed Mkdocs site. Added details --- README.md | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 80036c5..acc94aa 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,53 @@ # FarmOS NWS +Automated importing of National Weather Service (NWS) data into FarmOS. -Please visit https://bitsecondal.github.io/farmosnws/ for documentation. +## Purpose +The purpose of this project is to allow FarmOS to use data from the National +Weather Service to allow it to make better decisions as well as to log +data from a trusted weather source. + +Using data from the National Weather Service reduces the cost to get a FarmOS +installation going as temperature, rain, humidity and other sensors do not +have to be purchased. Furthermore, it reduces the maintenance costs by +reducing the amount of infrastructure required to maintain the farm or garden. + +## System Requirements +* Drupal 7 +* FarmOS + +## Setup + +### Clone the Repository +To get the latest release, clone this repository by running the command below +```shell +git clone https://github.com/bitsecondal/farmosnws.git +``` + +## 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 commands below: +```shell +git checkout master +git pull origin master +``` + +## Author +Kenny Robinson, [@almostengr](https://twitter.com/almostengr) + +## 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 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 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. From e27a333afcde78085bc9b6cd365a6b28417cc8bc Mon Sep 17 00:00:00 2001 From: Bit Second Date: Fri, 22 Dec 2017 13:22:27 -0600 Subject: [PATCH 62/75] Added setting of variable on install --- farmosnws.install | 2 ++ 1 file changed, 2 insertions(+) diff --git a/farmosnws.install b/farmosnws.install index bbf5931..77d5289 100644 --- a/farmosnws.install +++ b/farmosnws.install @@ -53,6 +53,7 @@ function farmosnws_install() { // set the default units to use variable_set('farmosnws_temp_units', 'us'); + variable_set('farmosnws_del_process_feed', 'No'); watchdog('farmosnws', 'FarmOS NWS module has been installed.', array(), WATCHDOG_INFO, NULL); } @@ -83,3 +84,4 @@ function farmosnws_uninstall() { watchdog('farmosnws', 'FarmOS NWS module has been uninstalled.', array(), WATCHDOG_INFO, NULL); } // end function + From f03f372cafbaf5d52c4820694499c243e021d0a0 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Fri, 22 Dec 2017 13:24:56 -0600 Subject: [PATCH 63/75] Added to do item. Corrected variable comparison --- farmosnws.module | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/farmosnws.module b/farmosnws.module index db771df..6571713 100644 --- a/farmosnws.module +++ b/farmosnws.module @@ -21,7 +21,8 @@ function farmosnws_menu() { 'access arguments' => array('access administration pages'), 'file' => 'farmosnws.admin.inc', ); - + + // TO DO: Have URL that will allow for non-cron processing of data return $items; } @@ -32,6 +33,7 @@ function farmosnws_menu() { function farmosnws_cron() { farmosnws_get_xml(); // farmosnws_load_xml(); + // farmosnws_convert_xml_2_csv(); } /** @@ -112,7 +114,7 @@ function farmosnws_get_xml() { watchdog('farmosnws', 'Weather data saved to ' . $weather_feed_name, array(), WATCHDOG_INFO, NULL); // farmosnws_load_xml($weather_feed_name); - // farmosnws_split_xml($weather_feed_name); + // farmosnws_convert_xml_2_csv($weather_feed_name); } else { drupal_set_message("Feed could not be downloaded because the directory does not exist. Please verify that Drupal has write access and try again.", 'error', FALSE); @@ -128,6 +130,7 @@ function farmosnws_get_xml() { * */ function farmosnws_convert_xml_2_csv($feedfilename) { +// function farmosnws_convert_xml_2_csv() { // read the files in the unprocessed directory // $rawfiles = scandir('filename'); $csvfilename = $feedfilename . '.csv'; @@ -251,7 +254,7 @@ function farmosnws_convert_xml_2_csv($feedfilename) { fclose($csvfile); // remove feed file - if ( variable_get('farmosnws_del_process_feed', 'n') == "y" ) { + if ( variable_get('farmosnws_del_process_feed', "No") == "Yes" ) { $removefeed = unlink($feedfilename); if ($removefeed == FALSE){ throw new Exception("Unable to remove XML feed file " . $feedfilename); From 66be4471f60e545f04bef2a6ed4654bb3fc40570 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Sun, 14 Jan 2018 15:47:53 -0600 Subject: [PATCH 64/75] Corrected adding of taxonomy terms during install --- farmosnws.info | 2 +- farmosnws.install | 63 ++++++++++++++--------------------------------- 2 files changed, 20 insertions(+), 45 deletions(-) diff --git a/farmosnws.info b/farmosnws.info index 0b97ba8..74c1896 100644 --- a/farmosnws.info +++ b/farmosnws.info @@ -2,7 +2,7 @@ name = FarmOS NWS description = Imports data from the National Weather Service into Drupal for use by FarmOS. core = 7.x package = farmOS -version = 7.x-2.0-beta6 +version = 7.x-2.0-beta7 dependencies[] = farm_quantity dependencies[] = farm_log_observation diff --git a/farmosnws.install b/farmosnws.install index 77d5289..40643f3 100644 --- a/farmosnws.install +++ b/farmosnws.install @@ -5,57 +5,32 @@ * implements hook_install() */ function farmosnws_install() { - + // add the quantity types - - // get the vocabulary ID so that the terms can be properly associated + + // get the vocabulary id $vocab_qty_units = taxonomy_vocabulary_machine_name_load('farm_quantity_units'); + + // list of terms to add + $terms_qty_list = array('Fahrenheit', 'Celsius', 'Percent Humdity', + 'Direction', 'Inches', 'MPH', 'Miles'); - $terms_qty_list = array( - 'Fahrenheit', - 'Celsius', - 'Percent Humdity', - 'Direction', - 'Inches', - 'MPH', - 'Miles', - ); - - // check if the term exists, if it does not then skip it + // check if the term exists, if it does not then add it foreach($terms_qty_list as $term_qty_item) { - $taxterm = taxonomy_get_term_by_name($term_qty_item, 'farm_quantity_units'); + $taxterm = taxonomy_get_term_by_name($term_qty_item); - if (count($taxterm) == 0) { - $tax_qty_term = new stdClass(); - $tax_qty_term->name = $term_qty_item; - $tax_qty_term->vid = $vocab_qty_units->vid; - taxonomy_term_save($tax_qty_term); + if (count($taxterm) == 0) { + $tax_qty_term = new stdClass(); + $tax_qty_term->name = $term_qty_item; + $tax_qty_term->vid = $vocab_qty_units->vid; + taxonomy_term_save($tax_qty_term); - watchdog('farmosnws', 'Created ' . $term_item . ' taxonomy term.', array(), WATCHDOG_INFO, NULL); - } + watchdog('farmosnws', 'Created ' . $term_qty_item . ' taxonomy term.', array(), WATCHDOG_INFO, NULL); + } + else { + watchdog('farmosnws', 'Matched taxonomy term ' . $term_qty_item, array(), WATCHDOG_INFO, NULL); + } } - - // add the observation types - - $vocab_observ_types = taxonomy_vocabulary_machine_name_load('farm_observation_types'); - $terms_observ_list = array('Temperature'); - - foreach($terms_observ_list as $term_observ_item) { - $tax_observ_term = taxonomy_get_term_by_name($$term_observ_item, 'farm_observation_types'); - - if (count($tax_observ_term) == 0){ - $tax_observ_new = new stdClass(); - $tax_observ_new->name = $term_observ_item; - $tax_observ_new->vid = $vocab_observ_types->vid; - taxonomy_term_save($tax_observ_new); - } - } - - // set the default units to use - variable_set('farmosnws_temp_units', 'us'); - variable_set('farmosnws_del_process_feed', 'No'); - - watchdog('farmosnws', 'FarmOS NWS module has been installed.', array(), WATCHDOG_INFO, NULL); } /** From f36945212a6089efdf39a6d2596017333781d8a3 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Sun, 14 Jan 2018 16:04:08 -0600 Subject: [PATCH 65/75] Set default values for configuration. Write status message to log --- farmosnws.install | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/farmosnws.install b/farmosnws.install index 40643f3..e77fe0e 100644 --- a/farmosnws.install +++ b/farmosnws.install @@ -31,6 +31,10 @@ function farmosnws_install() { watchdog('farmosnws', 'Matched taxonomy term ' . $term_qty_item, array(), WATCHDOG_INFO, NULL); } } + + // set default variable values + variable_set('farmosnws_temp_units', 'us'); + variable_set('farmosnws_delete_xml', 'yes'); } /** @@ -39,7 +43,8 @@ function farmosnws_install() { */ function farmosnws_enable() { // notice to visit configuration page to set initial values for variables - drupal_set_message(t("Visit the module " . l("configuration page", 'admin/config/services/farmosnws') . " to complete module setup."), 'warning', FALSE); + drupal_set_message(t("Visit the module " . l("configuration page", 'admin/config/services/farmosnws') . " to complete module setup."), 'warning', FALSE); + watchdog('farmosnws', 'Visit the module configuration page to complete module setup', array(), WATCHDOG_INFO, NULL); } /** @@ -57,6 +62,6 @@ function farmosnws_uninstall() { menu_rebuild(); - watchdog('farmosnws', 'FarmOS NWS module has been uninstalled.', array(), WATCHDOG_INFO, NULL); + watchdog('farmosnws', 'FarmOS NWS module has been uninstalled', array(), WATCHDOG_INFO, NULL); } // end function From f641d45d94b75442398f880794f6af7f1bcd1d40 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Sun, 14 Jan 2018 16:06:29 -0600 Subject: [PATCH 66/75] Updated options for admin form --- farmosnws.admin.inc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/farmosnws.admin.inc b/farmosnws.admin.inc index d3b1014..52ac697 100644 --- a/farmosnws.admin.inc +++ b/farmosnws.admin.inc @@ -20,7 +20,7 @@ function farmosnws_admin_form() { $form['farmosnws_locations'] = array( '#type' => 'textfield', '#title' => t('Locations'), - '#description' => t('Enter the locations that you would like weather data pulled for. Each location must be entered must be separated by commas.'), + '#description' => t('Enter the locations that you would like weather data pulled for. Each location must be entered must be separated by commas. Feeds can be found on the ' . l('NWS XML feeds page', 'http://w1.weather.gov/xml/current_obs/') . '.'), '#required' => TRUE, '#default_value' => variable_get('farmosnws_locations'), ); @@ -36,13 +36,14 @@ function farmosnws_admin_form() { '#description' => t('Select the system of measurement that you would like to use.'), '#default_value' => variable_get('farmosnws_temp_units'), ); + $form['farmosnws_delete_xml'] = array( '#type' => 'select', '#title' => t('Delete Processed XML'), '#required' => TRUE, '#options' => array( - 'Yes', - 'No', + 'yes' => 'Yes', + 'no' => 'No', ), '#description' => t('Delete the National Weather Service XML feed after it has been processed.'), '#default_value' => variable_get('farmosnws_delete_xml', 'Yes'), @@ -64,3 +65,4 @@ function farmosnws_admin_form_validate($form, &$form_state) { form_set_error('farmosnws_weather_feeds_dir', 'The weather feed directory cannot be created. Please verify that Drupal as write permissions and try again.'); } } // end if + From 4f6bdd760213c0e12d88c5ee24caf222d7fd4d6b Mon Sep 17 00:00:00 2001 From: Bit Second Date: Sun, 14 Jan 2018 17:13:39 -0600 Subject: [PATCH 67/75] Enabled XML to CSV conversion function. Resolved #5 --- farmosnws.module | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/farmosnws.module b/farmosnws.module index 6571713..53095a4 100644 --- a/farmosnws.module +++ b/farmosnws.module @@ -50,7 +50,7 @@ function farmosnws_create_feed_dir($feedpath) { // check to see if the feeds directory exists. If not attempt to create it. if ( is_dir($feedpath) == FALSE ) { - $mkdirsuccess = mkdir($weatherfeedsdir, 755); + $mkdirsuccess = mkdir($feedpath, 755); // verify directory exists if ( $feedpath == FALSE ){ @@ -114,7 +114,7 @@ function farmosnws_get_xml() { watchdog('farmosnws', 'Weather data saved to ' . $weather_feed_name, array(), WATCHDOG_INFO, NULL); // farmosnws_load_xml($weather_feed_name); - // farmosnws_convert_xml_2_csv($weather_feed_name); + farmosnws_convert_xml_2_csv($weather_feed_name); } else { drupal_set_message("Feed could not be downloaded because the directory does not exist. Please verify that Drupal has write access and try again.", 'error', FALSE); @@ -136,7 +136,7 @@ function farmosnws_convert_xml_2_csv($feedfilename) { $csvfilename = $feedfilename . '.csv'; try{ - $csvfile = fopen($feedfilename, "w"); + $csvfile = fopen($csvfilename, "w"); if ($csvfile === FALSE) { throw new Exception("Could open CSV file writing"); @@ -146,7 +146,7 @@ function farmosnws_convert_xml_2_csv($feedfilename) { fputcsv($csvfile, array("Done", "Date", "Name", "Notes", "Categories", "Quantity value", "Quantity unit")); // load the xml file - $xml = simplexml_load_file($filename); + $xml = simplexml_load_file($feedfilename); if ( variable_get('farmosnws_temp_units','') == 'metric' ){ // temperature in C From 0d44c8e24d9fa2fa7db7b4396fb00155cebaa90a Mon Sep 17 00:00:00 2001 From: Bit Second Date: Sun, 14 Jan 2018 17:58:22 -0600 Subject: [PATCH 68/75] Added additional measurement units --- farmosnws.install | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/farmosnws.install b/farmosnws.install index e77fe0e..16a0c57 100644 --- a/farmosnws.install +++ b/farmosnws.install @@ -12,8 +12,7 @@ function farmosnws_install() { $vocab_qty_units = taxonomy_vocabulary_machine_name_load('farm_quantity_units'); // list of terms to add - $terms_qty_list = array('Fahrenheit', 'Celsius', 'Percent Humdity', - 'Direction', 'Inches', 'MPH', 'Miles'); + $terms_qty_list = array('Fahrenheit', 'Celsius', 'Percent Humdity', 'Direction', 'Inches', 'MPH', 'Miles', 'Knots', 'KM'); // check if the term exists, if it does not then add it foreach($terms_qty_list as $term_qty_item) { From a5fd4214f9dff47edaa383c17c622787b858abca Mon Sep 17 00:00:00 2001 From: Bit Second Date: Sun, 14 Jan 2018 17:58:59 -0600 Subject: [PATCH 69/75] Updated importer feature --- ...mosnws_importer.feeds_importer_default.inc | 56 +++++++++++++------ farmosnws_importer/farmosnws_importer.info | 4 +- 2 files changed, 42 insertions(+), 18 deletions(-) diff --git a/farmosnws_importer/farmosnws_importer.feeds_importer_default.inc b/farmosnws_importer/farmosnws_importer.feeds_importer_default.inc index 65eb978..6430b36 100644 --- a/farmosnws_importer/farmosnws_importer.feeds_importer_default.inc +++ b/farmosnws_importer/farmosnws_importer.feeds_importer_default.inc @@ -21,26 +21,19 @@ function farmosnws_importer_feeds_importer_default() { 'plugin_key' => 'feeds_fetcher_directory_fetcher', 'config' => array( 'recursive' => 1, - 'directory' => 'public://feeds/curweather', - 'filemask' => '/\\.xml$/', + 'directory' => 'public://nwsfeeds', + 'filemask' => '/\\.csv$/', 'updated_files' => 0, 'after_processed' => '0', 'move_to_folder' => '', ), ), 'parser' => array( - 'plugin_key' => 'FeedsXPathParserXML', + 'plugin_key' => 'FeedsCSVParser', 'config' => array( - 'sources' => array(), - 'rawXML' => array(), - 'context' => '', - 'exp' => array( - 'errors' => FALSE, - 'tidy' => FALSE, - 'debug' => array(), - 'tidy_encoding' => 'UTF8', - ), - 'allow_override' => TRUE, + 'delimiter' => ',', + 'encoding' => 'ASCII', + 'no_headers' => 0, ), ), 'processor' => array( @@ -50,9 +43,40 @@ function farmosnws_importer_feeds_importer_default() { 'authorize' => 0, 'mappings' => array( 0 => array( - 'source' => 'xpathparser:0', + 'source' => 'Done', + 'target' => 'done', + 'unique' => FALSE, + 'language' => 'und', + ), + 1 => array( + 'source' => 'Date', + 'target' => 'timestamp', + 'unique' => FALSE, + 'language' => 'und', + ), + 2 => array( + 'source' => 'Name', + 'target' => 'name', + 'unique' => FALSE, + 'language' => 'und', + ), + 3 => array( + 'source' => 'Notes', + 'target' => 'field_farm_notes', + 'unique' => FALSE, + 'language' => 'und', + ), + 4 => array( + 'source' => 'Value', 'target' => 'field_farm_quantity:field_farm_quantity_value', 'unique' => FALSE, + 'language' => 'und', + ), + 5 => array( + 'source' => 'Unit', + 'target' => 'field_farm_quantity:field_farm_quantity_units', + 'unique' => FALSE, + 'language' => 'und', ), ), 'insert_new' => '1', @@ -66,10 +90,10 @@ function farmosnws_importer_feeds_importer_default() { ), 'content_type' => '', 'update' => 0, - 'import_period' => '1800', + 'import_period' => '0', 'expire_period' => 3600, 'import_on_create' => 1, - 'process_in_background' => 1, + 'process_in_background' => 0, ); $export['log_nws_observation'] = $feeds_importer; diff --git a/farmosnws_importer/farmosnws_importer.info b/farmosnws_importer/farmosnws_importer.info index 3e203eb..86e92ca 100644 --- a/farmosnws_importer/farmosnws_importer.info +++ b/farmosnws_importer/farmosnws_importer.info @@ -1,8 +1,8 @@ name = FarmOS NWS Feeds Importer description = Import National Weather Service (NWS) data into FarmOS. core = 7.x -package = farmOS Addons -version = 7.x-2.0-beta7 +package = farmOS +version = 7.x-2.0-beta8 dependencies[] = ctools dependencies[] = feeds dependencies[] = feeds_fetcher_directory From c4a5c60a384bb53d2290cd6282e8690599cd20da Mon Sep 17 00:00:00 2001 From: Bit Second Date: Sun, 14 Jan 2018 18:13:55 -0600 Subject: [PATCH 70/75] Added additional unit measurements --- farmosnws.install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/farmosnws.install b/farmosnws.install index 16a0c57..84bc84a 100644 --- a/farmosnws.install +++ b/farmosnws.install @@ -12,7 +12,7 @@ function farmosnws_install() { $vocab_qty_units = taxonomy_vocabulary_machine_name_load('farm_quantity_units'); // list of terms to add - $terms_qty_list = array('Fahrenheit', 'Celsius', 'Percent Humdity', 'Direction', 'Inches', 'MPH', 'Miles', 'Knots', 'KM'); + $terms_qty_list = array('Fahrenheit', 'Celsius', 'Percent Humdity', 'Direction', 'Inches', 'MPH', 'Miles', 'Knots', 'KM', 'Degrees'); // check if the term exists, if it does not then add it foreach($terms_qty_list as $term_qty_item) { From 8cc1d4b0b93931a03f3b69b92434ca63bba960eb Mon Sep 17 00:00:00 2001 From: Bit Second Date: Sun, 14 Jan 2018 19:01:18 -0600 Subject: [PATCH 71/75] Removed unused, commented code. Updated CSV output format. Removed load function. --- farmosnws.module | 150 ++++++++++++++++------------------------------- 1 file changed, 52 insertions(+), 98 deletions(-) diff --git a/farmosnws.module b/farmosnws.module index 53095a4..530babd 100644 --- a/farmosnws.module +++ b/farmosnws.module @@ -32,8 +32,6 @@ function farmosnws_menu() { */ function farmosnws_cron() { farmosnws_get_xml(); - // farmosnws_load_xml(); - // farmosnws_convert_xml_2_csv(); } /** @@ -74,6 +72,8 @@ function farmosnws_create_feed_dir($feedpath) { */ function farmosnws_get_xml() { $weatherfeedsdir = variable_get('farmosnws_weather_feeds_dir'); + + // $weatherfeedsdir = file_create_url($weatherfeedsdir); $locations = variable_get('farmosnws_locations', ''); $location_array = explode(",", $locations); @@ -92,10 +92,6 @@ function farmosnws_get_xml() { $response = drupal_http_request($url, array()); -// watchdog('farmosnws', 'Response code: ' . $response->code, array(), WATCHDOG_INFO, NULL); - - // watchdog('farmosnws', 'Response code: ' . $response->code . '. ' $response->error, array(), WATCHDOG_ERROR, NULL); - // if error occurs when performing the request if ( $response->error ) { watchdog('farmosnws', 'Response code: ' . $response->code . '. ' . $response->error, array(), WATCHDOG_ERROR, NULL); @@ -130,7 +126,6 @@ function farmosnws_get_xml() { * */ function farmosnws_convert_xml_2_csv($feedfilename) { -// function farmosnws_convert_xml_2_csv() { // read the files in the unprocessed directory // $rawfiles = scandir('filename'); $csvfilename = $feedfilename . '.csv'; @@ -141,58 +136,71 @@ function farmosnws_convert_xml_2_csv($feedfilename) { if ($csvfile === FALSE) { throw new Exception("Could open CSV file writing"); } + + // get taxonomy term ids + $term_celsius = taxonomy_get_term_by_name("Celsius"); + $term_millibars = taxonomy_get_term_by_name("Millibars"); + $term_fahrenheit = taxonomy_get_term_by_name("Fahrenheit"); + $term_inches = taxonomy_get_term_by_name("Inches"); + $term_inches = taxonomy_get_term_by_name("Humidity"); // write header - fputcsv($csvfile, array("Done", "Date", "Name", "Notes", "Categories", "Quantity value", "Quantity unit")); + fputcsv($csvfile, array("Done", "Date", "Name", "Notes", "Value", "Unit")); // load the xml file $xml = simplexml_load_file($feedfilename); + + // load the units configuration + $measure_units = variable_get('farmosnws_temp_units', 'us'); - if ( variable_get('farmosnws_temp_units','') == 'metric' ){ + // log the metric units + if ( $measure_units == 'metric' || $measure_units == 'both' ){ // temperature in C fputcsv($csvfile, - array("1", - $xml->observation_time_rfc822, + array(1, // done + $xml->observation_time_rfc822, // date $xml->location . ' Temperature', // name - $xml->location, - "Temperature", - $xml->temp_c, - "Celsius", - )); + $xml->location, // location + // "Temperature", // category + $xml->temp_c, // value + "Celsius", // unit + ), ','); // log the barametric pressure fputcsv($csvfile, - array("1", - $xml->observation_time_rfc822, + array(1, // done + $xml->observation_time_rfc822, // date $xml->location . ' Barometric Pressure', // name - $xml->location, - "Pressure", + $notes, // notes + // "Pressure", $xml->pressure_mb, "Millibars", - )); + ), ','); } - else{ + + // log the US, standard units + if ( $measure_units == 'us' || $measure_units == 'both' ){ // temperature in F fputcsv($csvfile, - array("1", + array(1, $xml->observation_time_rfc822, $xml->location . ' Temperature', // name $xml->location, - "Temperature", + // "Temperature", $xml->temp_f, "Fahrenheit", - )); + ), ','); // log the barametric pressure fputcsv($csvfile, - array("1", + array(1, $xml->observation_time_rfc822, $xml->location . ' Barometric Pressure', // name $xml->location, - "Pressure", + // "Pressure", $xml->pressure_in, "Inches", - )); + ), ','); } // log the relative humidity @@ -201,10 +209,10 @@ function farmosnws_convert_xml_2_csv($feedfilename) { $xml->observation_time_rfc822, $xml->location . ' Humidity', // name $xml->location, - "Humidity", + // "Humidity", $xml->relative_humidity, - "Humidity", - )); + "Percent Humidity", + ), ','); // log the wind speed fputcsv($csvfile, @@ -212,10 +220,10 @@ function farmosnws_convert_xml_2_csv($feedfilename) { $xml->observation_time_rfc822, $xml->location . ' Wind Speed', // name $xml->location, - "Wind", + // "Wind", $xml->wind_mph, "MPH", - )); + ), ','); // log the wind direction fputcsv($csvfile, @@ -223,21 +231,21 @@ function farmosnws_convert_xml_2_csv($feedfilename) { $xml->observation_time_rfc822, $xml->location . ' Wind Direction', // name $xml->location, - "Wind", - $xml->wind_dir, + // "Wind", + $xml->wind_degrees, "Direction", - )); + ), ','); // log the weather string fputcsv($csvfile, array("1", $xml->observation_time_rfc822, $xml->location . ' Weather', // name - $xml->location, - "Weather", - $xml->weather, - "Weather", - )); + $xml->weather, // $xml->location . ' ' . $xml->observation_time_rfc822, + // "Weather", + "", // $xml->weather, + "", + ), ','); // log the visibility fputcsv($csvfile, @@ -245,16 +253,16 @@ function farmosnws_convert_xml_2_csv($feedfilename) { $xml->observation_time_rfc822, $xml->location . ' Visibility', // name $xml->location, - "Visibility", + // "Visibility", $xml->visibility_mi, "Miles", - )); + ), ','); // close the file fclose($csvfile); // remove feed file - if ( variable_get('farmosnws_del_process_feed', "No") == "Yes" ) { + if ( variable_get('farmosnws_del_process_feed', "no") == "yes" ) { $removefeed = unlink($feedfilename); if ($removefeed == FALSE){ throw new Exception("Unable to remove XML feed file " . $feedfilename); @@ -267,57 +275,3 @@ function farmosnws_convert_xml_2_csv($feedfilename) { } } -/** - * - * @param unknown $feedfilename - * - * @tutorial http://audiblecode.com/blog/programmatically-create-and-update-field-collection-item-node-entity-api - * @tutorial http://drupal.org/node/1842304 - */ -function farmosnws_load_xml($feedfilename) { - global $user; - - // load the file - $xml = simplexml_load_file($feedfilename); - - /* - $qty = entity_create('farm_quantity', array('type' => 'farm_quantity')); - $qty->value = $xml->temp_f; - entity_save('farm_quantity', $qty); -*/ - - $log = entity_create('log', array('type' => 'farm_observation')); - $log_wrapper = entity_metadata_wrapper('log', $log); - print "Temp F: " . $xml->temp_f . "\r\n"; - $log_wrapper->field_farm_notes = $xml->temp_f; - print "Temp F int: " . intval($xml->temp_f); - $log_wrapper->field_farm_quantity->value = intval($xml->temp_f); - $log_wrapper->done = 1; - $log_wrapper->name = $xml->location . " at " . $xml->observation_time_rfc822; - $log_wrapper->timestamp = strtotime($xml->observation_time_rfc822); - $log_wrapper->save(); - - $qty = entity_create('farm_quantity', array('type' => 'farm_quantity')); - $qty->value = strval($xml->temp_f); - $qty->units = 'Fahrenheit'; - $qty->id = $log_wrapper->id; - entity_save('farm_quantity', $qty); - - // $etl = entity_load('log', array('102')); - // print_r($etl); - - // print("Temperature " . $xml->temp_f . "\r\n"); - - watchdog('farmosnws', 'Temperature data saved from ' . $feedfilename, array(), WATCHDOG_INFO, NULL); - - // log the relative humidity - - // log the wind speed - - // log the wind direction - - // log the barametric pressure - - // log the visibility -} - From 5867263b9955d99bae09769cac62fdb8ec3fbea1 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Sun, 14 Jan 2018 19:15:55 -0600 Subject: [PATCH 72/75] Updated dependencies and Feeds importer --- ...mosnws_importer.feeds_importer_default.inc | 35 ++++++++++++++----- farmosnws_importer/farmosnws_importer.info | 4 ++- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/farmosnws_importer/farmosnws_importer.feeds_importer_default.inc b/farmosnws_importer/farmosnws_importer.feeds_importer_default.inc index 6430b36..65754b8 100644 --- a/farmosnws_importer/farmosnws_importer.feeds_importer_default.inc +++ b/farmosnws_importer/farmosnws_importer.feeds_importer_default.inc @@ -49,35 +49,52 @@ function farmosnws_importer_feeds_importer_default() { 'language' => 'und', ), 1 => array( - 'source' => 'Date', - 'target' => 'timestamp', - 'unique' => FALSE, - 'language' => 'und', - ), - 2 => array( 'source' => 'Name', 'target' => 'name', 'unique' => FALSE, 'language' => 'und', ), - 3 => array( + 2 => array( 'source' => 'Notes', 'target' => 'field_farm_notes', 'unique' => FALSE, 'language' => 'und', ), - 4 => array( + 3 => array( 'source' => 'Value', 'target' => 'field_farm_quantity:field_farm_quantity_value', 'unique' => FALSE, 'language' => 'und', ), - 5 => array( + 4 => array( 'source' => 'Unit', 'target' => 'field_farm_quantity:field_farm_quantity_units', 'unique' => FALSE, 'language' => 'und', ), + 5 => array( + 'source' => 'Date', + 'target' => 'changed', + 'unique' => FALSE, + 'language' => 'und', + ), + 6 => array( + 'source' => 'Date', + 'target' => 'created', + 'unique' => FALSE, + 'language' => 'und', + ), + 7 => array( + 'source' => 'Latitude', + 'target' => 'field_farm_geofield:lat', + 'unique' => FALSE, + 'language' => 'und', + ), + 8 => array( + 'source' => 'Longitude', + 'target' => 'field_farm_geofield:lon', + 'unique' => FALSE, + ), ), 'insert_new' => '1', 'update_existing' => '0', diff --git a/farmosnws_importer/farmosnws_importer.info b/farmosnws_importer/farmosnws_importer.info index 86e92ca..07d2dbe 100644 --- a/farmosnws_importer/farmosnws_importer.info +++ b/farmosnws_importer/farmosnws_importer.info @@ -2,8 +2,10 @@ name = FarmOS NWS Feeds Importer description = Import National Weather Service (NWS) data into FarmOS. core = 7.x package = farmOS -version = 7.x-2.0-beta8 +version = 7.x-2.0 dependencies[] = ctools +dependencies[] = farm_log +dependencies[] = farm_log_observation dependencies[] = feeds dependencies[] = feeds_fetcher_directory dependencies[] = feeds_xpathparser From 35a1ef7143534286133016d3c3680c11c7af2afe Mon Sep 17 00:00:00 2001 From: Bit Second Date: Sun, 14 Jan 2018 21:28:30 -0600 Subject: [PATCH 73/75] Removed shell scripts --- get_weather.sh | 57 ---------------------------------------- get_weather_config_ex.sh | 9 ------- 2 files changed, 66 deletions(-) delete mode 100644 get_weather.sh delete mode 100644 get_weather_config_ex.sh diff --git a/get_weather.sh b/get_weather.sh deleted file mode 100644 index d114ab0..0000000 --- a/get_weather.sh +++ /dev/null @@ -1,57 +0,0 @@ -#!/bin/bash - -################################################################################ -# Description: Load the weather data in XML format from the National Weather -# Service into a given location. -# -# Usage: get_weather.sh -# "" is to be replaced with the full path of the configuration file. -# -# Author: Kenny Robinson, Bit Second Tech -################################################################################ - -# log all of the status and error messages -function log_message() { - # echo $(date)" | "$* - echo $* -} - -function show_help() { -# Show the help documentation - log_message "" - log_message "Usage:" - log_message "get_weather.sh " - log_message "" - log_message "Param can be replaced with one of the following:" - log_message "configfile - The full path of the configuration file." - log_message "help - Show the help information about this script." - log_message "" - log_message "For more information, visit https://github.com/bitsecondal/farmosnws" -} - -## SCRIPT MAIN ## SCRIPT MAIN ## SCRIPT MAIN ## -## SCRIPT MAIN ## SCRIPT MAIN ## SCRIPT MAIN ## - -FILENAME="${1}" - -# verify that the configuration file exists -if [[ -f ${FILENAME} ]]; then - - log_message "Loading the configuration" - - # load the configuration file - source $1 - - log_message "Done loading the configuration" - - log_message "Getting the weather data" - - # get and save the weather data - /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" -else - log_message "Configuration file does not exist." - show_help -fi - diff --git a/get_weather_config_ex.sh b/get_weather_config_ex.sh deleted file mode 100644 index f9b3384..0000000 --- a/get_weather_config_ex.sh +++ /dev/null @@ -1,9 +0,0 @@ -# Enter the file system path to the location that Drupal will pull feeds from -feedsdir=/path/to/drupal/feeds/location - -# Enter the NWS location code that you want to be queried -# Location code can be found by going to http://w1.weather.gov/xml/current_obs/ and searching for your location. -location=ABCD - -export feedsdir -export location From e65643e107e9de2a090789c9df7bb6a14041e35a Mon Sep 17 00:00:00 2001 From: Bit Second Date: Sun, 14 Jan 2018 21:46:39 -0600 Subject: [PATCH 74/75] Added install and uninstall instructions. Updated additional information --- README.md | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index acc94aa..e8eaf1d 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ reducing the amount of infrastructure required to maintain the farm or garden. * Drupal 7 * FarmOS -## Setup +## Installation ### Clone the Repository To get the latest release, clone this repository by running the command below @@ -23,11 +23,35 @@ To get the latest release, clone this repository by running the command below git clone https://github.com/bitsecondal/farmosnws.git ``` +### Configure FarmOS NWS +Within your Drupal site, enable the FarmOS NWS and FarmOS NWS Feeds Importer modules +from the Modules page. +After enabling the modules, go to the FarmOS NWS configuration page (Admin > +Configuration > Web Services > FarmOS NWS Settings). Enter the file system location, +weather locations that you would like weather imported for, measurement units, and +whether you want to keep files after they have been loaded. When done, click Save. + +### Configure Feed Importer +Within your Drupal site, go to the feed importer page (Structure > Feeds Importers > +Log: NWS Observation). In the Fetcher section, set the upload directory to the same +directory that you defined in the Configure FarmOS NWS section. When done, +click Save. + +## Uninstallation +Within your Drupal site, go to the Modules page and disable FarmOS NWS and FarmOS NWS +Importer modules and click Save Configuration. Then go to the Uninstall page (Modules > +Uninstall), select each module, and click Uninstall. + +If you uninstall the modules, the data that was imported by the modules WILL NOT be +removed. If you wish to remove the data that was imported remove, you will have to +manually remove each entry. + ## 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 commands 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 @@ -36,18 +60,14 @@ git pull origin master ## Author Kenny Robinson, [@almostengr](https://twitter.com/almostengr) -## Bug Reports and Feature Enhancements +## Additional Information 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 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 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. From 8e48ac283539ab7497384bd1ed74b83d51b9fe60 Mon Sep 17 00:00:00 2001 From: Bit Second Date: Sun, 14 Jan 2018 21:56:18 -0600 Subject: [PATCH 75/75] Cleaned up code. Updated version number --- farmosnws.admin.inc | 4 ++-- farmosnws.info | 3 ++- farmosnws.module | 8 +++----- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/farmosnws.admin.inc b/farmosnws.admin.inc index 52ac697..0256b2d 100644 --- a/farmosnws.admin.inc +++ b/farmosnws.admin.inc @@ -46,7 +46,7 @@ function farmosnws_admin_form() { 'no' => 'No', ), '#description' => t('Delete the National Weather Service XML feed after it has been processed.'), - '#default_value' => variable_get('farmosnws_delete_xml', 'Yes'), + '#default_value' => variable_get('farmosnws_delete_xml', 'yes'), ); return system_settings_form($form); @@ -57,11 +57,11 @@ function farmosnws_admin_form() { * Validate the module settings */ function farmosnws_admin_form_validate($form, &$form_state) { + // validate that the work directory exists and can be created $weatherfeedsdir = $form_state['values']['farmosnws_weather_feeds_dir']; $direxist = farmosnws_create_feed_dir($weatherfeedsdir); if ( $direxist == FALSE ){ - // watchdog('farmosnws', 'Unable to create the weather feed directory.', array(), WATCHDOG_ERROR, NULL); form_set_error('farmosnws_weather_feeds_dir', 'The weather feed directory cannot be created. Please verify that Drupal as write permissions and try again.'); } } // end if diff --git a/farmosnws.info b/farmosnws.info index 74c1896..b6691de 100644 --- a/farmosnws.info +++ b/farmosnws.info @@ -2,7 +2,8 @@ name = FarmOS NWS description = Imports data from the National Weather Service into Drupal for use by FarmOS. core = 7.x package = farmOS -version = 7.x-2.0-beta7 +version = 7.x-2.0 +dependencies[] = farm dependencies[] = farm_quantity dependencies[] = farm_log_observation diff --git a/farmosnws.module b/farmosnws.module index 530babd..f7c72d1 100644 --- a/farmosnws.module +++ b/farmosnws.module @@ -73,6 +73,7 @@ function farmosnws_create_feed_dir($feedpath) { function farmosnws_get_xml() { $weatherfeedsdir = variable_get('farmosnws_weather_feeds_dir'); + // TO DO: Add converter for schema to actual path // $weatherfeedsdir = file_create_url($weatherfeedsdir); $locations = variable_get('farmosnws_locations', ''); @@ -81,13 +82,12 @@ function farmosnws_get_xml() { foreach ($location_array as $loc) { // remove carriage returns and new lines $loc = str_replace(" ", "", str_replace("\r", "", str_replace("\n", "", $loc))); - // $loc = str_replace(" ", "", $loc); + // build URL to connect to NWS $weather_feed_name = $weatherfeedsdir . '/' . uniqid($loc, FALSE) . '.xml'; $url = "http://w1.weather.gov/xml/current_obs/" . $loc . ".xml"; watchdog('farmosnws', $url, array(), WATCHDOG_DEBUG, NULL); - watchdog('farmosnws', 'Getting weather data for ' . $loc, array(), WATCHDOG_INFO, NULL); $response = drupal_http_request($url, array()); @@ -109,7 +109,6 @@ function farmosnws_get_xml() { file_put_contents($weather_feed_name, $response->data); watchdog('farmosnws', 'Weather data saved to ' . $weather_feed_name, array(), WATCHDOG_INFO, NULL); - // farmosnws_load_xml($weather_feed_name); farmosnws_convert_xml_2_csv($weather_feed_name); } else { @@ -123,11 +122,9 @@ function farmosnws_get_xml() { /** * * @feedfilename string File name that will be split into smaller feeds - * */ function farmosnws_convert_xml_2_csv($feedfilename) { // read the files in the unprocessed directory - // $rawfiles = scandir('filename'); $csvfilename = $feedfilename . '.csv'; try{ @@ -275,3 +272,4 @@ function farmosnws_convert_xml_2_csv($feedfilename) { } } +