Your Name %!s(int64=6) %!d(string=hai) anos
pai
achega
72bc9ba928
Modificáronse 3 ficheiros con 442 adicións e 248 borrados
  1. 54 29
      hg3535/.idea/workspace.xml
  2. 348 179
      hg3535/pipelines.py
  3. 40 40
      hg3535/spiders/zuqiu.py

+ 54 - 29
hg3535/.idea/workspace.xml

@@ -2,10 +2,8 @@
 <project version="4">
   <component name="ChangeListManager">
     <list default="true" id="7fa42e97-ddea-4404-91db-5a9ccc162649" name="Default Changelist" comment="'更新日志按天输出'">
-      <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/pipelines.py" beforeDir="false" afterPath="$PROJECT_DIR$/pipelines.py" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/settings.py" beforeDir="false" afterPath="$PROJECT_DIR$/settings.py" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/spiders/zuqiu.py" beforeDir="false" afterPath="$PROJECT_DIR$/spiders/zuqiu.py" afterDir="false" />
     </list>
     <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
     <option name="SHOW_DIALOG" value="false" />
@@ -47,7 +45,7 @@
         <entry file="file://$PROJECT_DIR$/settings.py">
           <provider selected="true" editor-type-id="text-editor">
             <state relative-caret-position="2754">
-              <caret line="153" column="18" lean-forward="true" selection-start-line="153" selection-start-column="18" selection-end-line="153" selection-end-column="18" />
+              <caret line="153" column="18" selection-start-line="153" selection-start-column="18" selection-end-line="153" selection-end-column="18" />
             </state>
           </provider>
         </entry>
@@ -55,8 +53,8 @@
       <file pinned="false" current-in-tab="true">
         <entry file="file://$PROJECT_DIR$/pipelines.py">
           <provider selected="true" editor-type-id="text-editor">
-            <state relative-caret-position="378">
-              <caret line="27" column="14" lean-forward="true" selection-start-line="27" selection-start-column="14" selection-end-line="27" selection-end-column="14" />
+            <state relative-caret-position="-14605">
+              <caret line="206" column="116" selection-start-line="206" selection-start-column="116" selection-end-line="206" selection-end-column="116" />
               <folding>
                 <element signature="e#0#11#0" expanded="true" />
               </folding>
@@ -64,6 +62,18 @@
           </provider>
         </entry>
       </file>
+      <file pinned="false" current-in-tab="false">
+        <entry file="file://$PROJECT_DIR$/spiders/zuqiu.py">
+          <provider selected="true" editor-type-id="text-editor">
+            <state relative-caret-position="-7675">
+              <caret line="21" selection-start-line="21" selection-end-line="22" selection-end-column="101" />
+              <folding>
+                <element signature="e#24#35#0" expanded="true" />
+              </folding>
+            </state>
+          </provider>
+        </entry>
+      </file>
     </leaf>
   </component>
   <component name="FileTemplateManagerImpl">
@@ -218,6 +228,7 @@
       <foldersAlwaysOnTop value="true" />
     </navigator>
     <panes>
+      <pane id="Scope" />
       <pane id="ProjectPane">
         <subPane>
           <expand>
@@ -225,6 +236,11 @@
               <item name="hg3535" type="b2602c69:ProjectViewProjectNode" />
               <item name="hg3535" type="462c0819:PsiDirectoryNode" />
             </path>
+            <path>
+              <item name="hg3535" type="b2602c69:ProjectViewProjectNode" />
+              <item name="hg3535" type="462c0819:PsiDirectoryNode" />
+              <item name="spiders" type="462c0819:PsiDirectoryNode" />
+            </path>
             <path>
               <item name="hg3535" type="b2602c69:ProjectViewProjectNode" />
               <item name="External Libraries" type="cb654da1:ExternalLibrariesNode" />
@@ -233,7 +249,6 @@
           <select />
         </subPane>
       </pane>
-      <pane id="Scope" />
     </panes>
   </component>
   <component name="PropertiesComponent">
@@ -484,6 +499,7 @@
       <workItem from="1558523229860" duration="749000" />
       <workItem from="1558529201114" duration="63104000" />
       <workItem from="1558918879384" duration="20712000" />
+      <workItem from="1559039245474" duration="293000" />
     </task>
     <task id="LOCAL-00001" summary="修改后,版本二">
       <created>1555727493584</created>
@@ -629,7 +645,7 @@
     <servers />
   </component>
   <component name="TimeTrackingManager">
-    <option name="totallyTimeSpent" value="1559211000" />
+    <option name="totallyTimeSpent" value="1559504000" />
   </component>
   <component name="TodoView">
     <todo-panel id="selected-file">
@@ -642,8 +658,9 @@
   </component>
   <component name="ToolWindowManager">
     <frame x="-8" y="-8" width="1936" height="1066" extended-state="6" />
+    <editor active="true" />
     <layout>
-      <window_info content_ui="combo" id="Project" order="0" sideWeight="0.71173847" visible="true" weight="0.17963752" />
+      <window_info active="true" content_ui="combo" id="Project" order="0" sideWeight="0.71173847" visible="true" weight="0.18123667" />
       <window_info id="Structure" order="1" sideWeight="0.2882615" side_tool="true" weight="0.1108742" />
       <window_info id="Favorites" order="2" sideWeight="0.5013405" side_tool="true" weight="0.108208954" />
       <window_info anchor="bottom" id="Message" order="0" />
@@ -724,6 +741,20 @@
         </entry>
       </map>
     </option>
+    <option name="RECENT_FILTERS">
+      <map>
+        <entry key="Branch">
+          <value>
+            <list />
+          </value>
+        </entry>
+        <entry key="User">
+          <value>
+            <list />
+          </value>
+        </entry>
+      </map>
+    </option>
   </component>
   <component name="VcsManagerConfiguration">
     <MESSAGE value="修改后,版本二" />
@@ -1007,13 +1038,7 @@
         </state>
       </provider>
     </entry>
