-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
portal: add maintenance generate_downloads
- Loading branch information
Showing
3 changed files
with
41 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import os | ||
import json | ||
|
||
from itertools import combinations | ||
from mpcontribs.portal.views import make_download | ||
from mpcontribs.client import Client | ||
|
||
FORMATS = ["json", "csv"] | ||
HEADERS = {"X-Authenticated-Groups": os.environ["ADMIN_GROUP"]} | ||
|
||
|
||
def generate_downloads(): | ||
client = Client(host=os.environ["MPCONTRIBS_API_HOST"], headers=HEADERS) | ||
projects = client.projects.get_entries( | ||
_fields=["name", "stats"] | ||
).result().get("data", []) | ||
skip = {"columns", "contributions"} | ||
print("PROJECTS", len(projects)) | ||
|
||
for project in projects: | ||
name = project["name"] | ||
include = [k for k, v in project["stats"].items() if k not in skip and v] | ||
|
||
for fmt in FORMATS: | ||
query = {"project": name, "format": fmt} | ||
resp = make_download(client, query, []) | ||
print(name, json.loads(resp.content)) | ||
|
||
if include: | ||
for r in range(1, len(include)+1): | ||
for combo in combinations(include, r): | ||
resp = make_download(client, query, combo) | ||
print(name, combo, json.loads(resp.content)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters