<commit_before>#!/usr/bin/env python3

import requests
import json
import base64
import os
import datetime
import logging

_moduleLogger = logging.getLogger(__name__)

def _create_header(token):
    return {'Authorization': 'token %s' % token.strip()}


def _read_picture(file_name):
    with open(file_name, 'rb') as text:
        return base64.b64encode(text.read()).decode()


def _post_file(file_data, folder, file_name, header):
    # put encoded data into json request
    new_file_data = json.dumps({"message": "commit message", "content":file_data})

    # post a picture to a repo
    url = 'https://api.github.com/repos/theSloopJohnB/thesloopjohnb/contents/%s/%s' % (folder, file_name)
    
    r=requests.post(url, data=new_file_data, headers=header)
    if (r.ok):
        _moduleLogger.info('Response code: %s', r.status_code)
    else:
        _moduleLogger.error('Bad response code: %s', r.status_code)
        _moduleLogger.error('Bad response text: %s', r.text)
    return r.json()['content']['download_url']


# post a comment on an issue
def _post_comment_to_pr(urlPicPairs, pullRequestInfo, prNumber, header):
    formatString = "### %s: ![capture](%s)\n\n"
    body = """Bleep bloop!

LabVIEW Diff Robot here with some diffs served up hot for your pull request.

Notice something funny? Help fix me on [my GitHub repo.](https://github.com/LabVIEW-DCAF/buildsystem)
<commit_msg>should be put not post<commit_after>#!/usr/bin/env python3

import requests
import json
import base64
import os
import datetime
import logging

_moduleLogger = logging.getLogger(__name__)

def _create_header(token):
    return {'Authorization': 'token %s' % token.strip()}


def _read_picture(file_name):
    with open(file_name, 'rb') as text:
        return base64.b64encode(text.read()).decode()


def _post_file(file_data, folder, file_name, header):
    # put encoded data into json request
    new_file_data = json.dumps({"message": "commit message", "content":file_data})

    # post a picture to a repo
    url = 'https://api.github.com/repos/theSloopJohnB/thesloopjohnb/contents/%s/%s' % (folder, file_name)
    
    r=requests.put(url, data=new_file_data, headers=header)
    if (r.ok):
        _moduleLogger.info('Response code: %s', r.status_code)
    else:
        _moduleLogger.error('Bad response code: %s', r.status_code)
        _moduleLogger.error('Bad response text: %s', r.text)
    return r.json()['content']['download_url']


# post a comment on an issue
def _post_comment_to_pr(urlPicPairs, pullRequestInfo, prNumber, header):
    formatString = "### %s: ![capture](%s)\n\n"
    body = """Bleep bloop!

LabVIEW Diff Robot here with some diffs served up hot for your pull request.

Notice something funny? Help fix me on [my GitHub repo.](https://github.com/LabVIEW-DCAF/buildsystem)

{'fraction_non_alphanumeric': 0.1291012838801712, 'fraction_numerical': 0.004992867332382311, 'mean_word_length': 4.204081632653061, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3186682', 'n_tokens_mistral': 941, 'n_tokens_neox': 910, 'n_words': 246}