I have a patch that fix the problem.
In order to avoid having such a problem again (2nd or 3rd time) I
changed data source.
Instead of fetching html and parsing quotes I get a csv file (this seems
to be a new yahho feature).
Parsing is easier ...
Usage/include of some other kind of data is possible and easy
May I commit in gnome-2-4 branch ? in HEAD ?
Rémi Cohen-Scali wrote:
Hy
Was on vacations, (just back).
If the problem still persist, I'll try to get a patch for the end of week
Kevin Vandersloot wrote:
OK, this is a Show-Stopper for gnome-applets. We need to get a patch in
ASAP, otherwise we have to disable gtik from the build for the time
being.
Remi: have you got a working patch yet? Do you think you can get a
working patch soon? I don't know much about the parsing code to fix it.
Anyone else feel like looking into the problem.
Kevin
On Fri, 2003-09-05 at 01:18, Rémi Cohen-Scali wrote:
Yahoo finance web still changed its look. Stock ticker is of course
broken.
Here is a patch for fixing gtik.
Is it possible to commit it for 2.4?
Else gtik is not usable.
----
diff -urN gnome-applets-2.3.90/gtik.old/gtik.c
gnome-applets-2.3.90/gtik/gtik.c
--- gnome-applets-2.3.90/gtik.old/gtik.c Thu Jul 24 03:48:15 2003
+++ gnome-applets-2.3.90/gtik/gtik.c Fri Sep 5 07:10:56 2003
@@ -271,9 +271,9 @@
stockdata->vfshandle = NULL;
}
- source_text_uri = g_strconcat("http://finance.yahoo.com/q?s=",
+ source_text_uri = g_strconcat("http://finance.yahoo.com/q/cq?s=",
stockdata->props.tik_syms,
- "&d=v2",
+ "&d=v1",
NULL);
source_uri = gnome_vfs_uri_new(source_text_uri);
@@ -411,7 +411,7 @@
int i=0;
int j=0;
- static char Text[256]="";
+ static char Text[1024]="";
if (line == NULL) {
Text[0] = '\0';
@@ -441,10 +441,10 @@
}
/*-----------------------------------------------------------------*/
- static char *parseQuote(FILE *CONFIG, char line[512]) {
+ static char *parseQuote(FILE *CONFIG, char line[1024]) {
- char symbol[512];
- char buff[512];
+ char symbol[1024];
+ char buff[1024];
char price[16];
char change[16];
char percent[16];
@@ -473,16 +473,16 @@
linenum++;
/* Skip the time... */
- if (!AllOneLine) fgets(line,255,CONFIG);
+ if (!AllOneLine) fgets(line,1023,CONFIG);
else section = strtok(NULL,"|");
linenum++;
while (linenum < 8 ) {
if (!AllOneLine) {
- fgets(line,255,CONFIG);
+ fgets(line,1023,CONFIG);
if (strstr(line,
- "<td align=center nowrap colspan=2>")) {
+ "<td class=\"yfnc_tabledata1\" nowrap=\"nowrap\"
align=\"center\">")) {
strcpy(change,"");
strcpy(percent,"");
linenum=100;
@@ -491,26 +491,26 @@
else {
section = strtok(NULL,"|");
if (strstr(section,
- "<td align=center nowrap colspan=2>")) {
+ "<td class=\"yfnc_tabledata1\" nowrap=\"nowrap\"
align=\"center\">")) {
strcpy(change,"");
strcpy(percent,"");
linenum=100;
}
}
- if (linenum == 2) { + if (linenum == 3) {
if (!AllOneLine)
strcpy(price,extractText(line));
else
strcpy(price,extractText(section));
}
- else if (linenum == 3) {
+ else if (linenum == 4) {
if (!AllOneLine)
strcpy(change,extractText(line));
else
strcpy(change,extractText(section));
}
- else if (linenum == 4) {
+ else if (linenum == 5) {
if (!AllOneLine)
strcpy(percent,extractText(line));
else
@@ -530,7 +530,7 @@
int configured(StockData *stockdata) {
int retVar;
- char buffer[512];
+ char buffer[2048];
static FILE *CONFIG;
CONFIG = fopen((const char *)stockdata->configFileName,"r");
@@ -545,7 +545,7 @@
fgets(buffer, sizeof(buffer)-1, CONFIG);
if (strstr(buffer,
- "<td nowrap align=left><font face=arial
size=-1><a href=\"/q\?s=")) {
+ "<td class=\"yfnc_tabledata1\"
nowrap=\"nowrap\" align=\"center\"><b><a href=\"/q?s=")) {
setOutputArray(stockdata,
parseQuote(CONFIG,buffer));
retVar = 1;
_______________________________________________
desktop-devel-list mailing list
desktop-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/desktop-devel-list
_______________________________________________
desktop-devel-list mailing list
desktop-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/desktop-devel-list
______________________________________________________________________
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-applets/ChangeLog,v
retrieving revision 1.589.2.1
diff -u -r1.589.2.1 ChangeLog
--- ChangeLog 23 Sep 2003 01:28:17 -0000 1.589.2.1
+++ ChangeLog 24 Sep 2003 00:38:21 -0000
@@ -1,3 +1,17 @@
+2003-09-24 Remi Cohen-Scali <rcoscali cvs gnome org>
+
+ * gtik/gtik.c: Fixed quote parsing in gtik. Now use
+ a csv file fetched from yahoo finance site. This
+ should avoid bugs because of html layout modifications.
+ This seems to be a new recent but stable feature.
+ (updateOutput): Use CSV export URL.
+ (parseQuote): Implement a far simpler parser for CSV.
+ (configured): One and only one line per ticker. No more
+ need to find a magic string. Only get necessary data.
+ (create_hig_category): type catagory -> category
+ (splitChange): Use of bzero. Removed rise for minus
+ change.
+
2003-09-22 Kevin Vandersloot
* configure.in: release 2.4.1 for Stock Ticker fix.
Index: gtik/gtik.c
===================================================================
RCS file: /cvs/gnome/gnome-applets/gtik/gtik.c,v
retrieving revision 1.90.2.1
diff -u -r1.90.2.1 gtik.c
--- gtik/gtik.c 19 Sep 2003 00:22:29 -0000 1.90.2.1
+++ gtik/gtik.c 24 Sep 2003 00:38:22 -0000
@@ -270,10 +270,25 @@
gnome_vfs_async_cancel (stockdata->vfshandle);
stockdata->vfshandle = NULL;
}
-
- source_text_uri = g_strconcat("http://finance.yahoo.com/q/cq?s=",
+
+ /*
+ * Now using a CSV file to get quotes. Specification of CSV format
+ * is in URL f=sl1c1.
+ * Availables data columns are:
+ * s: ticker symbol
+ * l: last price
+ * d: date
+ * t: time
+ * c: change
+ * o: open price
+ * h: daily high
+ * g: daily low
+ * v: volume
+ * The digit following some data specifiers change data formating (html/raw)
+ */
+ source_text_uri = g_strconcat("http://finance.yahoo.com/d/quotes.csv?s=",
stockdata->props.tik_syms,
- "&d=v1",
+ "&f=sl1c1&e=.csv",
NULL);
source_uri = gnome_vfs_uri_new(source_text_uri);
@@ -407,121 +422,46 @@
/*-----------------------------------------------------------------*/
- static char *extractText(const char *line) {
-
- int i=0;
- int j=0;
- static char Text[1024]="";
-
- if (line == NULL) {
- Text[0] = '\0';
- return Text;
- }
-
- while (i < (strlen(line) -1)) {
- if (line[i] != '>')
- i++;
- else {
- i++;
- while (line[i] != '<') {
- Text[j] = line[i];
- i++;j++;
- }
- }
- }
- Text[j] = '\0';
- i = 0;
- while (i < (strlen(Text)) ) {
- if (Text[i] < 32)
- Text[i] = '\0';
- i++;
- }
- return(Text);
-
- }
-
- /*-----------------------------------------------------------------*/
- static char *parseQuote(FILE *CONFIG, char line[1024]) {
+ static char *parseQuote(char line[1024]) {
- char symbol[1024];
- char buff[1024];
- char price[16];
- char change[16];
- char percent[16];
- static char result[1024]="";
- int linenum=0;
- int AllOneLine=0;
- int flag=0;
- char *section = NULL;
- char *ptr;
-
- if (strlen(line) > 64) AllOneLine=1;
-
- if (AllOneLine) {
- strcpy(buff,line);
- while (!flag) {
- if ((ptr=strstr(buff,"</td>"))!=NULL) {
- ptr[0] = '|';
- }
- else flag=1;
- }
- section = strtok(buff,"|");
- }
- /* Get the stock symbol */
- if (!AllOneLine) strcpy(symbol,extractText(line));
- else strcpy(symbol,extractText(section));
- linenum++;
-
- /* Skip the time... */
- if (!AllOneLine) fgets(line,1023,CONFIG);
- else section = strtok(NULL,"|");
- linenum++;
-
- while (linenum < 8 ) {
- if (!AllOneLine) {
- fgets(line,1023,CONFIG);
-
- if (strstr(line,
- "td class=\"yfnc_tabledata1\" nowrap=\"nowrap\" align=\"center\">")) {
- strcpy(change,"");
- strcpy(percent,"");
- linenum=100;
- }
- }
- else {
- section = strtok(NULL,"|");
- if (section && strstr(section,
- "td class=\"yfnc_tabledata1\" nowrap=\"nowrap\" align=\"center\">")) {
- strcpy(change,"");
- strcpy(percent,"");
- linenum=100;
- }
- }
-
- if (linenum == 2) {
- if (!AllOneLine)
- strcpy(price,extractText(line));
- else
- strcpy(price,extractText(section));
- }
- else if (linenum == 3) {
- if (!AllOneLine)
- strcpy(change,extractText(line));
- else
- strcpy(change,extractText(section));
- }
- else if (linenum == 4) {
- if (!AllOneLine)
- strcpy(percent,extractText(line));
- else
- strcpy(percent,extractText(section));
- linenum = 100;
- }
- linenum++;
- }
- sprintf(result,"%s:%s:%s:%s",
- symbol,price,change,percent);
- return(result);
+ char *symbol;
+ char *price;
+ char *change;
+ double price_val;
+ double change_val;
+ double percent;
+ static char result[512]="";
+
+ /* Yahoo file comme in C format */
+ setlocale(LC_NUMERIC, "C");
+
+ symbol = strtok(line, ",");
+ symbol++;
+ symbol[strlen(symbol) -1] = 0;
+ g_message ("symbol: %s", symbol);
+
+ price = strtok(NULL, ",");
+ price_val = strtod(price, NULL);
+
+ change = strtok(NULL, ",");
+ /* file in DOS format: remove \r\n */
+ change[strlen(change) -1] = 0;
+ change[strlen(change) -1] = 0;
+ change_val = strtod(change, NULL);
+
+ percent = (change_val/price_val)*1E+02;
+
+ /* Restore numeric format for displaying */
+ setlocale(LC_NUMERIC, getenv("LANG"));
+
+ if (change_val == 0.0)
+ sprintf(result,"%s:%1.2f:%1.2f:%1.2f%%",
+ symbol,price_val,change_val,percent);
+ else
+ sprintf(result,"%s:%1.2f:%1.2f:%+1.2f%%",
+ symbol,price_val,change_val,percent);
+
+ return result;
}
@@ -545,10 +485,9 @@
while ( !feof(CONFIG) ) {
fgets(buffer, sizeof(buffer)-1, CONFIG);
- if (strstr(buffer,
- "<td class=\"yfnc_tabledata1\" nowrap=\"nowrap\" align=\"center\"><b><a href=\"/q?s=")) {
+ if (!feof(CONFIG)) {
- setOutputArray(stockdata, parseQuote(CONFIG,buffer));
+ setOutputArray(stockdata, parseQuote(buffer));
retVar = 1;
}
else {
@@ -1356,7 +1295,7 @@
}
static GtkWidget *
- create_hig_catagory (GtkWidget *main_box, gchar *title)
+ create_hig_category (GtkWidget *main_box, gchar *title)
{
GtkWidget *vbox, *vbox2, *hbox;
GtkWidget *label;
@@ -1440,7 +1379,7 @@
label = gtk_label_new (_("Behavior"));
gtk_notebook_append_page (GTK_NOTEBOOK (notebook), behav_vbox, label);
- vbox = create_hig_catagory (behav_vbox, _("Update"));
+ vbox = create_hig_category (behav_vbox, _("Update"));
hbox2 = gtk_hbox_new (FALSE, 12);
gtk_box_pack_start (GTK_BOX (vbox), hbox2, FALSE, FALSE, 0);
@@ -1462,7 +1401,7 @@
if ( ! key_writable (PANEL_APPLET (stockdata->applet), "timeout"))
hard_set_sensitive (hbox2, FALSE);
- vbox = create_hig_catagory (behav_vbox, _("Scrolling"));
+ vbox = create_hig_category (behav_vbox, _("Scrolling"));
hbox2 = gtk_hbox_new (FALSE, 12);
gtk_box_pack_start (GTK_BOX (vbox), hbox2, FALSE, FALSE, 0);
@@ -1527,7 +1466,7 @@
size = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
- vbox = create_hig_catagory (appear_vbox, _("Display"));
+ vbox = create_hig_category (appear_vbox, _("Display"));
gtk_widget_show_all (vbox);
hbox2 = gtk_hbox_new (FALSE, 6);
@@ -1568,7 +1507,7 @@
if ( ! key_writable (PANEL_APPLET (stockdata->applet), "width"))
hard_set_sensitive (hbox2, FALSE);
- vbox = create_hig_catagory (appear_vbox, _("Font and Colors"));
+ vbox = create_hig_category (appear_vbox, _("Font and Colors"));
size = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
size2= gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
@@ -1973,11 +1912,15 @@
/*-----------------------------------------------------------------*/
char *splitChange(StockData *stockdata,char *data, StockQuote *quote) {
- char buff[128]="";
- static char buff2[128]="";
+ char buff[128];
+ static char buff2[128];
char *var1, *var2, *var3, *var4;
- char rise[1]="";
+ char rise[2];
+ bzero(buff, 128);
+ bzero(buff2, 128);
+ bzero(rise, 2);
+
strcpy(buff,data);
var1 = strtok(buff,":");
var2 = strtok(NULL,":");
@@ -2003,7 +1946,6 @@
#endif
var4[0] = '(';
quote->color = RED;
- sprintf (rise, "-");
}
else {
var3 = g_strdup(_("(No"));