int convert_station_forecacom_data(const char *station_id_with_path, const char *result_file, const char *detail_path_data ){ xmlDoc *doc = NULL; xmlNode *root_node = NULL; int days_number = -1; char buffer[1024], buffer2[1024], *delimiter = NULL; FILE *file_out; if(!station_id_with_path) return -1; /* check for new file, if it exist, than rename it */ *buffer = 0; snprintf(buffer, sizeof(buffer) - 1, "%s.new", station_id_with_path); if(!access(buffer, R_OK)) rename(buffer, station_id_with_path); /* check file accessability */ if(!access(station_id_with_path, R_OK)){ /* check that the file containe valid data */ doc = htmlReadFile(station_id_with_path, "UTF-8", HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING); if(!doc) return -1; root_node = xmlDocGetRootElement(doc); if(root_node->type == XML_ELEMENT_NODE && strstr((char*)root_node->name, "err")){ xmlFreeDoc(doc); xmlCleanupParser(); return -2; } else{ /* prepare station id */ *buffer = 0; *buffer2 = 0; snprintf(buffer2, sizeof(buffer2) - 1, "%s", station_id_with_path); delimiter = strrchr(buffer2, '/'); if(delimiter){ delimiter++; /* delete '/' */ snprintf(buffer, sizeof(buffer) - 1, "%s", delimiter); delimiter = strrchr(buffer, '.'); if(!delimiter){ xmlFreeDoc(doc); xmlCleanupParser(); return -1; } *delimiter = 0; // if(get_detail_data) // days_number = parse_xml_detail_data(buffer, root_node, data); // else days_number = parse_and_write_xml_data(buffer, doc, result_file); xmlFreeDoc(doc); xmlCleanupParser(); if(!access(detail_path_data, R_OK)){ doc = htmlReadFile(detail_path_data, "UTF-8", HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING); if(doc){ root_node = NULL; root_node = xmlDocGetRootElement(doc); if(!root_node || ( root_node->type == XML_ELEMENT_NODE && strstr((char*)root_node->name, "err"))){ xmlFreeDoc(doc); xmlCleanupParser(); } else{ parse_and_write_detail_data(buffer, doc, result_file); xmlFreeDoc(doc); xmlCleanupParser(); } } } if (days_number > 0){ file_out = fopen(result_file, "a"); if (file_out){ fprintf(file_out,"</station>"); fclose(file_out); } } } } } else return -1;/* file isn't accessability */ return days_number; }
convert_station_hkogovhk_data(const gchar *station_id_with_path, const gchar *result_file, const gchar *detail_path_data ){ xmlDoc *doc = NULL; xmlNode *root_node = NULL; gint days_number = -1; gchar buffer[1024], *delimiter = NULL; FILE *file_out; file_out = fopen(result_file, "w"); if (!file_out) return -1; /* prepare station id */ *buffer = 0; delimiter = strrchr(station_id_with_path, '/'); if(delimiter){ delimiter++; /* delete '/' */ snprintf(buffer, sizeof(buffer) - 1, "%s", delimiter); } fprintf(file_out,"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<station name=\"Station name\" id=\"%s\" xmlns=\"http://omweather.garage.maemo.org/schemas\">\n", buffer); fprintf(file_out," <units>\n <t>C</t>\n <ws>m/s</ws>\n <wg>m/s</wg>\n <d>km</d>\n"); fprintf(file_out," <h>%%</h> \n <p>mmHg</p>\n </units>\n"); fclose(file_out); parse_current_weather(detail_path_data, result_file); parse_forecast_weather(station_id_with_path, result_file); file_out = fopen(result_file, "a"); if (file_out){ fprintf(file_out,"</station>"); fclose(file_out); } return 0; if(!station_id_with_path) return -1; /* check for new file, if it exist, than rename it */ *buffer = 0; snprintf(buffer, sizeof(buffer) - 1, "%s.new", station_id_with_path); if(!access(buffer, R_OK)) rename(buffer, station_id_with_path); /* check file accessability */ if(!access(station_id_with_path, R_OK)){ /* check that the file containe valid data */ doc = htmlReadFile(station_id_with_path, "UTF-8", 0); if(!doc) return -1; root_node = xmlDocGetRootElement(doc); if(root_node->type == XML_ELEMENT_NODE && strstr((char*)root_node->name, "err")){ xmlFreeDoc(doc); xmlCleanupParser(); return -2; } else{ /* prepare station id */ *buffer = 0; delimiter = strrchr(station_id_with_path, '/'); if(delimiter){ delimiter++; /* delete '/' */ snprintf(buffer, sizeof(buffer) - 1, "%s", delimiter); delimiter = strrchr(buffer, '.'); if(!delimiter){ xmlFreeDoc(doc); xmlCleanupParser(); return -1; } *delimiter = 0; // if(get_detail_data) // days_number = parse_xml_detail_data(buffer, root_node, data); // else days_number = parse_and_write_xml_data(buffer, doc, result_file); xmlFreeDoc(doc); xmlCleanupParser(); if(!access(detail_path_data, R_OK)){ doc = htmlReadFile(detail_path_data, "UTF-8", 0); if(doc){ root_node = NULL; root_node = xmlDocGetRootElement(doc); if(!root_node || ( root_node->type == XML_ELEMENT_NODE && strstr((char*)root_node->name, "err"))){ xmlFreeDoc(doc); xmlCleanupParser(); } else{ parse_and_write_detail_data(buffer, doc, result_file); xmlFreeDoc(doc); xmlCleanupParser(); } } } if (days_number > 0){ file_out = fopen(result_file, "a"); if (file_out){ fprintf(file_out,"</station>"); fclose(file_out); } } } } } else return -1;/* file isn't accessability */ return days_number; }