I want to get a list of trending packages but only for actual software excluding dependencies. For that I have to get the list of packages first excluding dependencies

I’m using an arch-based system. And this is what I’ve thought about.

get_packages

#!/usr/bin/env bash

wget https://pkgstats.archlinux.de/api/packages all_packages.txt
# Read the package list
while read package; do
  # Check if the package is a dependency
  if ! pacman -Qi $package | grep -q "Depends On"; then
    # Save actual packages that aren't dependencies
    echo $package
  fi
done < all_packages.txt

I can use it like get_packages > packages.txt

Is there a better way?

I don’t know if pacman knows all about the packages already or it has to make a request to check for each one. And if it does already know about them then I shouldn’t need to download the packages.