<commit_before>#!/usr/bin/env python
"""
Compute Wikipedia File/Image URL from File/Image name and show HTTP
status. Inspired by AzaToth's "wikimgrab.pl"
<https://commons.wikimedia.org/wiki/User:AzaToth/wikimgrab.pl>
"""

__author__ = "siznax"
__date__ = 2014

import argparse
import hashlib
import re
import requests

API = "http://upload.wikimedia.org/wikipedia"


def url(fname, namespace):
    """
    return Wikimedia File/Image URL from File/Image name
    """
    name = re.sub(r'^(File|Image):', '', fname).replace(' ', '_')
    digest = hashlib.md5(name).hexdigest()
    return "/".join([API, namespace, digest[:1], digest[:2], name])


def main(args):
    img_url = url(args.filename, args.namespace)
    print img_url
    print requests.head(img_url).status_code


if __name__ == "__main__":
    desc = "URL and HTTP status from Wikipedia File/Image name."
    argp = argparse.ArgumentParser(description=desc)
    argp.add_argument("filename")
    argp.add_argument("-ns", "--namespace", default='commons',
                      help="namespace (default=commons)")
    main(argp.parse_args())


# test cases TBD
#<commit_msg>updated pydoc, version. Use https scheme for API.<commit_after>#!/usr/bin/env python
"""
URL and HTTP status from Wikipedia File/Image name.

Inspired by AzaToth's "wikimgrab.pl"
https://commons.wikimedia.org/wiki/User:AzaToth/wikimgrab.pl
"""

__author__ = "@siznax"
__version__ = "15 Sep 2015"

import argparse
import hashlib
import re
import requests

API = "https://upload.wikimedia.org/wikipedia"


def url(fname, namespace):
    """
    return Wikimedia File/Image URL from File/Image name
    """
    name = re.sub(r'^(File|Image):', '', fname).replace(' ', '_')
    digest = hashlib.md5(name).hexdigest()
    return "/".join([API, namespace, digest[:1], digest[:2], name])


def main(args):
    img_url = url(args.filename, args.namespace)
    print img_url
    print requests.head(img_url).status_code


if __name__ == "__main__":
    desc = "URL and HTTP status from Wikipedia File/Image name."
    argp = argparse.ArgumentParser(description=desc)
    argp.add_argument("filename")
    argp.add_argument("-ns", "--namespace", default='commons',
                      help="namespace (default=commons)")
    main(argp.parse_args())


# test cases TBD
#
{'fraction_non_alphanumeric': 0.14758380496299522, 'fraction_numerical': 0.006965607313887679, 'mean_word_length': 3.8378947368421055, 'pattern_counts': {'":': 2, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 3, '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': '5160667', 'n_tokens_mistral': 770, 'n_tokens_neox': 746, 'n_words': 178}