import sqlite3
import collections # orderedDict
import operator

debianpkgdb = "Debian-stable.db" 
conn = sqlite3.connect(debianpkgdb)
c = conn.cursor()

c.execute(''' SELECT name, version, dependency, section FROM packages ''')

pkgDependsFreq = {}

for package in c.fetchall():
    # version and section are queried but not used
    # might be able to tell in the future if current version suitable for other package as dependency
    # section was to see which section in debian packages has the most frequently used package
    (name, version, dependency, section) = package

    if name not in pkgDependsFreq:
        pkgDependsFreq[name] = 0

    # get all alternative packages
    for altpkgname in dependency.split("|"):
        # remove white space
        altpkgname = altpkgname.strip()
        # remove required version or architecure
        altpkgname = altpkgname.split("[")[0].split("(")[0]

        pkgDependsFreq[altpkgname] = pkgDependsFreq.get(altpkgname, 0)+1


# for pkgname, pkgfreq in pkgDependsFreq.items():
#     print("name: ", pkgname, " used: ", pkgfreq)

sorted_x = sorted(pkgDependsFreq.items(), key=operator.itemgetter(1), reverse=True)

print(sorted_x[:10])

conn.close()

0d01b8a945a8849fa85aac3cfaabff499dbc914d
<mask token>

<mask token>
c.execute(' SELECT name, version, dependency, section FROM packages ')
<mask token>
for package in c.fetchall():
    name, version, dependency, section = package
    if name not in pkgDependsFreq:
        pkgDependsFreq[name] = 0
    for altpkgname in dependency.split('|'):
        altpkgname = altpkgname.strip()
        altpkgname = altpkgname.split('[')[0].split('(')[0]
        pkgDependsFreq[altpkgname] = pkgDependsFreq.get(altpkgname, 0) + 1
<mask token>
print(sorted_x[:10])
conn.close()

<mask token>
debianpkgdb = 'Debian-stable.db'
conn = sqlite3.connect(debianpkgdb)
c = conn.cursor()
c.execute(' SELECT name, version, dependency, section FROM packages ')
pkgDependsFreq = {}
for package in c.fetchall():
    name, version, dependency, section = package
    if name not in pkgDependsFreq:
        pkgDependsFreq[name] = 0
    for altpkgname in dependency.split('|'):
        altpkgname = altpkgname.strip()
        altpkgname = altpkgname.split('[')[0].split('(')[0]
        pkgDependsFreq[altpkgname] = pkgDependsFreq.get(altpkgname, 0) + 1
sorted_x = sorted(pkgDependsFreq.items(), key=operator.itemgetter(1),
    reverse=True)
print(sorted_x[:10])
conn.close()

import sqlite3
import collections
import operator
debianpkgdb = 'Debian-stable.db'
conn = sqlite3.connect(debianpkgdb)
c = conn.cursor()
c.execute(' SELECT name, version, dependency, section FROM packages ')
pkgDependsFreq = {}
for package in c.fetchall():
    name, version, dependency, section = package
    if name not in pkgDependsFreq:
        pkgDependsFreq[name] = 0
    for altpkgname in dependency.split('|'):
        altpkgname = altpkgname.strip()
        altpkgname = altpkgname.split('[')[0].split('(')[0]
        pkgDependsFreq[altpkgname] = pkgDependsFreq.get(altpkgname, 0) + 1
sorted_x = sorted(pkgDependsFreq.items(), key=operator.itemgetter(1),
    reverse=True)
print(sorted_x[:10])
conn.close()

import sqlite3
import collections # orderedDict
import operator

debianpkgdb = "Debian-stable.db" 
conn = sqlite3.connect(debianpkgdb)
c = conn.cursor()

c.execute(''' SELECT name, version, dependency, section FROM packages ''')

pkgDependsFreq = {}

for package in c.fetchall():
    # version and section are queried but not used
    # might be able to tell in the future if current version suitable for other package as dependency
    # section was to see which section in debian packages has the most frequently used package
    (name, version, dependency, section) = package

    if name not in pkgDependsFreq:
        pkgDependsFreq[name] = 0

    # get all alternative packages
    for altpkgname in dependency.split("|"):
        # remove white space
        altpkgname = altpkgname.strip()
        # remove required version or architecure
        altpkgname = altpkgname.split("[")[0].split("(")[0]

        pkgDependsFreq[altpkgname] = pkgDependsFreq.get(altpkgname, 0)+1


# for pkgname, pkgfreq in pkgDependsFreq.items():
#     print("name: ", pkgname, " used: ", pkgfreq)

sorted_x = sorted(pkgDependsFreq.items(), key=operator.itemgetter(1), reverse=True)

print(sorted_x[:10])

conn.close()
