#include #include #include #include #include using namespace std; #define UNAVAILABLE 0 #define SOLD_OUT 1 #define AVAILABLE 2 #define TWO_FOR_ONE 3 #define PREVIEW 4 #define FREE 5 void printEndTime(ofstream& outf,string &startTimeStr, int hours, int minutes) { int startHour, startMinute; size_t pos = startTimeStr.find(":"); if(pos != string::npos) { startHour = stoi(startTimeStr.substr(0, pos)); startMinute = stoi(startTimeStr.substr(pos + 1)); outf << (startHour + hours + ((minutes + startMinute) / 60)) % 24 << ':' << (minutes + startMinute) % 60 << ','; } // if colon found else outf << " ,"; } // calcEndTime int main() { string fileName, buffer; char searchString[256]; int fileNumber; size_t pos, pos2, pos3; int count = 0, availability, hours, minutes; ofstream outf("theater2025.csv"); outf << "Title,Start,Length,End,Venue,28,29,30,31,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26\n"; outf <<" , , , , ,M,T,W,T,F,S,S,M,T,W,T,F,S,S,M,T,W,T,F,S,S,M,T,W,T,F,S,S,M,T\n"; for (fileNumber = 1; fileNumber < 22; fileNumber++) { fileName = "Search _ Edinburgh Festival Fringe" + to_string(fileNumber) + ".html"; ifstream inf(fileName.c_str()); inf.seekg(0, ios::end); buffer.reserve(inf.tellg()); inf.seekg(0, std::ios::beg); buffer.assign((istreambuf_iterator(inf)), istreambuf_iterator()); for(size_t i = 0; i < buffer.length(); i++) if(buffer[i] == ',') buffer[i] = ';'; pos = buffer.find("THEATRE", 0); while (pos != string::npos) { pos = buffer.find("THEATRE", pos + 1); pos = buffer.find("event-card-search_eventTitle", pos); pos = buffer.find(">", pos); // cout << pos << endl; if(pos != string::npos) // if more titles { pos2 = buffer.find("<", pos); outf << buffer.substr(pos + 1, pos2 - pos -1) << ','; // title pos = buffer.find("Aug", pos) + 11; pos = buffer.find(">", pos) + 1; pos2 = buffer.find("<", pos); string startTimeStr = buffer.substr(pos, pos2 - pos); outf << startTimeStr << ","; pos = buffer.find("eventDuration", pos); pos = buffer.find(">", pos) + 1; pos2 = buffer.find("<", pos); // outf << buffer.substr(pos, pos2 - pos) << ','; // duration string string duration = buffer.substr(pos, pos2 - pos); pos3 = duration.find("hour"); hours = minutes = 0; if(pos3 != string::npos) // if hour { hours = stoi(duration); duration = duration.substr(pos3 + 3); // eliminate hour pos3 = duration.find(" "); if(pos3 != string::npos) // if a space after hour { duration = duration.substr(pos3); minutes = stoi(duration); } // if a space after hour } // if an hour else // no hour minutes = stoi(duration); outf << hours * 60 + minutes << ','; printEndTime(outf, startTimeStr, hours, minutes); pos = buffer.find("rule=\"evenodd\">", pos2); if(buffer.find("Various venues", pos) - pos < 1000) outf << "Various venues"; else // not Various venues { pos = buffer.find("", pos) + 13; pos2 = buffer.find("<", pos); outf << buffer.substr(pos, pos2 - pos); // venue } for(int day = 27; day != 26; day++) { availability = UNAVAILABLE; sprintf(searchString, ">%d<", day); pos2 = buffer.find(searchString, pos); pos3 = buffer.find("Available", pos); if(pos3 < pos2) // Available found availability = AVAILABLE; else // not Available { pos3 = buffer.find ("TwoForOne", pos); if(pos3 < pos2) // TwoForOne found availability = TWO_FOR_ONE; else // not Available, nor TwoForOne { pos3 = buffer.find ("Preview", pos); if(pos3 < pos2) // Preview found availability = PREVIEW; else // not Previow, nor Available, nor TwoForOne { pos3 = buffer.find ("NoAllocation", pos); if(pos3 < pos2) // NoAllocation found availability = SOLD_OUT; } // else not Preview, nor Available, nor TwoForOne } // else not Available, nor TwoForOne } // else not Available outf << ',' << availability; if (day == 31) day = 0; pos = pos2 + 5; } // for i outf << endl; } //if show found } // while more shows inf.close(); } // for fileNumber outf.close(); return 0; }