Skip to content
This repository has been archived by the owner on Oct 15, 2022. It is now read-only.

Add DebianPkgs module. #84

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions 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;

10 changes: 10 additions & 0 deletions 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
54 changes: 54 additions & 0 deletions share/debian_pkgs/parse.py
@@ -0,0 +1,54 @@
#!/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 = []
for repo in repos:
if repo in q.keys(): #11
abstract.append("%s (%s) %s https://packages.debian.org/%s/%s" % (repo, names[repo], q[repo]["ver"], names[repo], p))
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"]

out = p + "\t" #0
out += "A\t" #1
out += "\t" #2
out += "\t" #3
out += "\t" #4
out += "\t" #5
out += "\t" #6
out += "\t" #7
out += "\t" #8
out += "\t" #9
out += "[[Image:https://screenshots.debian.net/thumbnail-with-version/%s/%s]]\t" % (p, ver) #10
out += desc + "<br>" + "<br>".join(abstract) #11
out += "\t" #12
print(out)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elebow This isn't the correct output file format. I'd point you to the fathead docs but you wrote them 😏
I saw there were a few urls in the abstract text. I'd just pull one out (latest release?) and use that as the more at link.

2 changes: 2 additions & 0 deletions share/debian_pkgs/parse.sh
@@ -0,0 +1,2 @@
#!/bin/sh
python3 parse.py > output.txt