Ejemplo n.º 1
0
void gen_hot_subjects_xml(int mytype)
{
    FILE *fp;
    char curfile[256];
    char xml_buf[256];
    char url_buf[256];
    int i;

    if (mytype==4) {
        gen_blessing_list_xml();
        return;
    }

    sprintf(curfile, "xml/%s.xml", myfile[mytype]);
    if ((fp = fopen(curfile, "w")) != NULL) {
        fprintf(fp, "<?xml version=\"1.0\" encoding=\"GBK\"?>\n");
        fprintf(fp, "<hotsubjects>\n");

        for (i = 0; i < topnum; i++) {
            fprintf(fp, "<hotsubject>\n");
            fprintf(fp, "<title>%s</title>\n", encode_url(url_buf,encode_xml(xml_buf, top[i].title,
                    sizeof(xml_buf)),sizeof(url_buf)));
            fprintf(fp, "<author>%s</author>\n", encode_url(url_buf,top[i].userid,sizeof(url_buf)));
            fprintf(fp, "<board>%s</board>\n", encode_url(url_buf,top[i].board,sizeof(url_buf)));
            fprintf(fp, "<time>%ld</time>\n", top[i].date);
            fprintf(fp, "<number>%d</number>\n", top[i].number);
            fprintf(fp, "<groupid>%d</groupid>\n", top[i].groupid);
            fprintf(fp, "</hotsubject>\n");
        }
        fprintf(fp, "</hotsubjects>\n");

        fclose(fp);
    }
}
Ejemplo n.º 2
0
void gen_hot_subjects_xml(int mytype)
{
    FILE *fp;
    char curfile[256];
    char xml_buf[256];
    char url_buf[256];
    int i;

    if (mytype==4) {
        gen_blessing_list_xml();
        return;
    }

    sprintf(curfile, "xml/%s.xml", myfile[mytype]);
    if ((fp = fopen(curfile, "w")) != NULL) {
        fprintf(fp, "<?xml version=\"1.0\" encoding=\"GBK\"?>\n");
        fprintf(fp, "<hotsubjects>\n");

        for (i = 0; i < topnum; i++) {
            fprintf(fp, "<hotsubject>\n");
            fprintf(fp, "<title>%s</title>\n", encode_url(url_buf,encode_xml(xml_buf, top[i].title,
                    sizeof(xml_buf)),sizeof(url_buf)));
            fprintf(fp, "<author>%s</author>\n", encode_url(url_buf,top[i].userid,sizeof(url_buf)));
            fprintf(fp, "<board>%s</board>\n", encode_url(url_buf,top[i].board,sizeof(url_buf)));
            fprintf(fp, "<time>%ld</time>\n", top[i].date);
            fprintf(fp, "<number>%d</number>\n", top[i].number);
            fprintf(fp, "<groupid>%d</groupid>\n", top[i].groupid);
            fprintf(fp, "</hotsubject>\n");
        }
        fprintf(fp, "</hotsubjects>\n");

        fclose(fp);
    }

#ifdef REDIS
    redisContext *redis = redisConnect("127.0.0.1", 6379);
    const char *pattern = "stat:%s:%s";
    char key[128];
    char value[512];
    const char *argv[3] = { "RPUSH", key, value };

#define RPUSH(ikey,itype,ivalue) {\
    snprintf(key, 128, pattern, myfile[mytype], ikey);\
    snprintf(value, 512, itype, ivalue);\
    redisAppendCommandArgv(redis, 3, argv, NULL);\
}

#define DEL(ikey) {\
    snprintf(key, 128, pattern, myfile[mytype], ikey);\
    snprintf(value, 512, "DEL %s", key);\
    redisAppendCommand(redis, value);\
}

    DEL("title");
    DEL("author");
    DEL("board");
    DEL("replies");
    DEL("time");
    DEL("id");
    for (i = 0; i < topnum; i++) {
        RPUSH("title"   , "%s"  , top[i].title);
        RPUSH("author"  , "%s"  , top[i].userid);
        RPUSH("board"   , "%s"  , top[i].board);
        RPUSH("replies" , "%lu" , (unsigned long)top[i].number);
        RPUSH("time"    , "%lu" , (unsigned long)top[i].date);
        RPUSH("id"      , "%lu" , (unsigned long)top[i].groupid);
    }
    redisReply *reply;
    redisGetReply(redis, (void*)&reply);
    freeReplyObject(reply);
    redisFree(redis);

#undef RPUSH
#undef DEL
#endif
}