Skip to content

Commit 6eaa2cb

Browse files
committed
Add compatibility with python versions and create tests for it
1 parent 0a63956 commit 6eaa2cb

File tree

4 files changed

+68
-3
lines changed

4 files changed

+68
-3
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
3+
4+
name: Python package
5+
6+
on:
7+
push:
8+
branches: [ "main" ]
9+
pull_request:
10+
branches: [ "main" ]
11+
12+
jobs:
13+
build:
14+
15+
runs-on: ubuntu-latest
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
python-version: ["3.8", "3.9", "3.10", "3.11"]
20+
21+
steps:
22+
- uses: actions/checkout@v4
23+
- name: Set up Python ${{ matrix.python-version }}
24+
uses: actions/setup-python@v3
25+
with:
26+
python-version: ${{ matrix.python-version }}
27+
- name: Install dependencies
28+
run: |
29+
python -m pip install --upgrade pip setuptools wheel
30+
python -m pip install flake8 pytest
31+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
32+
- name: Lint with flake8
33+
run: |
34+
# stop the build if there are Python syntax errors or undefined names
35+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
36+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
37+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
38+
- name: Test with pytest
39+
run: |
40+
PYTHONPATH=. pytest
41+

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
[![Python 3.8](https://img.shields.io/badge/python-3.8-blue.svg)](https://www.python.org/downloads/release/python-360/)
2+
[![Python 3.9](https://img.shields.io/badge/python-3.9-blue.svg)](https://www.python.org/downloads/release/python-360/)
3+
[![Python 3.10](https://img.shields.io/badge/python-3.10-blue.svg)](https://www.python.org/downloads/release/python-360/)
4+
[![Python 3.11](https://img.shields.io/badge/python-3.11-blue.svg)](https://www.python.org/downloads/release/python-360/)
5+
16
arXivCollector
27
======
38

arxivcollector.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ def find_data(self, soup: BeautifulSoup, keyword) -> str:
6868
for p in soup.select('p'):
6969
if p.getText(strip=True).startswith(keyword):
7070
temp = p.getText(strip=True).split(';')
71-
sub = temp[0].strip().removeprefix('Submitted')
72-
ann = temp[-1].strip().removeprefix('originally announced')
71+
sub = temp[0].strip()[len('Submitted'):]
72+
ann = temp[-1].strip()[len('originally announced'):]
7373
# Convert sub to a datetime object
7474
sub = datetime.datetime.strptime(sub, "%d %B, %Y")
7575
break
@@ -88,7 +88,11 @@ def parse_html(self,response:httpx.Response):
8888
temp_authors = li.select('p.authors>a')
8989
authors = ' AND '.join([', '.join(j.getText(strip=True).split()[::-1]) for j in temp_authors])
9090

91-
Abstract = self.extract_text(li,'span.abstract-full').removesuffix('△ Less')
91+
abstract_text = self.extract_text(li, 'span.abstract-full')
92+
if abstract_text:
93+
Abstract = abstract_text[:-len('△ Less')]
94+
else:
95+
Abstract = ''
9296

9397
extracted_text = self.extract_text(li,'p.comments > span:nth-of-type(2)')
9498
note = extracted_text if extracted_text else ""

tests/test_generate_csv.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from pathlib import Path
2+
3+
from example import create
4+
5+
6+
def test_create_csv():
7+
url = 'https://arxiv.org/search/advanced?advanced=&terms-0-operator=AND&terms-0-term=stochastic+parrot&terms-0-field=title&classification-physics_archives=all&classification-include_cross_list=include&date-filter_by=all_dates&date-year=&date-from_date=&date-to_date=&date-date_type=submitted_date&abstracts=show&size=50&order=-announced_date_first'
8+
create(url, "output", "csv")
9+
create(url, "output", "bibtex")
10+
11+
# Check if file exists
12+
filenamecsv = "output.csv"
13+
filenamebib = "output.bib"
14+
assert Path(filenamecsv).exists(), "csv file was not created."
15+
assert Path(filenamebib).exists(), "bibtex file was not created."

0 commit comments

Comments
 (0)