Skip to content
Snippets Groups Projects

mkpkglists improvements

Merged Kevin Morris requested to merge kevr/aurweb:teapot into master
All threads resolved!
Compare and Show latest version
1 file
+ 9
15
Compare changes
  • Side-by-side
  • Inline
@@ -4,6 +4,7 @@ import datetime
import gzip
import json
import os
import sys
from collections import defaultdict
from decimal import Decimal
@@ -151,39 +152,32 @@ def main():
output = dict()
with gzip.open(packagesmetafile, "wt") as f:
""" The output "data" json key points to a list of dictionaries,
each representing a single result, filled with column names as
keys and column values as values.
each representing a single result. All items are produced in
the same format that RPC type=search uses.
Example:
{
"data": [
{
"ID": 123,
"Name": "package_name",
"PackageBaseID": 234,
"Version": "0.1.1",
"Description": "Some description...",
"URL": "https://some.url"
},
...
]
"warning": "...",
"data": [{...}, {...}, ...]
}
"""
def is_decimal(column):
""" Check if an SQL column is of decimal.Decimal type. """
if isinstance(column, Decimal):
return float(column)
return column
output = []
for result in cur.fetchall():
extended_fields = get_extended_fields(result[0], result[2])
item = {
column[0]: is_decimal(result[i])
for i, column in enumerate(cur.description)
}
item.update(extended_fields)
if sys.argv[1] == "--extended":
extended_fields = get_extended_fields(result[0], result[2])
item.update(extended_fields)
output.append(item)
json.dump({
Loading