Skip to content

Commit

Permalink
Merge pull request #4 from 403JFW/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
LiteSystems committed May 15, 2014
2 parents 78228af + 369b0b6 commit 7e6255e
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 8 deletions.
57 changes: 53 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,55 @@
.DS_Store
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

# C extensions
*.so

# Distribution / packaging
.Python
env/
bin/
build/
develop-eggs/
dist/
eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
*.pyc
.cache
nosetests.xml
coverage.xml

# Translations
*.mo

# Mr Developer
.mr.developer.cfg
.project
.pydevproject

# Rope
.ropeproject

# Django stuff:
*.log
*.pot

# Sphinx documentation
docs/_build/

*.swp
akatsuki.egg-info
dist
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ python:
- "2.7"
- "3.2"
- "3.3"
- "3.4"
- "pypy"
install:
- pip install coveralls
Expand Down
3 changes: 2 additions & 1 deletion akatsuki/bib2html.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@

from akatsuki.exporter import export_html
from akatsuki.parser import load_bibtex_file
from akatsuki.utils import sort_by_date
from akatsuki.utils import pmid_to_url, sort_by_date


def main(bibtex_file, html_file):
"""Load BibTeX file and export to HTML file"""
entries = load_bibtex_file(bibtex_file)
entries = pmid_to_url(entries)
entries = sort_by_date(entries, reverse=True)
export_html(html_file, entries)
2 changes: 2 additions & 0 deletions akatsuki/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,6 @@ def _entry_html(entry):
if 'pages' in entry:
result += ':%s' % entry['pages']
result += '.<br>\n'
if 'URL' in entry:
result += '<a href="{0:s}">{0:s}</a><br>\n'.format(entry['URL'])
return result
11 changes: 11 additions & 0 deletions akatsuki/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
'DEC': 12
}

PUBMED_URL = 'http://www.ncbi.nlm.nih.gov/pubmed/'


def sort_by_date(entries, reverse=False):
"""Sort entries by year and month of the entry"""
Expand All @@ -35,3 +37,12 @@ def sort_by_date(entries, reverse=False):
return sorted(entries,
key=lambda e: int(e['year']) * 100 + int(e['month_n']),
reverse=reverse)


def pmid_to_url(entries):
"""Set URL field from pmid"""
for entry in entries:
pmid = entry['id'].strip()
if (pmid[0:4] == 'pmid') and ('URL' not in entry):
entry['URL'] = PUBMED_URL + pmid[4:]
return entries
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@


setup(name='akatsuki',
version='0.1',
version='0.1.1',
description='BibTeX to HTML converter',
author='Yusuke Miyazaki',
author_email='miyazaki.dev@gmail.com',
url='https://github.com/403JFW/akatsuki',
packages=['akatsuki'],
scripts=['scripts/bib2html'],
test_suite='tests',
install_requires=['bibtexparser>=0.5.2'],
install_requires=['bibtexparser==0.5.2'],
classifiers=[
'Development Status :: 3 - Alpha',
'Environment :: Console',
Expand All @@ -30,6 +30,7 @@
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Utilities'
])
6 changes: 5 additions & 1 deletion tests/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def test_entry_html(self):
'year': '2014',
'id': 'ku2014',
'type': 'article',
'pages': '121--123'}
'pages': '121--123',
'URL': 'http://www.google.com/'}
entry_text = "%s<br>\n" % entry_dict['author']
entry_text += "%s<br>\n" % entry_dict['title']
entry_text += "%s %s %s;%s(%s):%s.<br>\n" % (
Expand All @@ -33,4 +34,7 @@ def test_entry_html(self):
entry_dict['volume'],
entry_dict['number'],
entry_dict['pages'])
if 'URL' in entry_dict:
link_text = '<a href="{0:s}">{0:s}</a><br>\n'
entry_text += link_text.format(entry_dict['URL'])
self.assertEqual(entry_text, exporter._entry_html(entry_dict))
21 changes: 21 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,24 @@ def test_sort_by_date(self):
result = utils.sort_by_date(entries, reverse=True)
for es in zip(result, expected_result):
self.assertEqual(es[0], es[1])

def test_pmid_to_url(self):
# Test data
entry_first = {
'title': 'First',
'id': 'aaa'}
entry_second = {
'title': 'Second',
'id': 'pmid24685317'}
entry_third = {
'title': 'Third',
'id': 'pmid24685317',
'URL': 'http://www.google.com/'}
entries = [entry_first, entry_second, entry_third]

result = utils.pmid_to_url(entries)

self.assertFalse('URL' in result[0])
self.assertEqual(result[1]['URL'],
'http://www.ncbi.nlm.nih.gov/pubmed/24685317')
self.assertEqual(result[2]['URL'], entry_third['URL'])

0 comments on commit 7e6255e

Please sign in to comment.