3 # Copyright (C) 2020 kaliko <kaliko@azylum.org>
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, version 3 only.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 from urllib.error import URLError, HTTPError
21 from urllib.request import Request, urlopen
22 from urllib.parse import urlencode
28 https://ftp-team.pages.debian.net/dak/epydoc/dakweb.queries.madison-module.html
30 logger = logging.getLogger(__package__)
34 values = urlencode(data)
35 url = f'https://api.ftp-master.debian.org/madison?{values}'
37 req = Request(url, method='GET')
39 response = urlopen(req)
41 except HTTPError as err:
42 logger.info('The server couldn\'t fulfill the request.')
43 logger.debug('Error code: %s', err.code)
44 except URLError as err:
45 logger.info('We failed to reach a server.')
46 logger.debug('Reason: %s', err.reason)
48 pkg_info = json.loads(ans)
49 except Exception as err:
50 logger.error('Failed to decode json')
53 return pkg_info[0][pkg]
57 if __name__ == '__main__':
61 # vim: ai ts=4 sw=4 sts=4 expandtab fileencoding=utf8