This Python script allows users to input an iOS app name and retrieves its overall rating and total number of ratings from the iTunes Search API. It also displays the current date and time when the data was checked, providing a simple way to monitor app performance on the App Store.
Click to view script…
import requests
from datetime import datetime
# Get the app name from the user
app_name = input("Enter the app name: ")
# Base URL for the iTunes Search API
base_url = "https://itunes.apple.com/search"
# Parameters for the API request
params = {
"term": app_name,
"country": "us",
"media": "software"
}
try:
# Send GET request to the API
response = requests.get(base_url, params=params)
response.raise_for_status() # Raise an exception for HTTP errors
# Parse the JSON response
data = response.json()
# Check if any apps were found
if data["resultCount"] > 0:
# Extract the first app's data
app = data["results"][0]
rating = app.get("averageUserRating", "N/A")
if rating != "N/A":
rating = f"{rating:.1f}" # Format rating to one decimal place
count = app.get("userRatingCount", "N/A")
current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# Print the results
print(f"App Name: {app['trackName']}")
print(f"Overall Rating: {rating}")
print(f"Total Ratings: {count}")
print(f"Date Checked: {current_time}")
else:
print("No apps found with that name.")
except requests.exceptions.RequestException as e:
print(f"Error fetching data: {e}")