Преглед изворни кода

Merge branch 'master' of https://git.fop.pe/Foppe/scratchings

Afwas [1337627 пре 6 година
родитељ
комит
3f1ab9f35d
3 измењених фајлова са 13 додато и 5 уклоњено
  1. 6 2
      _bs.py
  2. 5 1
      main.py
  3. 2 2
      model.py

+ 6 - 2
_bs.py

@@ -22,19 +22,23 @@ RaceDay = collections.namedtuple('RaceDay', RaceDayShort._fields + (
 Scratching = collections.namedtuple('Scratching', 'venue date race horse')
 Scratching = collections.namedtuple('Scratching', 'venue date race horse')
 
 
 
 
-def get_today_row(this_text):
+def get_today_row(this_text, this_row):
     """
     """
     Traverses the main table on the front page of https://racingaustralia.horse.
     Traverses the main table on the front page of https://racingaustralia.horse.
     This function scrapes Venue information and race day information.
     This function scrapes Venue information and race day information.
     Unfortunately there is no clever way to split this function into two parts.
     Unfortunately there is no clever way to split this function into two parts.
     :param this_text:
     :param this_text:
+    :param this_row:
     :return RaceDay this_race_day:
     :return RaceDay this_race_day:
     """
     """
     this_soup = BeautifulSoup(this_text, 'html.parser')
     this_soup = BeautifulSoup(this_text, 'html.parser')
     rows = this_soup.select('tr.rows')
     rows = this_soup.select('tr.rows')
     # print('len(rows) {}'.format(len(rows)))
     # print('len(rows) {}'.format(len(rows)))
     all_race_days = []
     all_race_days = []
-    for day in range(len(rows)):
+    days_to_check = [this_row]
+    if this_row == 0:
+        days_to_check = range(len(rows))
+    for day in days_to_check:
         my_row = rows[day]
         my_row = rows[day]
         cells = my_row.select('td')
         cells = my_row.select('td')
         i = 0
         i = 0

+ 5 - 1
main.py

@@ -3,13 +3,17 @@ import model
 from pprint import pprint
 from pprint import pprint
 import time
 import time
 import database
 import database
+import sys
 
 
 if __name__ == '__main__':
 if __name__ == '__main__':
+    row = 0
+    if len(sys.argv) > 1:
+        row = sys.argv[1]
     start = time.time()
     start = time.time()
 
 
     db = database.db
     db = database.db
 
 
-    race_days_global = model.scrape_main_page()
+    race_days_global = model.scrape_main_page(row)
     interim = time.time()
     interim = time.time()
     print('interim 1 {}'.format(interim - start))
     print('interim 1 {}'.format(interim - start))
     # pprint(race_days_global)
     # pprint(race_days_global)

+ 2 - 2
model.py

@@ -21,10 +21,10 @@ local_timezones = {
     "NT": "Australia/Darwin"}
     "NT": "Australia/Darwin"}
 
 
 
 
-def scrape_main_page():
+def scrape_main_page(row):
     this_url = """https://racingaustralia.horse/Home.aspx"""
     this_url = """https://racingaustralia.horse/Home.aspx"""
     this_data = _html.get_page(this_url)
     this_data = _html.get_page(this_url)
-    venues_all = _bs.get_today_row(this_data)
+    venues_all = _bs.get_today_row(this_data, row)
     return venues_all
     return venues_all