-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathne.py
43 lines (36 loc) · 1.25 KB
/
ne.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
42
43
import dateutil.parser
import requests
import logging
import lxml.html
from executiveorder import executiveorder
url = "http://govdocs.nebraska.gov/docs/pilot/pubs/EOIndex.html"
page = requests.get(url).content
page = lxml.html.fromstring(page)
page.make_links_absolute(url)
for row in page.xpath("//table[contains(@class,'MsoNormalTable')]/tr")[1:]:
identifier = ""
if row.xpath("td[1]/a"):
identifier = row.xpath("td[1]/a")[0].text_content()
if not row.xpath("td[2]//a[1]"):
title = row.xpath("td[2]")[0].text_content()
logging.warning(f"No PDF file for {title}, skipping")
continue
pdf_url = row.xpath("td[2]//a[1]/@href")[0]
title = row.xpath("td[2]//a[1]")[0].text_content()
pubdate = row.xpath("td[3]")[0].text_content().strip()
try:
pubdate = dateutil.parser.parse(pubdate)
except dateutil.parser._parser.ParserError:
logging.warning(f"Unable to parse date {pubdate}, for {title} skipping")
continue
eo = executiveorder.executiveorder(
abbr="ne",
identifier=identifier,
ocd_id="ocd-division/country:us/state:ne",
pdf_url=pdf_url,
published=pubdate,
source_url=url,
title=title,
)
logging.info(eo)
eo.save()