<jupyter_start><jupyter_text>robobrowser<jupyter_code>from robobrowser import RoboBrowser

def post_to_yaml_loader(url, unglue_url="https://unglue.it/api/loader/yaml"):
        
    browser = RoboBrowser(history=True)
    browser.open(unglue_url)

    form = browser.get_forms()[0]
    form['repo_url'] = url
    # weird I have to manually set referer
    browser.session.headers['referer'] = unglue_url
    browser.submit_form(form)
    
    return browser
b = post_to_yaml_loader('https://github.com/GITenberg/Adventures-of-Huckleberry-Finn_76/raw/master/metadata.yaml')
(b.url, b.response)<jupyter_output><empty_output><jupyter_text>opds<jupyter_code>from lxml import etree
import requests

opds_url = "https://unglue.it/api/opds/"
doc = etree.fromstring(requests.get(opds_url).content)
doc<jupyter_output><empty_output><jupyter_text>Failed attempt with requests to submit to yaml loader<jupyter_code>import requests

from lxml import etree
from lxml.cssselect import CSSSelector

unglue_url = "https://unglue.it/api/loader/yaml"

r = requests.get(unglue_url)
doc = etree.HTML(r.content)

sel = CSSSelector('input[name="csrfmiddlewaretoken"]')
csrftoken = sel(doc)[0].attrib.get('value')
csrftoken
r = requests.post(unglue_url, 
                  data={'repo_url':
                          'https://github.com/GITenberg/Adventures-of-Huckleberry-Finn_76/raw/master/metadata.yaml',
                         'csrfmiddlewaretoken':csrftoken
                         },
                  headers={'referer':unglue_url})
(r.status_code, r.content)<jupyter_output><empty_output><jupyter_text>travis webhooksFor https://travis-ci.org/GITenberg/Adventures-of-Huckleberry-Finn_76/builds/109712115 -- 2 webhooks were sent to :* [Travis webhook 1 for https://travis-ci.org/GITenberg/Adventures-of-Huckleberry-Finn_76/builds/109712115](https://gist.github.com/rdhyee/7f33050732a09dfa93f3)* [second webhook for https://travis-ci.org/GITenberg/Adventures-of-Huckleberry-Finn_76/builds/109712115](https://gist.github.com/rdhyee/8dc04b8fe52a9fefe3c2)<jupyter_code>import requests

raw_url_1 = (
 "https://gist.githubusercontent.com/rdhyee/7f33050732a09dfa93f3/raw/8abf5661911e7aedf434d464dd1a28b3d24d6f83/travis_webhook_1.json"
)

raw_url_2 = (
 "https://gist.githubusercontent.com/rdhyee/8dc04b8fe52a9fefe3c2/raw/8f9968f481df3f4d4ecd44624c2dc1b0a8e02a17/travis_webhook_2.json"
)
r1 = requests.get(raw_url_1).json()
r2 = requests.get(raw_url_2).json()
# url of metadata.yaml to load: 
# https://github.com/GITenberg/Adventures-of-Huckleberry-Finn_76/raw/master/metadata.yaml 
r1.get('commit'), r1.get('repository', {}).get('name')

r1
r1.get('type'), r1['state'], r1['result'], r1.get('status_message')
r2.get('type'), r2['state'], r2['result'], r2.get('status_message')<jupyter_output><empty_output><jupyter_text>travis webhook authenticationI think the documention is incorrect.  Instead of 'username/repository', just use the header `Travis-Repo-Slug`, which, I think, is just the full name of the repo -- e.g., `GITenberg/Adventures-of-Huckleberry-Finn_76`When Travis CI makes the POST request, a header named Authorization is included. Its value is the SHA2 hash of the GitHub username (see below), the name of the repository, and your Travis CI token.For instance, in Python, use this snippet:```Pythonfrom hashlib import sha256sha256('username/repository' + TRAVIS_TOKEN).hexdigest()```Use this to ensure Travis CI is the one making requests to your webhook.How to find `TRAVIS_TOKEN`?  You have to go your profile  (I thought you can use the travis CLI: `travis token` -- but that's for the "access token".  There are 3 different types of tokens in play for travis: [The Travis CI Blog: Token, Token, Token](https://blog.travis-ci.com/2013-01-28-token-token-token/))So I'm waiting for  to load up -- very slow on Chrome but fast on Firefox?<jupyter_code>sent_token = "<PASSWORD>"

from github_settings import TRAVIS_TOKEN, username
from hashlib import sha256


sha256('GITenberg/Adventures-of-Huckleberry-Finn_76' + TRAVIS_TOKEN).hexdigest()<jupyter_output><empty_output><jupyter_text>testing my webhook implementation<jupyter_code>import requests

url = "http://127.0.0.1:8000/api/travisci/webhook"

test_headers_url = \
   "https://gist.githubusercontent.com/rdhyee/a9242f60b568b5a9e8fa/raw/e5d71c9a17964e0d43f6a35bbf03efe3f8a7d752/webhook_headers.txt"

test_body_url = \
  "https://gist.githubusercontent.com/rdhyee/a9242f60b568b5a9e8fa/raw/e5d71c9a17964e0d43f6a35bbf03efe3f8a7d752/webook_body.json"
    
payload = requests.get(test_body_url).content

headers = dict([(k,v.strip()) for (k,v) in [line.split(":") for line in requests.get(test_headers_url).content.split('\n')]])

r = requests.post(url, data={'payload':payload}, headers=headers, allow_redirects=True)

(r.status_code, r.content)
# example of a request to exercise exception

import json
payload = json.dumps({
  "repository":{  
      "id":4651401,
      "name":"Adventures-of-Huckleberry-Finn_76",
      "owner_name":"GITenberg",
      "url":"http://GITenberg.github.com/"
   },
  "status_message": "Passed",
  "type": "push"
})

r = requests.post(url, data={'payload':payload}, headers={}, allow_redirects=True)
(r.status_code, r.content)
r = requests.get(url, allow_redirects=True)
(r.status_code, r.content)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13136072370900867, 'fraction_numerical': 0.05107425555974369, 'mean_word_length': 5.15661252900232, 'pattern_counts': {'":': 8, '<': 26, '<?xml version=': 0, '>': 26, 'https://': 16, 'lorem ipsum': 0, 'www.': 0, 'xml': 3}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '638735', 'license': 'Apache-2.0', 'n_tokens_mistral': 2120, 'n_tokens_neox': 1977, 'n_words': 334, 'path': 'webhooks_for_GITenberg.ipynb', 'repo_name': 'rdhyee/nypl50', 'size': '5360'}