Created
July 6, 2023 17:43
-
-
Save patent-ed/6d1d7a9419cdac0bc1982099fca98249 to your computer and use it in GitHub Desktop.
macos script that collects data from https://jamf-patch.jamfcloud.com/v1/software/ and output to UTF-8 csv and saves to /users shared folder on macOS, named by timestamp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import pandas as pd | |
import os | |
import datetime | |
# Get data from website | |
response = requests.get('https://jamf-patch.jamfcloud.com/v1/software/') | |
data = response.json() | |
# Convert data to pandas DataFrame | |
df = pd.DataFrame(data) | |
# Get timestamp | |
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S") | |
# Get Users Shared directory path | |
shared_dir = os.path.expanduser('/Users/Shared') | |
# Ensure the shared directory exists | |
os.makedirs(shared_dir, exist_ok=True) | |
# Name of the output file | |
file_name = os.path.join(shared_dir, f'output_{timestamp}.csv') | |
# Save DataFrame to CSV file in Users Shared folder | |
df.to_csv(file_name, index=False, encoding='utf-8') | |
print(f"Data saved to {file_name}") |
run in terminal: python3 ./savesoftware.py
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
May need to run : pip install requests pandas
This script will fetch the data from the website, convert it to a DataFrame (a table-like structure provided by pandas), and then save it as a CSV file in the Users Shared folder. The name of the CSV file will include the current timestamp to ensure each run generates a unique file.
Remember to replace the '/Users/Shared' with the absolute path of the Shared directory on your macOS.
Please note that Python might not be preinstalled in all macOS systems, or the installed version might be different from what this script expects. You may need to install an appropriate version of Python and pip (the Python package installer) to be able to run this script.
Remember that you should always be careful when running scripts that you got from the internet, and ensure that you understand what they do before you run them. This script is safe as it stands, but modifying it could potentially lead to unexpected consequences if you're not familiar with what the code is doing.