Exemplo n.º 1
0
    def getBuildList(self, itemName, limit=5, source=''):
        #获取build基本信息
        db = WarframeDB()
        itemInfo = db.getBuildItemlikeName(itemName)
        if len(itemInfo) == 0:
            return '', '', None
        itemType = itemInfo[0]['item_type']
        itemBuildId = itemInfo[0]['build_id']
        nameEn = itemInfo[0]['name_en']
        nameZh = itemInfo[0]['name_zh']
        #解析url中的mod装配并格式化
        #先尝试取DB的记录,如果DB没有或者太老,则取网站上的

        #多抓取2个,存到数据库里。但是最终只返回limit个

        records = self.getBuildListFromDb(itemBuildId, itemType,
                                          self.BUILD_RECORD_NUM, itemName)
        if records == []:
            records = self.getBuildListFromUrl(itemBuildId, itemType, nameEn,
                                               nameZh, self.BUILD_RECORD_NUM)
        #这里需要经过推荐算法,从N个中,选取M个,格式化,然后返回
        finalRecords = records[0:limit]
        for rec in finalRecords:
            build = self.getBuildFromUrl(rec['url'])
            rec['build'] = self.buildDictToStr(build)
            rec['build_dict'] = build
        return nameEn, nameZh, finalRecords
Exemplo n.º 2
0
#!/usr/bin/python
# -*- coding:utf-8 -*-
import sys

reload(sys)
sys.setdefaultencoding('utf-8')

from lxml import etree
import requests
import json
import urllib
import MySQLdb
import types
import urllib2
import time
import httplib
from db import WarframeDB
from translator import WmTranslator
from BuildStatic import BuildStatic

tr = WmTranslator()
wdb = WarframeDB()
items = wdb.getBuildItemlikeName('')
for it in items:
    zh = tr.en2zh(it['name_en'])
    sql = """UPDATE build_item set name_zh='%s' where id=%s""" % (zh, it['id'])
    print sql
    print wdb.queryBySql(sql)