-    <entry file="file://$PROJECT_DIR$/log/zq_jieshu_2019_5_27.log">
-      <provider selected="true" editor-type-id="text-editor">
-        <state relative-caret-position="-50826">
-          <caret line="4699" selection-start-line="4699" selection-end-line="4699" />
-        </state>
-      </provider>
-    </entry>
+    <entry file="file://$PROJECT_DIR$/log/zq_jieshu_2019_5_27.log" />
     <entry file="file://$PROJECT_DIR$/spiders/roll_zuqiu.py">
       <provider selected="true" editor-type-id="text-editor">
         <state relative-caret-position="18">
@@ -1061,16 +1086,6 @@
         </state>
       </provider>
     </entry>
-    <entry file="file://$PROJECT_DIR$/spiders/zuqiu.py">
-      <provider selected="true" editor-type-id="text-editor">
-        <state relative-caret-position="378">
-          <caret line="21" selection-start-line="21" selection-end-line="22" selection-end-column="101" />
-          <folding>
-            <element signature="e#24#35#0" expanded="true" />
-          </folding>
-        </state>
-      </provider>
-    </entry>
     <entry file="file://$PROJECT_DIR$/middlewares.py">
       <provider selected="true" editor-type-id="text-editor">
         <state relative-caret-position="299">
@@ -1094,14 +1109,24 @@
     <entry file="file://$PROJECT_DIR$/settings.py">
       <provider selected="true" editor-type-id="text-editor">
         <state relative-caret-position="2754">
-          <caret line="153" column="18" lean-forward="true" selection-start-line="153" selection-start-column="18" selection-end-line="153" selection-end-column="18" />
+          <caret line="153" column="18" selection-start-line="153" selection-start-column="18" selection-end-line="153" selection-end-column="18" />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/spiders/zuqiu.py">
+      <provider selected="true" editor-type-id="text-editor">
+        <state relative-caret-position="-7675">
+          <caret line="21" selection-start-line="21" selection-end-line="22" selection-end-column="101" />
+          <folding>
+            <element signature="e#24#35#0" expanded="true" />
+          </folding>
         </state>
       </provider>
     </entry>
     <entry file="file://$PROJECT_DIR$/pipelines.py">
       <provider selected="true" editor-type-id="text-editor">
-        <state relative-caret-position="378">
-          <caret line="27" column="14" lean-forward="true" selection-start-line="27" selection-start-column="14" selection-end-line="27" selection-end-column="14" />
+        <state relative-caret-position="-14605">
+          <caret line="206" column="116" selection-start-line="206" selection-start-column="116" selection-end-line="206" selection-end-column="116" />
           <folding>
             <element signature="e#0#11#0" expanded="true" />
           </folding>

+ 348 - 179
hg3535/pipelines.py

@@ -2,8 +2,10 @@ import json
 import time
 import redis
 import logging
-# import requests
+import requests
+import scrapy
 # from twisted.enterprise import adbapi
+from requests import Request
 from scrapy.conf import settings
 import psycopg2
 import psycopg2.extras
@@ -61,7 +63,7 @@ class Zuqiupipeline(object):
         number = item['number']
         pt = item['pt']
         corner_ball = item['corner_ball']
-        p_code, p_id = get_pcode(corner_ball, 'concede_size')
+        p_code, p_id = get_pcode(corner_ball, 'goal_size')
         # 构建唯一索引
         half_size_guest = item["half_size_guest"]
         half_size_guest_rule = item["half_size_guest_rule"]
@@ -73,7 +75,7 @@ class Zuqiupipeline(object):
                      'source': "hg3535", 'expire_time': expire_time, 'pt': pt}
         # 让球 数据插入数据库
         try:
