Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unique id key #53

Merged
merged 1 commit into from
Apr 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,8 @@ uoftscrapers.Athletics

##### Output format
```js
{
{
"id": String,
"date": String,
"events":[{
"title": String,
Expand Down
13 changes: 10 additions & 3 deletions uoftscrapers/scrapers/athletics/utm.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def scrape(location='.', month=None):
for tr in calendar.find_all('tr', class_='single-day'):
for td in tr.find_all('td'):
date = td.get('data-date')
id_ = UTMAthletics.get_id(date)

if not UTMAthletics.date_in_month(date, month):
continue
Expand Down Expand Up @@ -56,13 +57,14 @@ def scrape(location='.', month=None):
('end_time', end)
]))

athletics[date] = OrderedDict([
athletics[id_] = OrderedDict([
('id', id_),
('date', date),
('events', events)
])

for date, doc in athletics.items():
Scraper.save_json(doc, location, date)
for id_, doc in athletics.items():
Scraper.save_json(doc, location, id_)

Scraper.logger.info('UTMAthletics completed.')

Expand All @@ -71,6 +73,11 @@ def get_month(m):
now = datetime.now()
return '%s-%s' % (now.year, now.month)

@staticmethod
def get_id(d):
day = datetime.strptime(d, '%Y-%m-%d').day
return '%s%s' % (str(day).zfill(2), 'M')

@staticmethod
def date_in_month(d, m):
d = datetime.strptime(d, '%Y-%m-%d')
Expand Down
13 changes: 10 additions & 3 deletions uoftscrapers/scrapers/athletics/utsc.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def scrape(location='.', month=None):
for tr in calendar.find_all('tr', class_='single-day'):
for td in tr.find_all('td'):
date = td.get('data-date')
id_ = UTSCAthletics.get_id(date)

if not UTSCAthletics.date_in_month(date, month):
continue
Expand All @@ -55,13 +56,14 @@ def scrape(location='.', month=None):
('end_time', end)
]))

athletics[date] = OrderedDict([
athletics[id_] = OrderedDict([
('id', id_),
('date', date),
('events', events)
])

for date, doc in athletics.items():
Scraper.save_json(doc, location, date)
for id_, doc in athletics.items():
Scraper.save_json(doc, location, id_)

Scraper.logger.info('UTSCAthletics completed.')

Expand All @@ -70,6 +72,11 @@ def get_month(m):
now = datetime.now()
return '%s-%s' % (now.year, now.month)

@staticmethod
def get_id(d):
day = datetime.strptime(d, '%Y-%m-%d').day
return '%s%s' % (str(day).zfill(2), 'SC')

@staticmethod
def date_in_month(d, m):
d = datetime.strptime(d, '%Y-%m-%d')
Expand Down