~cwhii/aptcp/trunk

« back to all changes in this revision

Viewing changes to aptcp.cpp

  • Committer: C.W.Holeman II
  • Date: 2018-04-13 20:00:00 UTC
  • Revision ID: cwhii_pl@julianlocals.com-20180413200000-62a96e5ie27rw76q
Initialize stringstream with constructor. Replace junk with get().

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
// ----- a report for the specified colleges of how they accept the results for the various tests and what specific courses they give
5
5
// ----- credit for at their schools with links to the school's pages on the collegeboard.org web site.
6
6
//
 
7
// 10Apr'18 C.W.Holeman II
 
8
//          Initialize stringstreams with constructor.
 
9
// 14Mar'18 C.W.Holeman II
 
10
//          Output to standard out instead of hardcoded file name.
7
11
// 13Mar'18 C.W.Holamen II
8
12
//          Remove hard coded filename for input college list, using standard input instead. Added timestamp to output file name.
9
13
// 11Mar'18 C.W.Holeman II
57
61
#include "aptcp_tidydoc.hpp"
58
62
 
59
63
int main() {
60
 
 
61
64
   // ----- Create XML document content by concatenating the table from each college's policy page.
62
65
 
63
 
   std::stringstream xml_doc; xml_doc << APTCP_XML_DOC_PREFIX;
 
66
   std::stringstream xml_doc(APTCP_XML_DOC_PREFIX, std::ios::in | std::ios::out | std::ios::ate);
64
67
   {
65
 
      std::set<College> colleges{}; {
66
 
         std::copy(std::istream_iterator<College>{std::cin},
67
 
                         std::istream_iterator<College>{},
68
 
                                 std::inserter(colleges, colleges.begin()));
69
 
         }
70
 
      for (auto c: colleges){
71
 
         auto page {tidy_up_html(fetch_page(c.url())).value_or("optional-empty"+c.name())};
72
 
         auto b {page.find(APTCP_CONTENT_BEGIN)};
73
 
         if (b != std::string::npos){                                                                                      // Has content?
74
 
            xml_doc << page.substr(b).substr(0,page.substr(b).find(APTCP_CONTENT_END)+std::strlen(APTCP_CONTENT_END))      // Extract it.
75
 
                    << "<info>" << c << "</info>\n";
 
68
      std::set<College> colleges {}; std::copy(std::istream_iterator<College> {std::cin}, std::istream_iterator<College> {},
 
69
         std::inserter(colleges, colleges.begin()));
 
70
      for (auto c : colleges) {
 
71
         auto page {tidy_up_html(fetch_page(c.url()))};
 
72
         if (auto b {page.find(APTCP_CONTENT_BEGIN)}; b != std::string::npos) {                                      // Has content?
 
73
            xml_doc << page.substr(b).substr(0,page.substr(b).find(APTCP_CONTENT_END)+std::strlen(APTCP_CONTENT_END)) // Extract it.
 
74
               << "<info>" << c << "</info>\n";
76
75
            }
77
76
         else {
78
77
            xml_doc << "<warning>" << c << "</warning>\n";
83
82
 
84
83
   // ----- Create XSLT style sheet.
85
84
 
86
 
   std::stringstream style_sheet; style_sheet << APTCP_XSLT;
 
85
   std::stringstream style_sheet(APTCP_XSLT, std::ios::in | std::ios::out | std::ios::ate);
87
86
 
88
 
   // ----- Create the transformer.
 
87
        // ----- Create the transformer.
89
88
 
90
89
   XALAN_USING_XERCES(XMLPlatformUtils)
91
90
   XALAN_USING_XALAN(XalanTransformer)
92
91
   XMLPlatformUtils::Initialize();
93
92
   XalanTransformer::initialize();
94
 
   XalanTransformer transformer;
95
 
   auto now {std::time(nullptr)};
96
 
   transformer.setStylesheetParam("current_time_p", ("'" + std::string{std::asctime(std::localtime(&now))} + "'").c_str());
97
 
 
98
 
   // ----- Use the transformer to invoke the XSLT style sheet on the XML document.
99
 
 
100
 
   if (transformer.transform(xml_doc, style_sheet, std::cout) != 0) {
 
93
   XalanTransformer transformer {};
 
94
   {
 
95
      auto now {std::time(nullptr)};
 
96
      transformer.setStylesheetParam("current_time_p", ("'" + std::string {std::asctime(std::localtime(&now))}+ "'").c_str());
 
97
      }
 
98
 
 
99
// ----- Use the transformer to invoke the XSLT style sheet on the XML document.
 
100
 
 
101
   if (transformer.transform(xml_doc, style_sheet, std::cout) != 0)
101
102
      std::cerr << "aptcp/main()/transformer.getLastError(): " << transformer.getLastError() << "\n" << style_sheet.str() << xml_doc.str();
102
 
      }
103
103
   }
104