<commit_before>#!/usr/bin/env python3
import json, os, sys
import requests
api_url = "https://copr.fedorainfracloud.org/api_2"
api_login = os.environ["copr_login"]
api_token = os.environ["copr_token"]

r = requests.get("%s/projects/%s/chroots" % (api_url, os.environ["copr_projectid"])).json()
chroots = []
for i in r.get("chroots"):
    chroots.append(i.get("chroot").get("name"))

metadata = {
    'chroots': chroots,
    'project_id': int(os.environ["copr_projectid"]),
}
files = {
    "srpm": (os.path.basename(sys.argv[1]), open(sys.argv[1], 'rb'), 'application/x-rpm'),
    "metadata": ('', json.dumps(metadata))
}
r = requests.post("%s/builds" % api_url, auth=(api_login, api_token), files=files)<commit_msg>Improving build script<commit_after>#!/usr/bin/env python3
import json, os, sys
import requests
api_url = "https://copr.fedorainfracloud.org/api_2"
api_login = os.environ["copr_login"]
api_token = os.environ["copr_token"]
project_id = int(os.environ["copr_projectid"])

r = requests.get("%s/projects/%s/chroots" % (api_url, project_id))
if r.status_code != 200:
    print(r.json().get("message", "Error returned, but no message"))
    sys.exit(1)

r = r.json()
chroots = []
for i in r.get("chroots"):
    chroots.append(i.get("chroot").get("name"))

metadata = {
    'chroots': chroots,
    'project_id': project_id),
}
files = {
    "srpm": (os.path.basename(sys.argv[1]), open(sys.argv[1], 'rb'), 'application/x-rpm'),
    "metadata": ('', json.dumps(metadata))
}
r = requests.post("%s/builds" % api_url, auth=(api_login, api_token), files=files)
if r.status_code != 201:
    print(r.json().get("message", "Error returned, but no message"))
    sys.exit(1)
{'fraction_non_alphanumeric': 0.2044231918708906, 'fraction_numerical': 0.009563658099222952, 'mean_word_length': 5.087272727272727, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3983130', 'n_tokens_mistral': 658, 'n_tokens_neox': 642, 'n_words': 111}