예제 #1
0
	//-----------------------------------------------------------------------
	int XmlConvert(InStm *pin, const strvector &css, const strvector &fonts, const strvector &mfonts,
		XlitConv *xlitConv, OutPackStm *pout)
	{
		// perform pass 1 to determine fb2 document structure and to collect all cross-references inside the fb2 file
		UnitArray units;
		// The input file name is pin->UIFileName();
		XMLDocument doc;
		doc.LoadFile(pin->UIFileName().c_str());
		XMLHandle hDoc(&doc);
		XMLHandle fb = hDoc.FirstChildElement("FictionBook");
		XMLHandle desc = fb.FirstChildElement("description");
		XMLHandle titleInfo = desc.FirstChildElement("title-info");
		XMLHandle genre = titleInfo.FirstChildElement("genre");
		XMLHandle genreInfo = genre.FirstChild();
		const char* txt = genreInfo.ToNode()->Value(); // "Ciencia-Ficción"

		// Now build from the above the damn epub!
		// Go directly to DoConvertionPass2 and substitute XML calls to make epub.

		// CONVERTION PASS 1 (DETERMINE DOCUMENT STRUCTURE AND COLLECT ALL CROSS-REFERENCES INSIDE THE FB2 FILE)
		Ptr<ConverterPass1> conv = new ConverterPass1(&units);
		conv->XmlScan(hDoc);
		//DoConvertionPass1(CreateScanner(pin), &units);
		//pin->Rewind();

		// sanity check
		if (units.size() == 0)
			InternalError(__FILE__, __LINE__, "I don't know why but it happened that there is no content in input file!");

		// perform pass 2 to create epub document
		//XmlConversionPass2(hDoc, css, fonts, mfonts, xlitConv, &units, pout);
		//DoConvertionPass2(CreateScanner(pin), css, fonts, mfonts, xlitConv, &units, pout);
		return 0;
	}
예제 #2
0
bool XMLScreenLoader::loadText(XMLHandle &rootHandle, std::vector<Text>* text) {
  XMLElement *currElement = rootHandle.FirstChildElement("text").ToElement(); //grab the first element under the text section
  if (currElement){
    do {

      Text tempText{};

      currElement->QueryFloatAttribute("z", &tempText.z);
      currElement->QueryFloatAttribute("top", &tempText.top);
      currElement->QueryFloatAttribute("size", &tempText.size);
      if(!extractColor(currElement, &tempText.color)) return false;
      tempText.align = currElement->Attribute("align");

      if (tempText.align != "centered" and tempText.align != "left" and tempText.align != "right") {
        Util::Log(Error, "XMLScreenLoader") << "Alignment \"" << tempText.align << "\" is not supported!";
        continue;
      }

      tempText.text = currElement->GetText();

      text->push_back(tempText);
    } while((currElement = currElement->NextSiblingElement("text")) != nullptr);
  } else return false;

  return true;
}
예제 #3
0
	//-----------------------------------------------------------------------
	bool ConverterPass1::XmlFictionBook(XMLHandle hDoc)
	{
		XMLHandle fb = hDoc.FirstChildElement("FictionBook");
		XMLElement* fbEl;
		if (!(fbEl = fb.ToElement())) {
			errMsg = "FictionBook element not found.";
			return false;
		}

		if (!fbEl->Attribute("xmlns", "http://www.gribuser.ru/xml/fictionbook/2.0")) {
			errMsg = "Missing FictionBook namespace definition.";
			return false;
		}
		if (!fbEl->Attribute("xmlns:l", "http://www.w3.org/1999/xlink") &&
			!fbEl->Attribute("xmlns:xlink", "http://www.w3.org/1999/xlink")) {
			errMsg = "Bad FictionBook namespace definition or bad xlink namespace definition.";
			return false;
		}

		//<description>
		XMLElement *desc = fbEl->FirstChildElement("description");
		if (!desc) {
			errMsg = "description element not found.";
			return false;
		}
		XMLElement *titleInfo = desc->FirstChildElement("title-info");
		if (!titleInfo) {
			errMsg = "title-info element not found.";
			return false;
		}
		// needs to process "annotation" and "coverpage" elements here
		XmlAnnotation(titleInfo->FirstChildElement("annotation"), true);

		//</description>

		//<body>
		body(Unit::MAIN);
		if (s_->IsNextElement("body"))
			body(Unit::NOTES);
		if (s_->IsNextElement("body"))
			body(Unit::COMMENTS);
		//</body>
	}
