You are not logged in.

KarlBlau

Trainee

  • "KarlBlau" is male
  • "KarlBlau" started this thread

Posts: 97

Location: Germany, BW

Occupation: Student

  • Send private message

1

Sunday, July 24th 2005, 12:49pm

Downloading Keystatistics from Yahoo.Finance

Hi,

I want to download parse and save the data one gets at for http://finance.yahoo.com/q/ks?s=GT for example. I did the following:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
	QFile *fileGet;
	QHttp *httpGet;
	
	httpGet = new QHttp();
	fileGet = new QFile();

	// [URL]http://finance.yahoo.com/q/ks?s=GT[/URL]
	
	fileGet->setName("Fund-GT.txt");
	fileGet->open(IO_WriteOnly);
	
	httpGet->setHost("finance.yahoo.com");
	httpGet->get("/q/ks?s=GT", fileGet);
	
	httpGet->closeConnection();
	
	qDebug("downloaded");


A file is downloaded, but it is not the same as if I open http://finance.yahoo.com/q/ks?s=GT with Firefox and save the file by hand.

The data information are no more in the saved file. Why?
Are there different ways how to download files?

Thanks for any comments!

Karl

This post has been edited 1 times, last edit by "KarlBlau" (Jul 24th 2005, 3:30pm)


KarlBlau

Trainee

  • "KarlBlau" is male
  • "KarlBlau" started this thread

Posts: 97

Location: Germany, BW

Occupation: Student

  • Send private message

2

Sunday, July 24th 2005, 3:31pm

It works just the way I posted it. The wrong data was caused by another thing.
Bye, Karl

KarlBlau

Trainee

  • "KarlBlau" is male
  • "KarlBlau" started this thread

Posts: 97

Location: Germany, BW

Occupation: Student

  • Send private message

3

Sunday, July 24th 2005, 4:50pm

One more question

Hi,

as I wrote in my last post, the download of the file works.
I need to open the file just as the download is ready. So I did this:

Source code

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
27
28
29
30
31
// DOWNLOADING THE FILE
	QFile *fileGet;
	QHttp *httpGet;
	
	httpGet = new QHttp();
	fileGet = new QFile();

	fileGet->setName("data.txt");
	fileGet->open(IO_WriteOnly);

	httpGet->setHost("finance.yahoo.com");
	httpGet->get("/q/ks?s=GT", fileGet);

	httpGet->closeConnection();
	
	fileGet->close();

// OPENING THE FILE
	
	std::string filename="data.txt";
	std::string dummy;
	
	std::ifstream file(filename.c_str());
	if (file)
	{
		while (!file.eof())
		{
			std::getline(file, dummy);
			std::cout << dummy << std::endl;
		}
	}
This doesn't work. It seems as if the file data.txt was empty. No line is plotted by the 'cout << dummy' command. Altough the file is filled.
But when I use the second part of the code (OPENING THE FILE) without the first part (DOWNLOADING THE FILE) before it (-> I open the data.txt from the last downlad) then the 'cout << dummy' shows the correct content of the file!
That makes me think that the data.txt isn't closed after the fileGet->close() command. Or something like this.

I hope you know what I mean.

Any idea?

Karl

jacek

Master

  • "jacek" is male

Posts: 2,729

Location: Warsaw, Poland

  • Send private message

4

Sunday, July 24th 2005, 4:56pm

RE: One more question

Quoted

From Qt docs
int QHttp::get ( const QString & path, QIODevice * to = 0 )
...
The function does not block and returns immediately. [...] When it is finished the requestFinished() signal is emitted.

KarlBlau

Trainee

  • "KarlBlau" is male
  • "KarlBlau" started this thread

Posts: 97

Location: Germany, BW

Occupation: Student

  • Send private message

5

Sunday, July 24th 2005, 5:08pm

I see. I would like to keep alive the serial construction of the code. Is there a way to wait right behind the Downloading Part until the job is done and thereafter the program continues with opening the file?

Something like
while(!EndOfDownload) { }

Thanks, Karl

jacek

Master

  • "jacek" is male

Posts: 2,729

Location: Warsaw, Poland

  • Send private message

6

Sunday, July 24th 2005, 7:07pm

Quoted

Originally posted by KarlBlau
Something like
while(!EndOfDownload) { }

If you want to get any signals from QHttp, you can't block the event loop. Something like this might work:

Source code

1
while( !end ) qApp->processEvents();
Of course you will have to set that end variable to true in a slot.