model.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import _html
  2. import _bs
  3. import pytz
  4. import datetime
  5. # import time
  6. import psycopg2.extras
  7. """
  8. Modules _html and _bs4 contain specialized methods.
  9. """
  10. local_timezones = {
  11. "NSW": "Australia/Sydney",
  12. "VIC": "Australia/Melbourne",
  13. "QLD": "Australia/Brisbane",
  14. "WA": "Australia/Perth",
  15. "SA": "Australia/Adelaide",
  16. "TAS": "Australia/Hobart",
  17. "ACT": "Australia/Sydney",
  18. "NT": "Australia/Darwin"}
  19. def scrape_main_page():
  20. this_url = """https://racingaustralia.horse/Home.aspx"""
  21. this_data = _html.get_page(this_url)
  22. venues_all = _bs.get_today_row(this_data)
  23. return venues_all
  24. def get_raw_scratchings(this_venue):
  25. this_raw_data = _html.get_page(this_venue.scratchings_url)
  26. return this_raw_data
  27. def process_raw_data(this_raw_data, this_venue):
  28. """
  29. Processes the raw data from the Scratchings page to obtain meta data.
  30. this_venue is passed to _bs.process_scratchings() to create the inherited namedTuple
  31. :param this_raw_data:
  32. :param this_venue:
  33. :return:
  34. """
  35. race_day_info = _bs.get_meta_data(this_raw_data, this_venue)
  36. return race_day_info
  37. def get_scratching_details(this_raw_data, this_venue):
  38. # this_data = _html.get_page(this_venue.scratchings_url)
  39. scratchings_info = _bs.process_scratchings(this_raw_data, this_venue)
  40. return scratchings_info
  41. def convert_to_unixtime(dt_object):
  42. """
  43. Simple utility function that returns the unixtime from a timezone aware dateTime object
  44. :param dt_object:
  45. :return:
  46. """
  47. utc = pytz.UTC
  48. d = dt_object.astimezone(utc)
  49. epoch = datetime.datetime(1970, 1, 1, 0, 0, 0, tzinfo=pytz.UTC)
  50. ts = int((d - epoch).total_seconds())
  51. return ts