예제 #4
0
bool XmlScreenLoader::loadText(XMLHandle &rootHandle, std::vector<Text>* textVector) {
  //grab the first element under the text section
  XMLElement *currentElement = rootHandle.FirstChildElement("text").ToElement();
  if (currentElement) {
    do {
      Text text{};
      std::string align;

      currentElement->QueryFloatAttribute("z", &text.z);
      currentElement->QueryFloatAttribute("top", &text.top);
      currentElement->QueryFloatAttribute("size", &text.size);
      if (not extractColor(currentElement, &text.color)) {
        return false;
      }
      align = currentElement->Attribute("align");

      if (align == "center") {
        text.align = Text::Center;
      } else if (align == "left") {
        text.align = Text::Left;
      } else if (align == "right") {
        text.align = Text::Right;
      } else {
        Util::Log(Error, XmlScreenLoader::MODULE_NAME) << "Alignment \"" << align << "\" is not supported!";
        continue;
      }

      text.content = currentElement->GetText();

      textVector->push_back(text);
    } while ((currentElement = currentElement->NextSiblingElement("text")) != nullptr);
  } else {
    return false;
  }

  return true;
}
예제 #5
0
int main()
{
	
	bool soundFlag = false;
	std::string headlines[3000];
	int strCount = 0;
	bool storyExists = false;
	int pageSwitch = 0;
while (true){
	std::ofstream a_file ( "ESPN_NEWS.txt", std::ios::app );
	CURL *curl;
    FILE *fp;
    CURLcode res;
	if (pageSwitch==0){
		char *url = "http://sports.espn.go.com/espn/rss/news";
		char outfilename[FILENAME_MAX] = "input3.xml";
	    curl = curl_easy_init();
	    if (curl) {
			fp = fopen(outfilename,"wb");
			curl_easy_setopt(curl, CURLOPT_URL, url);
			curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
			curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
			res = curl_easy_perform(curl);
			curl_easy_cleanup(curl);
			fclose(fp);
	   }
	}
	else if(pageSwitch==1){
		char *url = "http://sports.espn.go.com/espn/rss/nfl/news";
		char outfilename[FILENAME_MAX] = "input3.xml";
		curl = curl_easy_init();
		if (curl) {
		     fp = fopen(outfilename,"wb");
			 curl_easy_setopt(curl, CURLOPT_URL, url);
			 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
			 curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
			 res = curl_easy_perform(curl);
			 curl_easy_cleanup(curl);
			 fclose(fp);
		}
	}
	else if(pageSwitch==2){
		char *url = "http://sports.espn.go.com/espn/rss/nba/news";
		char outfilename[FILENAME_MAX] = "input3.xml";
	    curl = curl_easy_init();
	    if (curl) {
		 fp = fopen(outfilename,"wb");
		 curl_easy_setopt(curl, CURLOPT_URL, url);
		 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
		 curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
		 res = curl_easy_perform(curl);
		 curl_easy_cleanup(curl);
		 fclose(fp);
		}
	}
	else{
	  char *url = "http://sports.espn.go.com/espn/rss/espnu/news";
	  char outfilename[FILENAME_MAX] = "input3.xml";
	  curl = curl_easy_init();
	  if (curl) {
        fp = fopen(outfilename,"wb");
        curl_easy_setopt(curl, CURLOPT_URL, url);
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
        res = curl_easy_perform(curl);
        curl_easy_cleanup(curl);
        fclose(fp);
	  }
	}

	////////////////////////////////////////////////////////////////
	bool loopFlag = true;
	bool bigLoop = true;
	
    tinyxml2::XMLDocument doc;
    doc.LoadFile( "input3.xml" );
	XMLNode *rootnode = doc.FirstChild();
	//////////////////////////////
	rootnode = rootnode->NextSibling();
	rootnode = rootnode->FirstChild();////////////hard code to get past the xml header into <ITEM> </ITEM portion
	rootnode = rootnode->FirstChild();
	rootnode = rootnode->NextSibling();
	///////////////////////////////////
	
	while(loopFlag==true){
		if(std::strcmp(rootnode->Value(),"item") != 0){   
			rootnode = rootnode->NextSibling();
		}
		else 
			loopFlag=false;
	}


	while(bigLoop==true){
		XMLHandle safe = rootnode;
		if(safe.ToNode()==NULL)
			bigLoop=false;
		else{
			NewsEntry *story = new NewsEntry(); 
			rootnode = rootnode->FirstChild();
			rootnode = rootnode->NextSibling();
			rootnode = rootnode->FirstChild();
			story->setTitle(rootnode->Value());
			for(int x=0; x<strCount; x++){
				if(story->getTitle().compare(headlines[x])==0){
					storyExists = true;
				}

			}	

			if(storyExists==false){
				if(soundFlag==true){
					PlaySound(TEXT("sportscenter.wav"), NULL, SND_FILENAME | SND_ASYNC);
				}
				std::cout<< story->getTitle() <<std::endl;
				a_file << story->getTitle();
				a_file << "\n";
				headlines[strCount] = story->getTitle();
				strCount++;
			}
			
		
			rootnode = rootnode->Parent();
			rootnode = rootnode->NextSibling();
			rootnode = rootnode->FirstChild();
			story->setDescription(rootnode->Value());
			if(storyExists==false){
				std::cout<< story->getDescription() <<std::endl;
				a_file << story->getDescription();
				a_file << "\n";
			}
			
			rootnode = rootnode->Parent();
			rootnode = rootnode->NextSibling();
			rootnode = rootnode->FirstChild();
			story->setPubDate(rootnode->Value());
			if(storyExists==false){
				std::cout << story->getPubdate() <<std::endl;
				a_file << story->getPubdate();
				a_file << "\n";
			}
		
			rootnode = rootnode->Parent();
			rootnode = rootnode->NextSibling();
			
			rootnode = rootnode->FirstChild();
			story->setLink(rootnode->Value());
			if(storyExists==false){
				//std::cout<< story->getLink() << std::endl;
				a_file << story->getLink();
				a_file << "\n";
				a_file << "\n";
				printf("\n");
			}
			
			rootnode = rootnode->Parent();
			
			rootnode = rootnode->Parent();
			rootnode = rootnode->NextSibling();
			delete story;
			storyExists = false;
			
		}
	}

	pageSwitch++;
	if(pageSwitch>3){
		pageSwitch = 0;
		soundFlag=true;
	}
	a_file.close();
	Sleep(100000);
  }
	
  return 0;
}