Browse Source

Test

etomic
jl777 8 years ago
parent
commit
d753cf12cf
  1. 45
      iguana/dpow/dpow_prices.c

45
iguana/dpow/dpow_prices.c

@ -1271,29 +1271,37 @@ int32_t PAX_ecbparse(char *date,double *prices,char *url,int32_t basenum)
char *jsonstr,*relstr,*basestr,name[16]; int32_t count=0,i,relnum; cJSON *json,*ratesobj,*item; struct destbuf tmp; char *jsonstr,*relstr,*basestr,name[16]; int32_t count=0,i,relnum; cJSON *json,*ratesobj,*item; struct destbuf tmp;
if ( (jsonstr= issue_curl(url)) != 0 ) if ( (jsonstr= issue_curl(url)) != 0 )
{ {
// if ( Debuglevel > 2 ) if ( Debuglevel > 2 )
printf("(%s)\n",jsonstr); printf("(%s)\n",jsonstr);
if ( (json= cJSON_Parse(jsonstr)) != 0 ) if ( (json= cJSON_Parse(jsonstr)) != 0 )
{ {
copy_cJSON(&tmp,jobj(json,"date")), safecopy(date,tmp.buf,64); if ( jobj(json,"error") != 0 || jobj(json,"date") == 0 )
if ( (basestr= jstr(json,"base")) != 0 && strcmp(basestr,CURRENCIES[basenum]) == 0 && (ratesobj= jobj(json,"rates")) != 0 && (item= ratesobj->child) != 0 ) {
printf("Got error from fixer.io (%s)\n",jsonstr);
sleep(1);
}
else
{ {
while ( item != 0 ) copy_cJSON(&tmp,jobj(json,"date")), safecopy(date,tmp.buf,64);
if ( (basestr= jstr(json,"base")) != 0 && strcmp(basestr,CURRENCIES[basenum]) == 0 && (ratesobj= jobj(json,"rates")) != 0 && (item= ratesobj->child) != 0 )
{ {
if ( (relstr= get_cJSON_fieldname(item)) != 0 && (relnum= PAX_basenum(relstr)) >= 0 ) while ( item != 0 )
{ {
i = basenum*MAX_CURRENCIES + relnum; if ( (relstr= get_cJSON_fieldname(item)) != 0 && (relnum= PAX_basenum(relstr)) >= 0 )
prices[i] = item->valuedouble; {
//if ( basenum == JPYNUM ) i = basenum*MAX_CURRENCIES + relnum;
// prices[i] *= 100.; prices[i] = item->valuedouble;
// else if ( relnum == JPYNUM ) //if ( basenum == JPYNUM )
// prices[i] /= 100.; // prices[i] *= 100.;
count++; // else if ( relnum == JPYNUM )
if ( Debuglevel > 2 ) // prices[i] /= 100.;
printf("(%02d:%02d %f) ",basenum,relnum,prices[i]); count++;
sprintf(name,"%s%s",CURRENCIES[basenum],CURRENCIES[relnum]); if ( Debuglevel > 2 )
} else printf("cant find.(%s)\n",relstr);//, getchar(); printf("(%02d:%02d %f) ",basenum,relnum,prices[i]);
item = item->next; sprintf(name,"%s%s",CURRENCIES[basenum],CURRENCIES[relnum]);
} else printf("cant find.(%s)\n",relstr);//, getchar();
item = item->next;
}
} }
} }
free_json(json); free_json(json);
@ -1369,7 +1377,6 @@ int32_t ecb_matrix(double basevals[MAX_CURRENCIES],double matrix[MAX_CURRENCIES]
} else printf("ecb_matrix.(%s) load error fp.%p\n",fname,fp); } else printf("ecb_matrix.(%s) load error fp.%p\n",fname,fp);
datenum = conv_date(&seconds,date); datenum = conv_date(&seconds,date);
year = datenum / 10000, month = (datenum / 100) % 100, day = (datenum % 100); year = datenum / 10000, month = (datenum / 100) % 100, day = (datenum % 100);
printf("%d %d %d %d\n",datenum,year,month,day);
if ( loaded == 0 ) if ( loaded == 0 )
{ {
if ( (n= PAX_ecbprices(date,&matrix[0][0],year,month,day)) > 0 ) if ( (n= PAX_ecbprices(date,&matrix[0][0],year,month,day)) > 0 )
@ -1382,7 +1389,6 @@ int32_t ecb_matrix(double basevals[MAX_CURRENCIES],double matrix[MAX_CURRENCIES]
fclose(fp); fclose(fp);
} }
} //else printf("peggy_matrix error loading %d.%d.%d\n",year,month,day); } //else printf("peggy_matrix error loading %d.%d.%d\n",year,month,day);
printf("after loaded.(%s)\n",date);
} }
else else
{ {
@ -1412,7 +1418,6 @@ int32_t ecb_matrix(double basevals[MAX_CURRENCIES],double matrix[MAX_CURRENCIES]
return(-1); return(-1);
} }
//"2000-01-03" //"2000-01-03"
printf("call conv_date(%s)\n",date);
if ( (datenum= conv_date(&seconds,date)) < 0 ) if ( (datenum= conv_date(&seconds,date)) < 0 )
return(-1); return(-1);
//printf("loaded.(%s) nonz.%d (%d %d %d) datenum.%d\n",date,n,year,month,day,datenum); //printf("loaded.(%s) nonz.%d (%d %d %d) datenum.%d\n",date,n,year,month,day,datenum);

Loading…
Cancel
Save