From 6df59b9b7dc60b1fb41694671a04376fa377f9bb Mon Sep 17 00:00:00 2001 From: Dan Howe Date: Fri, 17 Aug 2018 15:10:09 +1000 Subject: [PATCH] Add note when no documents are available on DPE portal --- .../major_projects_grabber.py | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/major_projects_grabber/major_projects_grabber.py b/major_projects_grabber/major_projects_grabber.py index c82a149..1c79a34 100644 --- a/major_projects_grabber/major_projects_grabber.py +++ b/major_projects_grabber/major_projects_grabber.py @@ -46,6 +46,23 @@ def get_documents(mod_id, output_dir): # Get list of document folders folders = mod_tree.xpath('//div[@class="folder_row"]') + + # Create modification folder + mod_dir = os.path.join(output_dir, project_name, mod_name) + os.makedirs(mod_dir, exist_ok=True) + + # Add note if no documents are found on portal + if not folders: + txt_name = 'No documents on DPE portal for this modification.txt' + open(os.path.join(mod_dir,txt_name), 'a').close() + + # Create link to DPE Major Projects page for current modification + text = """ + + """.format(mod_url) + with open(os.path.join(mod_dir, 'DPE-portal-page.html'), 'w') as f: + f.write(text) + for folder in folders: folder_name = folder.xpath('a[2]')[0].text.strip() @@ -122,7 +139,11 @@ def main(): parser.add_argument( '-o', metavar='OUTPUT_DIR', default='.', help='root output directory') parser.add_argument( - '-i', metavar='ID', default=[], help='modification job id(s)', nargs='*') + '-i', + metavar='ID', + default=[], + help='modification job id(s)', + nargs='*') parser.add_argument('-u', metavar='URL', help='url of search results page') # Print usage if no arguments are provided