Skip to content

Commit

Permalink
Merge pull request #18 from pitthsls/sushiclient
Browse files Browse the repository at this point in the history
use single branch; having sushiclient branch is becoming annoying.
  • Loading branch information
Wooble committed Nov 23, 2015
2 parents dc02cb1 + 9b32e54 commit 0e541f3
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 23 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ python:

install:
- pip install .
- pip install git+https://github.com/PyCQA/pep8.git
- pip install httmock
- pip install coveralls
- pip install flake8
Expand Down
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,7 @@ Fetching SUSHI data::
Sqornshellous Swamptalk
Acta Mattressica

Output of report as TSV (currently only supports JR1)::

>>> report.write_tsv("/tmp/counterreport.tsv")

7 changes: 4 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
import sys
import os

# noinspection PyProtectedMember
from pycounter.version import __version__

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.abspath('../../pycounter'))
sys.path.append(os.path.join(os.path.dirname(__file__), '../..'))
print(sys.path)
# noinspection PyProtectedMember
from pycounter.version import __version__

# -- General configuration ------------------------------------------------

Expand Down
36 changes: 19 additions & 17 deletions pycounter/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,12 @@ def __iter__(self):
for item in self._full_data:
yield (item[0], self.metric, item[1])
else:
currmonth = self.period[0]
mondat = iter(self._monthdata)
while currmonth < self.period[1]:
currusage = next(mondat)
yield (currmonth, self.metric, currusage)
currmonth = next_month(currmonth)
current_month = self.period[0]
month_data_iter = iter(self._monthdata)
while current_month < self.period[1]:
current_usage = next(month_data_iter)
yield (current_month, self.metric, current_usage)
current_month = next_month(current_month)


class CounterJournal(CounterEresource):
Expand Down Expand Up @@ -391,6 +391,8 @@ def __init__(self, line=None, period=None, metric=None, month_data=None,
def format_stat(stat):
"""Turn string numbers that might have an embedded comma into
integers
:param stat: numeric value, possibly with commas, to turn into int
"""
stat = stat.replace(',', '')
try:
Expand Down Expand Up @@ -419,12 +421,12 @@ def parse(filename, filetype=None):
elif filename.endswith('.csv'):
filetype = 'csv'
else:
with open(filename, 'rb') as fobj:
firstbytes = fobj.read(2)
if firstbytes == b"PK":
with open(filename, 'rb') as file_obj:
first_bytes = file_obj.read(2)
if first_bytes == b"PK":
filetype = 'xlsx'
else:
content = fobj.read()
content = file_obj.read()
if b'\t' in content:
filetype = 'tsv'
else:
Expand All @@ -449,8 +451,8 @@ def parse_xlsx(filename):
"""
from openpyxl import load_workbook
with open(filename, 'rb') as xlsxfile:
workbook = load_workbook(xlsxfile)
with open(filename, 'rb') as xlsx_file:
workbook = load_workbook(xlsx_file)
worksheet = workbook.get_sheet_by_name(workbook.get_sheet_names()[0])
row_it = worksheet.iter_rows()
split_row_list = ([cell.value if cell.value is not None else ""
Expand Down Expand Up @@ -562,12 +564,12 @@ def parse_generic(report_reader):
continue
if report.report_version == 4:
if report.report_type.startswith('JR1'):
oldline = line
old_line = line
line = line[0:3] + line[5:7] + line[10:last_col]
doi = oldline[3]
prop_id = oldline[4]
html_total = int(oldline[8])
pdf_total = int(oldline[9])
doi = old_line[3]
prop_id = old_line[4]
html_total = int(old_line[8])
pdf_total = int(old_line[9])

elif report.report_type in ('BR1', 'BR2'):
line = line[0:3] + line[5:7] + line[8:last_col]
Expand Down
6 changes: 6 additions & 0 deletions pycounter/sushiclient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""command line client to fetch statistics via SUSHI"""
from __future__ import print_function


def main():
print("pycounter SUSHI client.")
3 changes: 2 additions & 1 deletion pycounter/version.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
__version__ = "0.9.dev1"
"""version information"""
__version__ = "0.9.dev2"
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
],
install_requires=['pyisbn', 'openpyxl<2.3', 'lxml', 'requests',
install_requires=['pyisbn', 'openpyxl<2.3', 'lxml<=3.4.4', 'requests',
'six', 'arrow'],
tests_require=['httmock', 'mock'],
entry_points={
'console_scripts': ['sushiclient = pycounter.sushiclient:main']
}
)

0 comments on commit 0e541f3

Please sign in to comment.