📄 admin.cpp
字号:
#include "string.h"#include "stdio.h"#include <stdlib.h>#include "admin.h"#include "utils.h"#include "database.h"#define XML_PREFIX "tempdata"int processRss(char* rss, int class_id, struct Outline* outline, int is_insert_news){ struct Channel* channel = NULL; struct Channel* pCurrent = NULL; struct ITEM* pItem = NULL; int ret = 0; int count = 0; channel = createRss(rss, outline); if(channel == NULL) { return -1; } pCurrent = channel; while(pCurrent) { pItem = pCurrent->pItem; while(pItem) { pItem = pItem->pNext; } pCurrent = pCurrent->pNext; } ret = db_init(); if(ret == 0) { debug("连接数据库成功\n"); int source_id = query_sourceid(class_id, outline->title); if(source_id < 0) { db_fini(); error("获取souceid失败,%s还没有添加到数据库\n", outline->title); return -1; } debug("准备插入到t_superlink表\n"); count = set_superlink(outline, class_id, source_id, channel); debug("插入到t_superlink表结束:插入数量%d\n", count); ret = count; if(is_insert_news == 1 && count > 0) {//仅仅插入新闻链接到t_news表中 debug("准备插入到t_news表\n"); int cnt = set_news(count, outline, class_id, source_id, channel); debug("插入到t_news表结束:插入数量%d\n", cnt); } db_fini(); debug("关闭数据库连接\n"); }else { ret = -2; error("db_init failed.\n"); } destroyRss(channel); return ret;}int processOutline(int class_id, struct Outline* outline, int is_insert_news){ char rss_file[32]; sprintf(rss_file, "%s.xml", XML_PREFIX); debug("准备下载:%s\n", outline->xmlUrl); char command[256]; sprintf(command, "rm %s -f && wget -t1 -q -O %s %s", rss_file, rss_file, outline->xmlUrl); system(command); debug("下载结束\n"); if(filesize(rss_file) <= 0) return -1; int ret = processRss(rss_file, class_id, outline, is_insert_news); if(ret == -1) debug("format of %s is wrong.\n", outline->xmlUrl); if(ret == -2) debug("connection to database failed.\n"); return ret; }int processSource(int key, struct Source* source){ struct Outline* pNext = NULL; struct Outline* pCur = source->outline; int class_id = 0; int source_id = 0; int is_insert_news = 0; int ret = db_init(); if(ret == 0) { class_id = query_classid(key, source->subkey); db_fini(); } if(class_id < 0) return -1; if(source->subkey == 0) is_insert_news = 1;//仅仅插入新闻条目 while(pCur) { pNext = pCur->pNext; ret = processOutline(class_id, pCur, is_insert_news); info(" 来源:%s; 类型: %d; 链接:%s; 新增条目: %d\n", pCur->title, pCur->kind, pCur->xmlUrl, ret); pCur = pNext; } return 0;}int processChannel(struct ChannelCuster* channelCuster){ struct Source* pNext = NULL; struct Source* pCur = channelCuster->source; while(pCur) { info("%s(共%d条): \n", pCur->name, pCur->outline_count); pNext = pCur->pNext; processSource(channelCuster->key, pCur); pCur = pNext; } return 0;}int work(struct ChannelCuster* channelCuster){ struct ChannelCuster* pNext = NULL; struct ChannelCuster* pCur = channelCuster; int count = 1; while(pCur) { info("------------%s-----------\n", pCur->name); pNext = pCur->pNext; processChannel(pCur); count++; pCur = pNext; } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -