diff --git a/lib/DDG/Fathead/DebianPkgs.pm b/lib/DDG/Fathead/DebianPkgs.pm new file mode 100644 index 0000000000..83fd7988bd --- /dev/null +++ b/lib/DDG/Fathead/DebianPkgs.pm @@ -0,0 +1,17 @@ +package DDG::Fathead::DebianPkgs; + +use DDG::Fathead; + +primary_example_queries "debian vim"; +secondary_example_queries + "debian package plink", + "netcat debian pkg"; +description "Debian packages"; +name "DebianPkgs"; +source "Debian.org"; +code_url "https://github.com/duckduckgo/zeroclickinfo-fathead/tree/master/share/debian_pkgs"; +topics "linux", "sysadmin"; +category "software"; + +1; + diff --git a/share/debian_pkgs/fetch.sh b/share/debian_pkgs/fetch.sh new file mode 100644 index 0000000000..a058a95651 --- /dev/null +++ b/share/debian_pkgs/fetch.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +mkdir download +wget https://packages.debian.org/stable/allpackages?format=txt.gz -O download/stable.txt.gz +wget https://packages.debian.org/testing/allpackages?format=txt.gz -O download/testing.txt.gz +wget https://packages.debian.org/unstable/allpackages?format=txt.gz -O download/unstable.txt.gz + +gunzip download/stable.txt.gz +gunzip download/testing.txt.gz +gunzip download/unstable.txt.gz diff --git a/share/debian_pkgs/parse.py b/share/debian_pkgs/parse.py new file mode 100644 index 0000000000..960f58f958 --- /dev/null +++ b/share/debian_pkgs/parse.py @@ -0,0 +1,58 @@ +#!/usr/bin/python3 + +repos = ["stable", "testing", "unstable"] + +lines = {} +names = {} +pkgs = {} + +for repo in repos: + with open("download/%s.txt" % repo) as f: + lines[repo] = f.readlines() + + names[repo] = lines[repo][0].rsplit(" ", 1)[1].strip("\"\n") #the codename of each repo is in the first line + + lines[repo] = lines[repo][6:] #omit the 6 lines of header + + for p in lines[repo]: + (name, ver, desc) = p.split(" ", 2) + + if name not in pkgs.keys(): + pkgs[name] = {} #this dict will hold the package's (ver, desc) from each of the three repos. Some may not exist. + + if repo not in pkgs[name].keys(): + pkgs[name][repo] = {} + + pkgs[name][repo]["ver"] = ver.strip("()") + pkgs[name][repo]["desc"] = desc.strip() + +for (p, q) in pkgs.items(): + desc = None + ver = None + abstract = [] + firstrepo = None #the first repo that contains the package, for generating a link + for repo in repos: + if repo in q.keys(): #11 + abstract.append("%s (%s) %s" % (repo, names[repo], q[repo]["ver"])) + if not desc: #we only need to show one of the descriptions, since they're all very similar. We'll prefer them in the order listed in the repos array + desc = q[repo]["desc"] + if not ver: #same for the screenshot + ver = q[repo]["ver"] + if not firstrepo: + firstrepo = names[repo] + + out = p + "\t" #1 + out += "A\t" #2 + out += "\t" #3 + out += "\t" #4 + out += "\t" #5 + out += "\t" #6 + out += "\t" #7 + out += "\t" #8 + out += "\t" #9 + out += "\t" #10 + out += "[[Image:https://screenshots.debian.net/thumbnail-with-version/%s/%s]]\t" % (p, ver) #11 + out += desc + "

" + "
".join(abstract) #12 + out += "\thttps://packages.debian.org/%s/%s" % (firstrepo, p) #13 + + print(out) diff --git a/share/debian_pkgs/parse.sh b/share/debian_pkgs/parse.sh new file mode 100644 index 0000000000..3c447f0352 --- /dev/null +++ b/share/debian_pkgs/parse.sh @@ -0,0 +1,2 @@ +#!/bin/sh +python3 parse.py > output.txt