Advertisement
authorblues

Untitled

Jun 22nd, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.08 KB | None | 0 0
  1. import asyncio
  2. import aiohttp
  3. from collections import namedtuple
  4. import datetime
  5.  
  6. entries = []
  7. url = 'https://gamesdonequick.com/tracker/runs/sgdq2018'
  8. MarathonEntry = namedtuple('MarathonEntry', ('game', 'category', 'runner', 'estimate', 'starttime'))
  9.  
  10. headers = {'User-Agent': '<your user agent here>'}
  11. async with aiohttp.ClientSession(headers=headers) as session:
  12.     async with session.get(url) as req:
  13.         pagehtml = await req.text()
  14.  
  15. entries = []
  16. soup = BeautifulSoup(pagehtml, 'html.parser')
  17. for row in soup.find_all('tr'):
  18.     elts = row.find_all('td')
  19.     if len(elts) != 6: continue
  20.    
  21.     GDQ_TSFORMAT = '%m/%d/%Y %H:%M:%S %z'
  22.     timestamp_s = datetime.datetime.strptime(elts[3].get_text().strip(), GDQ_TSFORMAT)
  23.     timestamp_e = datetime.datetime.strptime(elts[4].get_text().strip(), GDQ_TSFORMAT)
  24.     runner = elts[1].get_text().strip()
  25.     game = elts[0].get_text().strip()
  26.     category = elts[2].get_text().strip()
  27.     estimate = timestamp_e - timestamp_s
  28.    
  29.     entries.append(MarathonEntry(game=game,
  30.             category=category,
  31.             runner=runner,
  32.             estimate=estimate,
  33.             starttime=timestamp_s))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement