Wednesday, July 8, 2020

Testing

#include <iostream>
#include <fstream>
#include <string>
#include <string.h>
#include <sstream>
#include <windows.h>
#include <shellapi.h>
#include <dos.h>
#define MAX 100

using namespace std;
char* initializestrings(char* s, int l)
{
  for(int i=0;i<l;i++)
  {
   s[i]='\0';

  }
  return s;
}
int main()
{
ofstream editing[MAX];
ifstream txtfile[MAX];
string links[MAX];
string csv[MAX];
char txt[2048];
int n;
cout<<"Enter the number of quizzes you want to update?\n";
cin>>n;
cout<<"Enter the links of quizzes you want to edit?\n";
for(int i=0; i<n; i++)
cin>>links[i];
string postid[n];
for(int i=0;i<n;i++)
{
int find1, find2; find1=0; find2=0;
find1 = links[i].find("=");
find2 = links[i].find("&");
if(find1<0 || find2<0 || find1>find2)
{
cout<<"URL: "<<i+1<<" is not of the correct format. Please rerun the program!";
exit(0);
}
else
{

postid[i] = links[i].substr(find1+1, find2-find1-1);
}
}

for(int i=0; i<n; i++)
{
links[i].insert(0,"'");
links[i].append("'");
string quizcsv ="'quiz.xlsx')";
    csv[i] = quizcsv.insert(1, postid[i]);

}
for(int i=0;i<n;i++)
{
txtfile[i].open("quiz_update.py");
editing[i].open("updatedscript.py");
while(!txtfile[i].eof())
{
     strcpy(initializestrings(txt, 2048),txt);
     txtfile[i].getline(txt, 2048);
     string temp; temp = "";
     temp = txt;
     int found, found2;
     found = temp.find("post_url = ");
     found2 = temp.find("input_file_path = os.path.join(sys.path[0]");
     if(found == 0)
     { 
     
temp = "";
temp = "post_url = ";
temp.append(links[i]);
editing[i]<<temp;
}
else if(found2 == 0)
{
temp = "";
temp = "input_file_path = os.path.join(sys.path[0], 'data', ";
temp.append(csv[i]);
editing[i]<<temp;
}
else
editing[i]<<temp;
editing[i]<<"\n";

}
editing[i].close();
txtfile[i].close();
ShellExecuteA(NULL, "open", "updatedscript.py", NULL, NULL, SW_SHOWNORMAL);
Sleep(480000);
    system("taskkill /IM py.exe /F");
    system("taskkill /IM chrome.exe /F");
    remove("updatedscript.py");
       
}


return 0;
}

No comments:

Post a Comment