-            zqone_intodb(data1=half_size_home, data2=size_data, data3="half_size_home", data4=half_size_home_rule,
+            zqone_intodb(data1=half_size_home, data2=size_data, data3="half_goal_size_home", data4=half_size_home_rule,
                          cursor=self.cursor, redis_db=self.redis_db)
         except Exception as e:
             logger.warning('足球half_size_home插入错误')
@@ -81,7 +83,7 @@ class Zuqiupipeline(object):
         #     print(item)
         # # 让球 数据插入数据库
         try:
-            zqone_intodb(data1=half_size_guest, data2=size_data, data3="half_size_guest", data4=half_size_guest_rule,
+            zqone_intodb(data1=half_size_guest, data2=size_data, data3="half_goal_size_guest", data4=half_size_guest_rule,
                          cursor=self.cursor, redis_db=self.redis_db)
         except Exception as e:
             logger.warning('足球half_size_guest插入错误')
@@ -92,17 +94,20 @@ class Zuqiupipeline(object):
         size_home = item["size_home"]
         size_home_rule = item["size_home_rule"]
         try:
-            zqone_intodb(data1=size_guest, data2=size_data, data3="size_guest", data4=size_guest_rule,
+            zqone_intodb(data1=size_guest, data2=size_data, data3="goal_size_guest", data4=size_guest_rule,
                          cursor=self.cursor, redis_db=self.redis_db)
         except Exception as e:
             logger.warning('足球size_guest插入错误')
             logger.warning(e)
         try:
-            zqone_intodb(data1=size_home, data2=size_data, data3="size_home", data4=size_home_rule,
+            zqone_intodb(data1=size_home, data2=size_data, data3="goal_size_home", data4=size_home_rule,
                          cursor=self.cursor, redis_db=self.redis_db)
         except Exception as e:
             logger.warning('足球size_home插入错误')
             logger.warning(e)
+        p_code, p_id = get_pcode(corner_ball, 'concede')
+        concede_data = {'league_id': league_id, 'game_id': competition_id, 'utime': utime, 'p_id': p_id, 'p_code': p_code,
+                     'source': "hg3535", 'expire_time': expire_time, 'pt': pt}
         # 上半场大小
         half_concede_home_rule = item["half_concede_home_rule"]
         half_concede_home = item["half_concede_home"]
@@ -110,13 +115,13 @@ class Zuqiupipeline(object):
         half_concede_guest = item["half_concede_guest"]
         # 上半场让球
         try:
-            zqone_intodb(data1=half_concede_home, data2=size_data, data3="half_concede_home", data4=half_concede_home_rule,
+            zqone_intodb(data1=half_concede_home, data2=concede_data, data3="half_concede_home", data4=half_concede_home_rule,
                          cursor=self.cursor, redis_db=self.redis_db)
         except Exception as e:
             logger.warning('足球half_concede_home插入错误')
             logger.warning(e)
         try:
-            zqone_intodb(data1=half_concede_guest, data2=size_data, data3="half_concede_guest", data4=half_concede_guest_rule, cursor=self.cursor, redis_db=self.redis_db)
+            zqone_intodb(data1=half_concede_guest, data2=concede_data, data3="half_concede_guest", data4=half_concede_guest_rule, cursor=self.cursor, redis_db=self.redis_db)
         except Exception as e:
             logger.warning('足球half_concede_guest插入错误')
             logger.warning(e)
@@ -126,18 +131,18 @@ class Zuqiupipeline(object):
         concede_home_rule = item["concede_home_rule"]
         # 全场让球
         try:
-            zqone_intodb(data1=concede_guest, data2=size_data, data3="concede_guest", data4=concede_guest_rule,
+            zqone_intodb(data1=concede_guest, data2=concede_data, data3="concede_guest", data4=concede_guest_rule,
                          cursor=self.cursor, redis_db=self.redis_db)
         except Exception as e:
             logger.warning('足球concede_guest插入错误')
             logger.warning(e)
         try:
-            zqone_intodb(data1=concede_home, data2=size_data, data3="concede_home", data4=concede_home_rule,
+            zqone_intodb(data1=concede_home, data2=concede_data, data3="concede_home", data4=concede_home_rule,
                          cursor=self.cursor,redis_db=self.redis_db)
         except Exception as e:
             logger.warning('足球concede_home插入错误')
             logger.warning(e)
-        #
+
         p_code, p_id = get_pcode(corner_ball, 'capot')
         # 独赢----------------------------------------------------------------------------------------------------------
         half_capot_home = item["half_capot_home"]
@@ -203,6 +208,30 @@ class Zuqiupipeline(object):
         except Exception as e:
             logger.warning('足球odd_even_odd插入错误')
             logger.warning(e)
+        # url = 'http://sports.5gogo.com/Sports/WriteSports/setSports'
+        # data = {
+        #     "game_code": "zq",
+        #     "title": "odds",
+        #     "data": {
+        #         "match_id": competition_id,
+        #         "lg_id": 1123,
+        #         "odds_code": "concede_guest",
+        #         "status": 0,
+        #         "sort": 0,
+        #         "p_code": "concede_size",
+        #         "odds": 1.2333,
+        #         "condition": "+1.5",
+        #         "odds_only": "b15bad3fc8f09924874fef0e19f63d001",
+        #         "sole": "5e2225944d8cdc44cd7943330986978d2",
+        #         "source": "c22123",
+        #         "type": 0,
+        #         "team": ""
+        #     }
+        # }
+        # data = json.dumps(data)
+        # print(data)
+        # r = requests.post(url, data=data)
+        # print(r.content)
         try:
             zqtwo_intodb(data1=odd_even_even, data2=two_sides_data, data3="two_sides_double", data4='双', cursor=self.cursor,redis_db=self.redis_db)
         except Exception as e:
@@ -314,7 +343,7 @@ class Zuqiupipeline(object):
                     logger.warning('足球first_last_balls插入错误')
                     logger.warning(e)
 
-        p_code, p_id = get_pcode(corner_ball, 'temaball')
+        p_code, p_id = get_pcode(corner_ball, 'team_score')
         full_dicts = item['full_data']
         half_dicts = item['half_data']
         full_dict_rules = item['full_data_rule']
@@ -952,14 +981,6 @@ class Bangqiupipeline(object):
 
 # 足球 篮球 网球 棒球 冠军------------------------------------------------------------------------------------------------
 class Guanjunpipeline(object):
-    def open_spider(self, spider):
-        self.pool = redis.ConnectionPool(host=settings["R_HOST"], port=settings["R_POST"],
-                                         password=settings["R_PASSWORD"])
-        self.redis_db = redis.StrictRedis(connection_pool=self.pool)
-        self.conn = psycopg2.connect(host=settings["POST_HOST"], port=settings['POST_PORT'], user=settings["POST_USER"],
-                                     password=settings["POST_PASSWORD"], database=settings["POST_DATABASE"])
-        self.cursor = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
-
     def process_item(self, item, spider):
         logger = logging.getLogger(__name__)
         data_game = item['data_game'].replace('年', "-").replace('月', "-").replace('日', "")
@@ -989,81 +1010,115 @@ class Guanjunpipeline(object):
         r_hash = hash_func(league_id, new_champion, tema_home, champion_team)
         odds_only = r_hash
         s_hash = hash_func(league_id, league_name, ball, 0)
+        url = 'http://sports.5gogo.com/Sports/WriteSports/setSports'
         if ball == "足球":
+            payload1 = {
+                "game_code": "zq",
+                "title": "league",
+                "data": {
+                    "name_chinese": league_name,
+                    "kind": "1",
+                    "match_mode": "1",
+                    "if_stop": "0",
+                    "belong": " ",
+                    "last_time": "2019-01-01 00:00:00",
+                    "lg_id": league_id,
+                    "source": "hg3535"
+                }
+            }
+            resp = requests.post(url, data={"data": json.dumps(payload1)})
+            print(resp.json())
             n_gameid = int('1' + str(league_id))
-            data_dict = {'league_id': league_id, 'new_champion': new_champion, 'utime': utime,
-                         'champion_team': champion_team, "p_id": 8, 'new_league_name': new_league_name,
-                         'tema_home': tema_home, 'new_hash': new_hash, 'expire_time': expire_time,
-                         "odds_only": odds_only,
-                         "league_name": league_name, 'time3': time3, 'game_id': n_gameid}
-            try:
-                gjz_into(data_dict, self.cursor, r_hash, s_hash, self.redis_db)
-                Competition_sql = "insert into st_zq_competition(home_team, lg_id, match_id, ctime, utime, source, us_time) values (%s, %s, %s, %s, %s, %s, %s) on conflict(match_id) do update set utime=%s;"
-                self.cursor.execute(Competition_sql, (league_name, league_id, n_gameid, utime, utime, 'hg3535', data_game, utime))
-            except Exception as e:
-                logger.warning('足球冠军插入错误')
-                logger.warning(e)
-
-        elif ball == "篮球":
-            n_gameid = int('2' + str(league_id))
-            data_dict = {'league_id': league_id, 'new_champion': new_champion, 'utime': utime,
-                         'champion_team': champion_team, "p_id": 7, 'new_league_name': new_league_name,
-                         'tema_home': tema_home, 'new_hash': new_hash, 'expire_time': expire_time,
-                         "odds_only": odds_only,
-                         "league_name": league_name, 'time3': time3, 'game_id': n_gameid}
-            try:
-                gjl_into(data_dict, self.cursor, r_hash, s_hash, self.redis_db)
-                Competition_sql = "insert into st_lq_competition(home_team, lg_id, match_id, ctime, utime, source, us_time) values (%s, %s, %s, %s, %s, %s, %s) on conflict(match_id) do update set utime=%s;"
-                self.cursor.execute(Competition_sql, (league_name, league_id, n_gameid, utime, utime, 'hg3535', data_game, utime))
-            except Exception as e:
-                logger.warning('篮球冠军插入错误')
-                logger.warning(e)
-
-        elif ball == "网球":
-            n_gameid = int('3' + str(league_id))
-            data_dict = {'league_id': league_id, 'new_champion': new_champion, 'utime': utime,
-                         'champion_team': champion_team, "p_id": 6, 'new_league_name': new_league_name,
-                         'tema_home': tema_home, 'new_hash': new_hash, 'expire_time': expire_time,
-                         "odds_only": odds_only,
-                         "league_name": league_name, 'time3': time3, 'game_id': n_gameid}
-            try:
-                gjw_into(data_dict, self.cursor, r_hash, s_hash, self.redis_db)
-                Competition_sql = "insert into st_wq_competition(home_team, lg_id, match_id, ctime, utime, source, us_time) values (%s, %s, %s, %s, %s, %s, %s) on conflict(match_id) do update set utime=%s;"
-                self.cursor.execute(Competition_sql, (league_name, league_id, n_gameid, utime, utime, 'hg3535', data_game, utime))
-            except Exception as e:
-                logger.warning('网球冠军插入错误')
-                logger.warning(e)
-
-
-        elif ball == "棒球":
-            n_gameid = int('4' + str(league_id))
-            data_dict = {'league_id': league_id, 'new_champion': new_champion, 'utime': utime,
-                         'champion_team': champion_team, "p_id": 5, 'new_league_name': new_league_name,
-                         'tema_home': tema_home, 'new_hash': new_hash, 'expire_time': expire_time,
-                         "odds_only": odds_only,
-                         "league_name": league_name, 'time3': time3, 'game_id': n_gameid}
-            try:
-                gjb_into(data_dict, self.cursor, r_hash, s_hash, self.redis_db)
-                Competition_sql = "insert into st_bq_competition(home_team, lg_id, match_id, ctime, utime, source, us_time) values (%s, %s, %s, %s, %s, %s, %s) on conflict(match_id) do update set utime=%s;"
-                self.cursor.execute(Competition_sql, (league_name, league_id, n_gameid, utime, utime, 'hg3535', data_game, utime))
-            except Exception as e:
-                logger.warning('棒球冠军插入错误')
-                logger.warning(e)
-        return item
-
-    def close_spider(self, spider):
-        self.conn.commit()
-        self.conn.close()
+            payload2 = {
+                "game_code": "zq",
+                "title": "competition",
+                "data": {
+                    "home_team": league_name,
+                    "guest_team": " ",
+                    "lg_id": league_id,
+                    "status": 0,
+                    "match_id": n_gameid,
+                    "match_date": " ",
+                    "match_time": " ",
+                    "tag": " ",
+                    "source": "hg3535",
+                    "is_rollball": 0,
+                    "is_today": 0,
+                    "is_morningplate": 0,
+                    "is_stringscene": 0,
+                    "us_time": data_game
+                    }
+            }
+            resp1 = requests.post(url, data={"data": json.dumps(payload2)})
+            print(resp1.json())
+            return item
+    #         data_dict = {'league_id': league_id, 'new_champion': new_champion, 'utime': utime,
+    #                      'champion_team': champion_team, "p_id": 8, 'new_league_name': new_league_name,
+    #                      'tema_home': tema_home, 'new_hash': new_hash, 'expire_time': expire_time,
+    #                      "odds_only": odds_only,
+    #                      "league_name": league_name, 'time3': time3, 'game_id': n_gameid}
+    #         try:
+    #             gjz_into(data_dict, self.cursor, r_hash, s_hash, self.redis_db)
+    #             Competition_sql = "insert into st_zq_competition(home_team, lg_id, match_id, ctime, utime, source, us_time) values (%s, %s, %s, %s, %s, %s, %s) on conflict(match_id) do update set utime=%s;"
+    #             self.cursor.execute(Competition_sql, (league_name, league_id, n_gameid, utime, utime, 'hg3535', data_game, utime))
+    #         except Exception as e:
+    #             logger.warning('足球冠军插入错误')
+    #             logger.warning(e)
+    #
+    #     elif ball == "篮球":
+    #         n_gameid = int('2' + str(league_id))
+    #         data_dict = {'league_id': league_id, 'new_champion': new_champion, 'utime': utime,
+    #                      'champion_team': champion_team, "p_id": 7, 'new_league_name': new_league_name,
+    #                      'tema_home': tema_home, 'new_hash': new_hash, 'expire_time': expire_time,
+    #                      "odds_only": odds_only,
+    #                      "league_name": league_name, 'time3': time3, 'game_id': n_gameid}
+    #         try:
+    #             gjl_into(data_dict, self.cursor, r_hash, s_hash, self.redis_db)
+    #             Competition_sql = "insert into st_lq_competition(home_team, lg_id, match_id, ctime, utime, source, us_time) values (%s, %s, %s, %s, %s, %s, %s) on conflict(match_id) do update set utime=%s;"
+    #             self.cursor.execute(Competition_sql, (league_name, league_id, n_gameid, utime, utime, 'hg3535', data_game, utime))
+    #         except Exception as e:
+    #             logger.warning('篮球冠军插入错误')
+    #             logger.warning(e)
+    #
+    #     elif ball == "网球":
+    #         n_gameid = int('3' + str(league_id))
+    #         data_dict = {'league_id': league_id, 'new_champion': new_champion, 'utime': utime,
+    #                      'champion_team': champion_team, "p_id": 6, 'new_league_name': new_league_name,
+    #                      'tema_home': tema_home, 'new_hash': new_hash, 'expire_time': expire_time,
+    #                      "odds_only": odds_only,
+    #                      "league_name": league_name, 'time3': time3, 'game_id': n_gameid}
+    #         try:
+    #             gjw_into(data_dict, self.cursor, r_hash, s_hash, self.redis_db)
+    #             Competition_sql = "insert into st_wq_competition(home_team, lg_id, match_id, ctime, utime, source, us_time) values (%s, %s, %s, %s, %s, %s, %s) on conflict(match_id) do update set utime=%s;"
+    #             self.cursor.execute(Competition_sql, (league_name, league_id, n_gameid, utime, utime, 'hg3535', data_game, utime))
+    #         except Exception as e:
+    #             logger.warning('网球冠军插入错误')
+    #             logger.warning(e)
+    #
+    #
+    #     elif ball == "棒球":
+    #         n_gameid = int('4' + str(league_id))
+    #         data_dict = {'league_id': league_id, 'new_champion': new_champion, 'utime': utime,
+    #                      'champion_team': champion_team, "p_id": 5, 'new_league_name': new_league_name,
+    #                      'tema_home': tema_home, 'new_hash': new_hash, 'expire_time': expire_time,
+    #                      "odds_only": odds_only,
+    #                      "league_name": league_name, 'time3': time3, 'game_id': n_gameid}
+    #         try:
+    #             gjb_into(data_dict, self.cursor, r_hash, s_hash, self.redis_db)
+    #             Competition_sql = "insert into st_bq_competition(home_team, lg_id, match_id, ctime, utime, source, us_time) values (%s, %s, %s, %s, %s, %s, %s) on conflict(match_id) do update set utime=%s;"
+    #             self.cursor.execute(Competition_sql, (league_name, league_id, n_gameid, utime, utime, 'hg3535', data_game, utime))
+    #         except Exception as e:
+    #             logger.warning('棒球冠军插入错误')
+    #             logger.warning(e)
+    #     return item
+    #
+    # def close_spider(self, spider):
+    #     self.conn.commit()
+    #     self.conn.close()
 
 
 # 足球 篮球 网球 棒球 联赛------------------------------------------------------------------------------------------------
 class Liansaipipeline(object):
-    def open_spider(self, spider):
-        self.pool = redis.ConnectionPool(host=settings["R_HOST"], port=settings["R_POST"], password=settings["R_PASSWORD"])
-        self.redis_db = redis.StrictRedis(connection_pool=self.pool)
-        self.conn = psycopg2.connect(host=settings["POST_HOST"], port=settings['POST_PORT'], user=settings["POST_USER"], password=settings["POST_PASSWORD"], database=settings["POST_DATABASE"])
-        self.cursor = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
-
     def process_item(self, item, spider):
         logger = logging.getLogger(__name__)
         area_id = item["area_id"]
@@ -1071,94 +1126,208 @@ class Liansaipipeline(object):
         st_league = item["st_league"]
         name_chinese = item["name_chinese"]
         ball = item['ball']
-        utime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
+        # utime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
         area_dict = {"南美洲": 3, "北美洲": 4, "欧洲": 5, "大洋洲": 6, "南极洲": 7, "非洲": 1, "世界": 8, "亚洲": 2}
-        redis_data_dict = "hg3535_liansai"
-        r_hash = hash_func(st_league, name_chinese, ball, 0)
-        if self.redis_db.hexists(redis_data_dict, r_hash):
-            pass
-        else:
-            self.redis_db.hset(redis_data_dict, r_hash, 0)
-            if ball == "足球":
-                try:
-                    if area_name in area_dict:
-                        sql1 = "insert into st_zq_league(name_chinese, lg_id, area_id,source,utime) values (%s, %s, %s, %s, %s) on conflict(lg_id) do update set area_id = %s,source=%s;"
-                        self.cursor.execute(sql1, (name_chinese, st_league, area_dict[area_name], "hg3535",utime, area_dict[area_name], "hg3535"))
-                    else:
-                        if area_name == "足球":
-                            sql2 = "insert into st_zq_league(name_chinese, lg_id, country_id,source) values (%s, %s, %s, %s) on conflict(lg_id) do update set source=%s;"
-                            self.cursor.execute(sql2, (name_chinese, st_league, 0, "hg3535", "hg3535"))
-                        else:
-                            sql2 = "insert into st_zq_league(name_chinese, lg_id, country_id,source,utime) values (%s, %s, %s, %s, %s) on conflict(lg_id) do update set country_id = %s,source=%s;"
-                            self.cursor.execute(sql2, (name_chinese, st_league, area_id, "hg3535",utime, area_id, "hg3535"))
-
-                            sql3 = "insert into st_country(country_id, name_chinese, country_area, country_order,recommend_order, update_time,source) values (%s, %s, %s,%s, %s, %s,%s) on conflict(country_id) do update set update_time =%s,source=%s;"
-                            self.cursor.execute(sql3, (area_id, area_name, 0, 0, 0, utime, "hg3535", utime, "hg3535"))
-                except Exception as e:
-                    logger.warning("足球联赛插入错误")
-                    logger.warning(e)
-
-            elif ball == "篮球":
-                try:
-                    if area_name in area_dict:
-                        sql1 = "insert into st_lq_league(name_chinese, lg_id, area_id,source,utime) values (%s, %s, %s,%s,%s) on conflict(lg_id) do update set area_id = %s,source=%s;"
-                        self.cursor.execute(sql1,
-                                       (name_chinese, st_league, area_dict[area_name], "hg3535",utime, area_dict[area_name],"hg3535"))
-                    else:
-                        if area_name == "篮球":
-                            sql2 = "insert into st_lq_league(name_chinese, lg_id, country_id,source) values (%s, %s, %s, %s) on conflict(lg_id) do update set source=%s;"
-                            self.cursor.execute(sql2, (name_chinese, st_league, 0, "hg3535", "hg3535"))
-                        else:
-                            sql2 = "insert into st_lq_league(name_chinese, lg_id, country_id,source,utime) values (%s, %s, %s, %s, %s) on conflict(lg_id) do update set country_id = %s,source=%s;"
-                            self.cursor.execute(sql2, (name_chinese, st_league, area_id, "hg3535",utime, area_id, "hg3535"))
-
-                            sql3 = "insert into st_country(country_id, name_chinese, country_area, country_order,recommend_order, update_time,source) values (%s, %s, %s,%s, %s, %s,%s) on conflict(country_id) do update set update_time =%s,source=%s;"
-                            self.cursor.execute(sql3, (area_id, area_name, 0, 0, 0, utime, "hg3535", utime, "hg3535"))
-                except Exception as e:
-                    logger.warning("篮球联赛插入错误")
-                    logger.warning(e)
-            elif ball == "网球":
-                try:
-                    if area_name in area_dict:
-                        sql1 = "insert into st_wq_league(name_chinese, lg_id, area_id,source,utime) values (%s, %s, %s,%s,%s) on conflict(lg_id) do update set area_id = %s,source=%s;"
-                        self.cursor.execute(sql1, (name_chinese, st_league, area_dict[area_name], "hg3535",utime, area_dict[area_name],"hg3535"))
-                    else:
-                        if area_name == "网球":
-                            sql2 = "insert into st_wq_league(name_chinese, lg_id, country_id,source) values (%s, %s, %s,%s) on conflict(lg_id) do update set source=%s;"
-                            self.cursor.execute(sql2, (name_chinese, st_league, 0, "hg3535", "hg3535"))
-                        else:
-                            sql2 = "insert into st_wq_league(name_chinese, lg_id, country_id,source,utime) values (%s, %s, %s,%s,%s) on conflict(lg_id) do update set country_id = %s,source=%s;"
-                            self.cursor.execute(sql2, (name_chinese, st_league, area_id, "hg3535",utime, area_id, "hg3535"))
-
-                            sql3 = "insert into st_country(country_id, name_chinese, country_area, country_order,recommend_order, update_time,source) values (%s, %s, %s,%s, %s, %s,%s) on conflict(country_id) do update set update_time =%s,source=%s;"
-                            self.cursor.execute(sql3, (area_id, area_name, 0, 0, 0, utime, "hg3535", utime, "hg3535"))
-                except Exception as e:
-                    logger.warning("网球联赛插入错误")
-                    logger.warning(e)
-            elif ball == "棒球":
-                try:
-                    if area_name in area_dict:
-                        sql1 = "insert into st_bq_league(name_chinese, lg_id, area_id,source,utime) values (%s, %s, %s,%s,%s) on conflict(lg_id) do update set area_id = %s,source=%s;"
-                        self.cursor.execute(sql1,(name_chinese, st_league, area_dict[area_name], "hg3535",utime, area_dict[area_name],"hg3535"))
-                    else:
-                        if area_name == "棒球":
-                            sql2 = "insert into st_bq_league(name_chinese, lg_id, country_id,source) values (%s, %s, %s,%s) on conflict(lg_id) do update set source=%s;"
-                            self.cursor.execute(sql2, (name_chinese, st_league, 0, "hg3535", "hg3535"))
-                        else:
-                            sql2 = "insert into st_bq_league(name_chinese, lg_id, country_id,source,utime) values (%s, %s, %s,%s,%s) on conflict(lg_id) do update set country_id = %s,source=%s;"
-                            self.cursor.execute(sql2, (name_chinese, st_league, area_id, "hg3535",utime, area_id, "hg3535"))
-
-                            sql3 = "insert into st_country(country_id, name_chinese, country_area, country_order,recommend_order, update_time,source) values (%s, %s, %s,%s, %s, %s,%s) on conflict(country_id) do update set update_time =%s,source=%s;"
-                            self.cursor.execute(sql3, (area_id, area_name, 0, 0, 0, utime, "hg3535", utime, "hg3535"))
-                except Exception as e:
-                    logger.warning("棒球联赛插入错误")
-                    logger.warning(e)
-            return item
-
-    def close_spider(self, spider):
-        self.conn.commit()
-        self.conn.close()
-
+        # redis_data_dict = "hg3535_liansai"
+        # r_hash = hash_func(st_league, name_chinese, ball, 0)
+        url = 'http://sports.5gogo.com/Sports/WriteSports/setSports'
+        if ball == "足球":
+            if area_name in area_dict:
+                payload = {
+                        "game_code": "zq",
+                        "title": "league",
+                        "data": {
+                            "name_chinese": name_chinese,
+                            "kind": "1",
+                            "match_mode": "1",
+                            "if_stop": "0",
+                            "belong": area_name,
+                            "last_time": "2019-01-01 00:00:00",
+                            "lg_id": st_league,
+                            "source": "hg3535"
+                            }
+                        }
+            else:
+                if area_name == "足球":
+                    payload = {
+                            "game_code": "zq",
+                            "title": "league",
+                            "data": {
+                                "name_chinese": name_chinese,
+                                "kind": "1",
+                                "match_mode": "1",
+                                "if_stop": "0",
+                                "belong": "中国",
+                                "last_time": "2019-01-01 00:00:00",
+                                "lg_id": st_league,
+                                "source": "hg3535"
+                            }
+                    }
+                else:
+                    payload = {
+                            "game_code": "zq",
+                            "title": "league",
+                            "data": {
+                                "name_chinese": name_chinese,
+                                "kind": "1",
+                                "match_mode": "1",
+                                "if_stop": "0",
+                                "belong": 'area_name',
+                                "last_time": "2019-01-01 00:00:00",
+                                "lg_id": st_league,
+                                "source": "hg3535"
+                            }}
+            data = {"data": json.dumps(payload)}
+            resp = requests.post(url, data=data)
+            print(resp.text)
+        elif ball == "篮球":
+            if area_name in area_dict:
+                payload = {
+                    "game_code": "lq",
+                    "title": "league",
+                    "data": {
+                        "name_chinese": name_chinese,
+                        "kind": "1",
+                        "match_mode": "1",
+                        "if_stop": "0",
+                        "belong": area_name,
+                        "last_time": "2019-01-01 00:00:00",
+                        "lg_id": st_league,
+                        "source": "hg3535"
+                    }
+                }
+            else:
+                if area_name == "篮球":
+                    payload = {
+                        "game_code": "lq",
+                        "title": "league",
+                        "data": {
+                            "name_chinese": name_chinese,
+                            "kind": "1",
+                            "match_mode": "1",
+                            "if_stop": "0",
+                            "belong": "中国",
+                            "last_time": "2019-01-01 00:00:00",
+                            "lg_id": st_league,
+                            "source": "hg3535"
+                        }
+                    }
+                else:
+                    payload = {
+                        "game_code": "lq",
+                        "title": "league",
+                        "data": {
+                            "name_chinese": name_chinese,
+                            "kind": "1",
+                            "match_mode": "1",
+                            "if_stop": "0",
+                            "belong": 'area_name',
+                            "last_time": "2019-01-01 00:00:00",
+                            "lg_id": st_league,
+                            "source": "hg3535"
+                        }}
+            data = {"data": json.dumps(payload)}
+            resp = requests.post(url, data=data)
+            print(resp.text)
+        elif ball == "网球":
+            if area_name in area_dict:
+                payload = {
+                    "game_code": "wq",
+                    "title": "league",
+                    "data": {
+                        "name_chinese": name_chinese,
+                        "kind": "1",
+                        "match_mode": "1",
+                        "if_stop": "0",
+                        "belong": area_name,
+                        "last_time": "2019-01-01 00:00:00",
+                        "lg_id": st_league,
+                        "source": "hg3535"
+                    }
+                }
+            else:
+                if area_name == "网球":
+                    payload = {
+                        "game_code": "wq",
+                        "title": "league",
+                        "data": {
+                            "name_chinese": name_chinese,
+                            "kind": "1",
+                            "match_mode": "1",
+                            "if_stop": "0",
+                            "belong": "中国",
+                            "last_time": "2019-01-01 00:00:00",
+                            "lg_id": st_league,
+                            "source": "hg3535"
+                        }
+                    }
+                else:
+                    payload = {
+                        "game_code": "wq",
+                        "title": "league",
+                        "data": {
+                            "name_chinese": name_chinese,
+                            "kind": "1",
+                            "match_mode": "1",
+                            "if_stop": "0",
+                            "belong": 'area_name',
+                            "last_time": "2019-01-01 00:00:00",
+                            "lg_id": st_league,
+                            "source": "hg3535"
+                        }}
+            data = {"data": json.dumps(payload)}
+            resp = requests.post(url, data=data)
+            print(resp.text)
+        elif ball == "棒球":
+            if area_name in area_dict:
+                payload = {
+                    "game_code": "bq",
+                    "title": "league",
+                    "data": {
+                        "name_chinese": name_chinese,
+                        "kind": "1",
+                        "match_mode": "1",
+                        "if_stop": "0",
+                        "belong": area_name,
+                        "last_time": "2019-01-01 00:00:00",
+                        "lg_id": st_league,
+                        "source": "hg3535"
+                    }
+                }
+            else:
+                if area_name == "棒球":
+                    payload = {
+                        "game_code": "bq",
+                        "title": "league",
+                        "data": {
+                            "name_chinese": name_chinese,
+                            "kind": "1",
+                            "match_mode": "1",
+                            "if_stop": "0",
+                            "belong": "中国",
+                            "last_time": "2019-01-01 00:00:00",
+                            "lg_id": st_league,
+                            "source": "hg3535"
+                        }
+                    }
+                else:
+                    payload = {
+                        "game_code": "bq",
+                        "title": "league",
+                        "data": {
+                            "name_chinese": name_chinese,
+                            "kind": "1",
+                            "match_mode": "1",
+                            "if_stop": "0",
+                            "belong": 'area_name',
+                            "last_time": "2019-01-01 00:00:00",
+                            "lg_id": st_league,
+                            "source": "hg3535"
+                        }}
+            data = {"data": json.dumps(payload)}
+            resp = requests.post(url, data=data)
+            print(resp.text)
+        return item
 
 # ---------------------------------------------------------滚球---------------------------------------------------------
 # 滚球足球 插入
@@ -1811,15 +1980,15 @@ class Roll_Banqiupipeline(object):
         # 让球
         concede = {'league_id': league_id, 'game_id': game_id, 'utime': utime, 'p_id': 1, 'p_code': "concede",
                    'source': "hg3535", 'expire_time': expire_time, 'sort': 0}
-        # bqone_intodb(data1=concedes_dict, data2=concede, data3=concedes_dict_rule, cursor=cursor)
+        # bqone_intodb(data1=concedes_dict, data2=concede, data3=concedes_dict_rule, cursor=self.cursor)
         # 总得分:大/小
         total_size = {'league_id': league_id, 'game_id': game_id, 'utime': utime, 'p_id': 2, 'p_code': "total_size",
                    'source': "hg3535", 'expire_time': expire_time, 'sort': 0}
-        # bqone_intodb(data1=total_size_dict, data2=total_size, data3=total_size_dict_rule, cursor=cursor)
+        # bqone_intodb(data1=total_size_dict, data2=total_size, data3=total_size_dict_rule, cursor=self.cursor)
 
         odd_even = {'league_id': league_id, 'game_id': game_id, 'utime': utime, 'p_id': 3, 'p_code': "two_sides",
                    'source': "hg3535", 'expire_time': expire_time, 'sort': 0}
-        # bqone_intodb(data1=odd_evens_dict, data2=odd_even, data3=odd_evens_dict_rule, cursor=cursor)
+        # bqone_intodb(data1=odd_evens_dict, data2=odd_even, data3=odd_evens_dict_rule, cursor=self.cursor)
         # 赛事失效时间
         # n_time = out_time(ctime, 3.5)
         # 插入独赢

+ 40 - 40
hg3535/spiders/zuqiu.py

@@ -391,78 +391,78 @@ class ZuqiuSpider(scrapy.Spider):
                         try:
                             home_data = data['o']['ou']['v']
                             # 球队进球 大条件
-                            full_dict_rule['home_size_big'] = home_data[1]
+                            full_dict_rule['score_home_big'] = home_data[1]
                             # 球队进球小条件
-                            full_dict_rule['home_size_small'] = home_data[3]
+                            full_dict_rule['score_home_small'] = home_data[3]
 
                             if pt is 3:
                                 # 球队进球大赔率
-                                full_dict['home_size_big'] = round(float(home_data[5]) - 1, 2)
+                                full_dict['score_home_big'] = round(float(home_data[5]) - 1, 2)
                                 # 球队进球小赔率
-                                full_dict['home_size_small'] = round(float(home_data[7]) - 1, 2)
+                                full_dict['score_home_small'] = round(float(home_data[7]) - 1, 2)
                             else:
                                 # 球队进球大赔率
-                                full_dict['home_size_big'] = home_data[5]
+                                full_dict['score_home_big'] = home_data[5]
                                 # 球队进球小赔率
-                                full_dict['home_size_small'] = home_data[7]
+                                full_dict['score_home_small'] = home_data[7]
                         except:
-                            full_dict['home_size_small'] = ""
-                            full_dict_rule['home_size_small'] = ""
-                            full_dict['home_size_big'] = ""
-                            full_dict_rule['home_size_big'] = ""
+                            full_dict['score_home_small'] = ""
+                            full_dict_rule['score_home_small'] = ""
+                            full_dict['score_home_big'] = ""
+                            full_dict_rule['score_home_big'] = ""
                         try:
                             half_home_data = data['o']['ou1st']['v']
-                            half_dict_rule['half_home_size_big'] = half_home_data[1]
-                            half_dict_rule['half_home_size_small'] = half_home_data[3]
+                            half_dict_rule['half_score_home_big'] = half_home_data[1]
+                            half_dict_rule['half_score_home_small'] = half_home_data[3]
 
                             if pt is 3:
-                                half_dict['half_home_size_big'] = round(float(half_home_data[5]) - 1, 2)
-                                half_dict['half_home_size_small'] = round(float(half_home_data[7]) - 1, 2)
+                                half_dict['half_score_home_big'] = round(float(half_home_data[5]) - 1, 2)
+                                half_dict['half_score_home_small'] = round(float(half_home_data[7]) - 1, 2)
                             else:
                                 half_home_size_big = half_home_data[5]
-                                half_dict['half_home_size_big'] = half_home_size_big
+                                half_dict['half_score_home_big'] = half_home_size_big
                                 half_home_size_small = half_home_data[7]
-                                half_dict['half_home_size_small'] = half_home_size_small
+                                half_dict['half_score_home_small'] = half_home_size_small
 
                         except:
-                            half_dict_rule['half_home_size_big'] = ""
-                            half_dict['half_home_size_big'] = ""
-                            half_dict_rule['half_home_size_small'] = ""
-                            half_dict['half_home_size_small'] = ""
+                            half_dict_rule['half_score_home_big'] = ""
+                            half_dict['half_score_home_big'] = ""
+                            half_dict_rule['half_score_home_small'] = ""
+                            half_dict['half_score_home_small'] = ""
 
                     if new_data is 13:
                         try:
                             guest_data = data['o']['ou']['v']
-                            full_dict_rule['guest_size_big'] = guest_data[1]
-                            full_dict_rule['guest_size_small'] = guest_data[3]
+                            full_dict_rule['score_guest_big'] = guest_data[1]
+                            full_dict_rule['score_guest_small'] = guest_data[3]
 
                             if pt is 3:
-                                full_dict['guest_size_big'] = round(float(guest_data[5]) - 1, 2)
-                                full_dict['guest_size_small'] = round(float(guest_data[7]) - 1, 2)
+                                full_dict['score_guest_big'] = round(float(guest_data[5]) - 1, 2)
+                                full_dict['score_guest_small'] = round(float(guest_data[7]) - 1, 2)
                             else:
-                                full_dict['guest_size_big'] = guest_data[5]
-                                full_dict['guest_size_small'] = guest_data[7]
+                                full_dict['score_guest_big'] = guest_data[5]
+                                full_dict['score_guest_small'] = guest_data[7]
                         except:
-                            full_dict_rule['guest_size_big'] = ""
-                            full_dict['guest_size_big'] = ""
-                            full_dict_rule['guest_size_small'] = ""
-                            full_dict['guest_size_small'] = ''
+                            full_dict_rule['score_guest_big'] = ""
+                            full_dict['score_guest_big'] = ""
+                            full_dict_rule['score_guest_small'] = ""
+                            full_dict['score_guest_small'] = ''
                         try:
                             half_guest_data = data['o']['ou1st']['v']
-                            half_dict_rule['half_guest_size_big'] = half_guest_data[1]
-                            half_dict_rule['half_guest_size_small'] = half_guest_data[3]
+                            half_dict_rule['half_score_guest_big'] = half_guest_data[1]
+                            half_dict_rule['half_score_guest_small'] = half_guest_data[3]
                             if pt is 3:
-                                half_dict['half_guest_size_big'] = round(float(half_guest_data[5]) - 1, 2)
-                                half_dict['half_guest_size_small'] = round(float(half_guest_data[7]) - 1, 2)
+                                half_dict['half_score_guest_big'] = round(float(half_guest_data[5]) - 1, 2)
+                                half_dict['half_score_guest_small'] = round(float(half_guest_data[7]) - 1, 2)
                             else:
-                                half_dict['half_guest_size_big'] = half_guest_data[5]
-                                half_dict['half_guest_size_small'] = half_guest_data[7]
+                                half_dict['half_score_guest_big'] = half_guest_data[5]
+                                half_dict['half_score_guest_small'] = half_guest_data[7]
                         except:
-                            half_dict_rule['half_guest_size_big'] = ""
-                            half_dict['half_guest_size_big'] = ""
+                            half_dict_rule['half_score_guest_big'] = ""
+                            half_dict['half_score_guest_big'] = ""
 
-                            half_dict_rule['half_guest_size_small'] = ""
-                            half_dict['half_guest_size_small'] = ""
+                            half_dict_rule['half_score_guest_small'] = ""
+                            half_dict['half_score_guest_small'] = ""
 
                 item['league_id'] = league_id
                 item['league_name'] = league_name