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

# Check for new versions of third-party libraries

from __future__ import print_function
import datetime
import json
import urllib

TAGGED_REPOS = {
    'pybind/pybind11': 'v2.1.1',
    'taocpp/PEGTL': '2.1.4',
    'cxong/tinydir': '1.2.3',
}

NOT_TAGGED_REPOS = {
    'chadaustin/sajson': 'include/sajson.h',
    'sgorsten/linalg': 'linalg.h',
    'nothings/stb': 'stb_sprintf.h',
}

for repo, version in TAGGED_REPOS.items():
    url = 'https://api.github.com/repos/%s/releases/latest' % repo
    response = urllib.urlopen(url)
    data = json.load(response)
    if 'tag_name' in data:
        latest_tag = data['tag_name']
    else:
        url = 'https://api.github.com/repos/%s/tags' % repo
        response = urllib.urlopen(url)
        data = json.load(response)
        latest_tag = data[0]['name']
    mark = ('   !!!' if version != latest_tag else '')
    print('%-18s %10s %10s%s' % (repo, version, latest_tag, mark))

since = datetime.datetime.now() - datetime.timedelta(days=30)
for repo, filename in NOT_TAGGED_REPOS.items():
    url = 'https://api.github.com/repos/%s/commits?path=%s&since=%s' % (
            repo, filename, since)
    response = urllib.urlopen(url)
    data = json.load(response)
    info = '-'
    if data:
        info = data[0]['commit']['committer']['date'][:10]
    print('%-18s  modified: %s' % (repo, info))<commit_msg>upstream-check.py: catch network error<commit_after>#!/usr/bin/env python

# Check for new versions of third-party libraries

from __future__ import print_function
import datetime
import json
import urllib

TAGGED_REPOS = {
    'pybind/pybind11': 'v2.1.1',
    'taocpp/PEGTL': '2.1.4',
    'cxong/tinydir': '1.2.3',
}

NOT_TAGGED_REPOS = {
    'chadaustin/sajson': 'include/sajson.h',
    'sgorsten/linalg': 'linalg.h',
    'nothings/stb': 'stb_sprintf.h',
}

def check_tags():
    for repo, version in TAGGED_REPOS.items():
        url = 'https://api.github.com/repos/%s/releases/latest' % repo
        response = urllib.urlopen(url)
        data = json.load(response)
        if 'tag_name' in data:
            latest_tag = data['tag_name']
        else:
            url = 'https://api.github.com/repos/%s/tags' % repo
            response = urllib.urlopen(url)
            data = json.load(response)
            latest_tag = data[0]['name']
        mark = ('   !!!' if version != latest_tag else '')
        print('%-18s %10s %10s%s' % (repo, version, latest_tag, mark))

def check_recent_commits():
    since = datetime.datetime.now() - datetime.timedelta(days=30)
    for repo, filename in NOT_TAGGED_REPOS.items():
        url = 'https://api.github.com/repos/%s/commits?path=%s&since=%s' % (
                repo, filename, since)
        response = urllib.urlopen(url)
        data = json.load(response)
        info = '-'
        if data:
            info = data[0]['commit']['committer']['date'][:10]
        print('%-18s  modified: %s' % (repo, info))

try:
    check_tags()
    check_recent_commits()
except IOError as e:
    print(e)
{'fraction_non_alphanumeric': 0.16332566546171542, 'fraction_numerical': 0.01643115346697338, 'mean_word_length': 2.8385876418663303, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, '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': '5414085', 'n_tokens_mistral': 1135, 'n_tokens_neox': 1099, 'n_words': 214}