-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
42 lines (31 loc) · 979 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import urllib.request
import re
import pandas as pd
import os.path
from datetime import datetime
def get_url(url):
return urllib.request.urlopen(urllib.request.Request(url)).read().decode('utf-8')
# maintain order found, eliminate duplicates
def unique_urls(urls):
result = []
for m in urls:
if m not in result:
result.append(m)
return result
def get_event_urls(html):
p = re.compile('<a href="(http://www\.ufcstats\.com/event-details/\w+)"')
return [m.strip() for m in p.findall(html)]
def get_max_crawled_date():
if os.path.isfile("ufcscrapR-data/fight_list.csv"):
df = pd.read_csv("ufcscrapR-data/fight_list.csv")
df.date = pd.to_datetime(df.date)
return df.date.max()
else:
return datetime.strptime("November 12, 1993", "%B %d, %Y")
def get_max_fight_id():
if os.path.isfile("ufcscrapR-data/fight_list.csv"):
df = pd.read_csv("ufcscrapR-data/fight_list.csv")
df.date = pd.to_datetime(df.date)
return df.fight_id.max()
else:
return 0