move some goal parsing code into sharable module
The code for extracting data from a goal document can be reused. Change-Id: I128e8bd1395713f1daa233751a25487cc0fff153 Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
parent
3c6601d1f2
commit
78ce365758
38
goal_tools/goals.py
Normal file
38
goal_tools/goals.py
Normal file
@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import bs4 as beautifulsoup
|
||||
import requests
|
||||
|
||||
_SITE_TITLE = '— OpenStack Technical Committee Governance Documents'
|
||||
|
||||
|
||||
def _parse_goal_page(html):
|
||||
data = {
|
||||
'title': '',
|
||||
'description': '',
|
||||
}
|
||||
bs = beautifulsoup.BeautifulSoup(html, 'html.parser')
|
||||
data['title'] = bs.title.string or ''
|
||||
if data['title'].endswith(_SITE_TITLE):
|
||||
data['title'] = data['title'][:-len(_SITE_TITLE)].strip()
|
||||
data['description'] = bs.p.text or bs.p.string or ''
|
||||
return data
|
||||
|
||||
|
||||
def get_info(url):
|
||||
html = requests.get(url)
|
||||
data = _parse_goal_page(html.text)
|
||||
data['url'] = url
|
||||
return data
|
@ -19,11 +19,11 @@ import os.path
|
||||
import warnings
|
||||
|
||||
import appdirs
|
||||
import bs4 as beautifulsoup
|
||||
import requests
|
||||
import yaml
|
||||
|
||||
from goal_tools import storyboard
|
||||
from goal_tools import goals
|
||||
|
||||
_GOVERNANCE_PROJECT_NAME = 'openstack/governance'
|
||||
_STORY_URL_TEMPLATE = 'https://storyboard.openstack.org/#!/story/{}'
|
||||
@ -57,29 +57,6 @@ def _get_worklist_settings(tag):
|
||||
}
|
||||
|
||||
|
||||
_SITE_TITLE = '— OpenStack Technical Committee Governance Documents'
|
||||
|
||||
|
||||
def _parse_goal_page(html):
|
||||
data = {
|
||||
'title': '',
|
||||
'description': '',
|
||||
}
|
||||
bs = beautifulsoup.BeautifulSoup(html, 'html.parser')
|
||||
data['title'] = bs.title.string or ''
|
||||
if data['title'].endswith(_SITE_TITLE):
|
||||
data['title'] = data['title'][:-len(_SITE_TITLE)].strip()
|
||||
data['description'] = bs.p.text or bs.p.string or ''
|
||||
return data
|
||||
|
||||
|
||||
def _get_goal_info(url):
|
||||
html = requests.get(url)
|
||||
data = _parse_goal_page(html.text)
|
||||
data['url'] = url
|
||||
return data
|
||||
|
||||
|
||||
def _get_project_info(url):
|
||||
response = requests.get(url)
|
||||
data = yaml.safe_load(response.text)
|
||||
@ -187,7 +164,7 @@ def main():
|
||||
|
||||
try:
|
||||
LOG.debug('reading goal info from {}'.format(args.goal_url))
|
||||
goal_info = _get_goal_info(args.goal_url)
|
||||
goal_info = goals.get_info(args.goal_url)
|
||||
except Exception as err:
|
||||
parser.error(err)
|
||||
full_description = (goal_info['description'] +
|
||||
|
Loading…
Reference in New Issue
Block a user