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

import urllib2
import re

DRYAD_DOI_URL = "http://dx.doi.org/"
DRYAD_VIEWS_PATTERN = re.compile("(?P<views>\d+) views", re.DOTALL)
DRYAD_DOWNLOADS_PATTERN = re.compile("(?P<downloads>\d+) downloads", re.DOTALL)
DRYAD_TITLE_PATTERN = re.compile('please cite the Dryad data package: </p>\n<blockquote>(?P<title>.+?)<span>Dryad Digital Repository. </span>', re.DOTALL)

DRYAD_DOI_PATTERN = re.compile("(10.(\d)+/dryad(\S)+)", re.DOTALL | re.IGNORECASE)

def run_plugin(doi):
    # Right now this is only designed to look up dois
    if not DRYAD_DOI_PATTERN.search(doi):
        return(None)
    page = get_dryad_page(doi)
    if page:
        response = get_stats(page)
    else:
        response = None
    return(response)
    
def get_dryad_page(doi):
    if not doi:
        return(None)
    query_url = DRYAD_DOI_URL + doi
    try:
        page = urllib2.urlopen(query_url).read()
    except urllib2.HTTPError:
        page = None
    return(page)  

def get_stats(page):
    if not page:
        return(None)
        
    view_matches = DRYAD_VIEWS_PATTERN.finditer(page)
    if not view_matches:
        views = None
    try:
        views = sum([int(view_match.group("views")) for view_match in view_matches])
    except ValueError:
        views = None

    download_matches = DRYAD_DOWNLOADS_PATTERN.finditer(page)
    if not download_matches:
        downloads = None
    try:
        downloads = sum([int(download_match.group("downloads")) for download_match in download_matches])
    except ValueError:
        downloads = None

    title_matches = DRYAD_TITLE_PATTERN.search(page)
    if not title_matches:
        title = None
    try:
        title = title_matches.group("title")
    except ValueError:
        title = None
                
    return({"page_views":views, "total_downloads":downloads, "artifact_title":title})  
        

from optparse import OptionParser

def main():
    parser = OptionParser(usage="usage: %prog [options] filename",<commit_msg>remove dryad title for now<commit_after>#!/usr/bin/env python

import urllib2
import re
import string

DRYAD_DOI_URL = "http://dx.doi.org/"
DRYAD_VIEWS_PATTERN = re.compile("(?P<views>\d+) views", re.DOTALL)
DRYAD_DOWNLOADS_PATTERN = re.compile("(?P<downloads>\d+) downloads", re.DOTALL)
DRYAD_TITLE_PATTERN = re.compile('please cite the Dryad data package: </p>\n<blockquote>(?P<title>.+?)<span>Dryad Digital Repository. </span>', re.DOTALL)

DRYAD_DOI_PATTERN = re.compile("(10.(\d)+/dryad(\S)+)", re.DOTALL | re.IGNORECASE)

def run_plugin(doi):
    # Right now this is only designed to look up dois
    if not DRYAD_DOI_PATTERN.search(doi):
        return(None)
    page = get_dryad_page(doi)
    if page:
        response = get_stats(page)
    else:
        response = None
    return(response)
    
def get_dryad_page(doi):
    if not doi:
        return(None)
    query_url = DRYAD_DOI_URL + doi
    try:
        page = urllib2.urlopen(query_url).read()
    except urllib2.HTTPError:
        page = None
    return(page)  

def get_stats(page):
    if not page:
        return(None)
        
    view_matches = DRYAD_VIEWS_PATTERN.finditer(page)
    if not view_matches:
        views = None
    try:
        views = sum([int(view_match.group("views")) for view_match in view_matches])
    except ValueError:
        views = None

    download_matches = DRYAD_DOWNLOADS_PATTERN.finditer(page)
    if not download_matches:
        downloads = None
    try:
        downloads = sum([int(download_match.group("downloads")) for download_match in download_matches])
    except ValueError:
        downloads = None

    title_matches = DRYAD_TITLE_PATTERN.search(page)
    if not title_matches:
        title = None
    try:
        title = string.replace(title_matches.group("title"), ":", "-")
    except ValueError:
        title = None
                
    #return({"page_views":views, "total_downloads":downloads, "artifact_title":title})  
    return({"page_views":views, "total_downloads":downloads})
        

from optparse import OptionParser

def main():
    parser = OptionParser(usage="usage: %prog [options] filename",
{'fraction_non_alphanumeric': 0.11692381870781099, 'fraction_numerical': 0.0024108003857280617, 'mean_word_length': 3.1283582089552238, 'pattern_counts': {'":': 9, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '883818', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1411, 'n_words': 297}