Skip to content
This repository has been archived by the owner on Nov 5, 2020. It is now read-only.

Commit

Permalink
Cleaned up code. Updated version number
Browse files Browse the repository at this point in the history
  • Loading branch information
almostengr committed Jan 15, 2018
1 parent e65643e commit 8e48ac2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
4 changes: 2 additions & 2 deletions farmosnws.admin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion farmosnws.info
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 3 additions & 5 deletions farmosnws.module
Original file line number Diff line number Diff line change
Expand Up @@ -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', '');
Expand All @@ -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());
Expand All @@ -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 {
Expand All @@ -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{
Expand Down Expand Up @@ -275,3 +272,4 @@ function farmosnws_convert_xml_2_csv($feedfilename) {
}
}


0 comments on commit 8e48ac2

Please sign in to comment.