born před 6 roky
rodič
revize
4e75417e6e

+ 34 - 0
collectSports/biz/zqchain.py

@@ -0,0 +1,34 @@
+import biz
+import pycomm
+from models.zqChain import zqChain as zlm
+class zqChain(object):
+    def __init__(self):
+        self.csrc=biz.getCurrentSource()
+        self.zqLeague=zlm()
+    
+    def getOutUid(self,lgid):
+        return self.csrc+str(lgid)
+    def update(self,data):
+        da={}
+        for i in data:
+            da[i]=data[i]
+        uid=self.getOutUid(da['league_id'])
+        hasLeague=self.getLeague(da['league_id'])
+        da['out_uid']=uid
+        da['src']=self.csrc
+        da['out_league_id']=da['league_id']
+        da.pop('league_id')
+        if hasLeague==-1:
+            self.zqLeague.save(da)
+        else:
+            self.zqLeague.update(da," out_uid='%s'" % uid)
+
+
+    def getLeague(self,oleague_id):
+        cond={}
+        cond['where']="out_uid='%s'" %(self.getOutUid(oleague_id))
+        cond['fields']="league_id"
+        data=self.zqLeague.select(cond)
+        if not data:
+            return -1
+        return data

+ 33 - 0
collectSports/biz/zqmatch.py

@@ -0,0 +1,33 @@
+import biz
+import pycomm
+from models.zqMatch import zqMatch as zlm
+class zqMatch(object):
+    def __init__(self):
+        self.csrc=biz.getCurrentSource()
+        self.zqLeague=zlm()
+    
+    def getOutUid(self,lgid):
+        return self.csrc+str(lgid)
+    def update(self,data):
+        da={}
+        for i in data:
+            da[i]=data[i]
+        uid=self.getOutUid(da['league_id'])
+        hasLeague=self.getLeague(da['league_id'])
+        da['out_uid']=uid
+        da['out_league_id']=da['league_id']
+        da.pop('league_id')
+        if hasLeague==-1:
+            self.zqLeague.save(da)
+        else:
+            self.zqLeague.update(da," out_uid='%s'" % uid)
+
+
+    def getLeague(self,oleague_id):
+        cond={}
+        cond['where']="out_uid='%s'" %(self.getOutUid(oleague_id))
+        cond['fields']="league_id"
+        data=self.zqLeague.select(cond)
+        if not data:
+            return -1
+        return data

+ 0 - 0
collectSports/models/__init__.py


+ 62 - 0
collectSports/models/model.py

@@ -0,0 +1,62 @@
+import biz
+class Model(dict):
+    
+    def __init__(self):
+        self.db=biz.getDB()
+        self.cursor=self.db.getCursor()
+        self.conn=self.db.getConn()
+        pass
+        
+    def query(self,sql,args=None):
+        
+        self.cursor.execute(sql,args)
+        res = self.cursor.fetchall()
+        return res
+
+    def execute(self,sql,args=None):
+        try:
+            self.cursor.execute(sql,args)
+            self.conn.commit()
+        except BaseException as e:
+            print(e)
+
+    def select(self,conditions={}):
+        where=fields=limit=orderby=''
+        limit='limit 1 offset 0'
+        if 'where' in conditions:
+            where=' where '+conditions['where']
+        if 'fields' in conditions:
+            fields='  '+conditions['fields']
+        if 'limit' in conditions:
+            limit_d=conditions['limit'].split(',')
+            limit=' limit '+limit_d[0]+ ' offset '+limit_d[1]
+        if 'orderby' in conditions:
+            orderby='  order by '+conditions['orderby']
+        s="select %s from \"%s\" %s %s %s " % (fields,self.table_name,where,orderby,limit)
+        return self.query(s)
+
+    def update(self,data,where=''):
+        values=[]
+        if where!='':
+            where=' where %s' %(where)
+            
+        for index in data:
+            s="%s='%s'" % (index,data[index])
+            values.append(s)
+        sql = "update \"%s\" set %s  %s" % (self.table_name, ','.join(values),where )
+        return self.execute(sql)
+    def save(self,data):
+        fields=[]
+        values=[]
+        vls=''
+        
+        for index in data:
+            fields.append(index)
+            values.append(data[index])
+        if vls=='':
+            vls=''
+        else:
+            vls=vls+','                
+        vls=vls+"('%s')" % '\',\''.join('%s' %id for id in values)
+        sql = "insert into \"%s\"(%s) values %s" % ( self.table_name,','.join(fields),vls)
+        return  self.execute(sql)

+ 6 - 0
collectSports/models/zqChain.py

@@ -0,0 +1,6 @@
+from models.model import *
+class zqChain(Model):
+    table_name = 'zq_chain'
+    
+
+ 

+ 6 - 0
collectSports/models/zqLeague.py

@@ -0,0 +1,6 @@
+from models.model import *
+class zqLeague(Model):
+    table_name = 'zq_league'
+    
+
+ 

+ 4 - 0
collectSports/models/zqLeagueOut.py

@@ -0,0 +1,4 @@
+from models.model import *
+class zqLeagueOut(Model):
+    table_name = 'zq_league_out'
+    

+ 6 - 0
collectSports/models/zqMatch.py

@@ -0,0 +1,6 @@
+from models.model import *
+class zqMatch(Model):
+    table_name = 'zq_match'
+    
+
+ 

+ 20 - 0
collectSports/spiders/demo.py

@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+import scrapy
+from models.zqLeague import *
+
+class DemoSpider(scrapy.Spider):
+    name = 'demo'
+    allowed_domains = ['baidu.com']
+    start_urls = ['http://baidu.com/']
+
+    def start_requests(self):
+        so=zqLeague()
+        # so.select(league_id=3)
+        # so.league_name='china no 1'
+        print(so.update({'league_id':1,'league_name':'ttt'},'league_id=3'))
+        request = scrapy.FormRequest('https://baidu.com', callback=self.parse)
+        yield request
+        
+
+    def parse(self, response):
+        pass