Python Forum

Full Version: Code help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,
I am making a piece of code to describe a job description for my school and I am having a bit of difficulty downloading and opening a PDF file from the internet. I was just wondering whether anyone could help me, please. My code is listed below.
import requests
url = "https://www.jobs.nhs.uk/xi/doc_viewer/?descriptor=IX8ZPiYFSTsbAwZIGhcqbiUrDD0BKgROWkREV3Z4Ynpc"
r = requests.get(url, allow_redirects=True)
def download():
    open('2776245_ESM1_DirectorforInsightsandDataPlatformDelivery.pdf', 'wb').write(r.content)
print("===== List of commands ======\nJob Description\nRequired Qualifications\nSalary\nWorking Hours\nRoles and Responsibilities\nMore Info\nDone\n(Typing 'Done' will result in ending the program. Also note : these commands are case sensitive)")
exitloop = "not done"
while exitloop != "Done":
    command=input("What would you like to know about a Director for Insights and Data Platform Delivery")
    if command == "Job Description":
        print("==Job Decription==\nThe role sits within the Data and Analytics leadership team, reporting to the National Director of Data and Analytics. The role will be responsible for the roll out and delivery of the new NHS Data Platform. This is a large national project to support better decision making through data in NHS England and Improvement, supporting regions and local systems. The post will be a member of the senior data and analytical senior team. The key stakeholders will be NHS England and Improvement teams, regions and other arm’s length bodies.\n\n\n\n\n")
    elif command == "Required Qualifications":
        print("==Required Qualifications==\nEducated to degree level in relevant subject or equivalent level of experience of working at a similar level in specialist area and further training or significant experience in project management, financial management or supporting change management processes.(Both Required)\n\n\n\n\n")
    elif command == "Salary":
        print("==Salary==\nThe estimated salary of a Director for Insights and Data Platform Delivery is between £100,000-£200,000\n\n\n\n\n")
    elif command == "Working Hours":
        print("==Working Hours==\nIt will be a full-time job with 37.5 hours required per week\n\n\n\n\n")
    elif command == "Roles and Responsibilities":
        print("==Roles and Responsibilities==\nResponsible for the delivery of the programme and management of the third parties to ensure delivery against SLAs \n- Responsible for information-related compliance and governance, including cybersecurity, business continuity, identity and access management, information privacy, approvals, controls and risk management \n- Maintains internal information technology systems. \n- Scope the immediate team resource requirements and lead the recruitment and mobilisation of the right information and technology capability \n- Responsible for working with operational teams to design and delivery the operating model for how the data platform fits with other programmes such as UDAL, and how we deliver analytical and improvement products and data for the wider NHS.\n- Agree the transition necessary for the service operations necessary to manage the data assets within the NHSEI teams as a business as usual capability \n- Manage and lead the benefit realisation monitoring from operational adoption of operational products developed on the data platform.\n\n\n\n\n")
    elif command == "More info":
        print("For more information read the following downloaded document")
        download()
    elif command == "Done":
        exitloop = "Done"
    else:
        print("Invalid command. Try again.")
To download and open the pdf

import requests
import subprocess, os, platform

url = "https://www.jobs.nhs.uk/xi/doc_viewer/?descriptor=IX8ZPiYFSTsbAwZIGhcqbiUrDD0BKgROWkREV3Z4Ynpc"
r = requests.get(url, allow_redirects=True)

myfile = "2776245_ESM1_DirectorforInsightsandDataPlatformDelivery.pdf"
with open(myfile, "wb") as f:
    f.write(r.content)

if platform.system() == 'Darwin':       # macOS
    subprocess.call(('open', myfile))
elif platform.system() == 'Windows':    # Windows
    os.startfile(myfile)
else:                                   # Linux
    subprocess.call(('xdg-open', myfile))
Thank you