Skip to content

Commit

Permalink
fixed formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
tholzheim committed May 17, 2024
1 parent 1a270db commit d0b0752
Show file tree
Hide file tree
Showing 24 changed files with 168 additions and 187 deletions.
77 changes: 39 additions & 38 deletions ceurws/ceur_ws.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

import calendar
import datetime
import re
from pathlib import Path
from typing import Optional, Union
from typing import Optional
from urllib.request import Request, urlopen

import dateutil.parser
Expand Down Expand Up @@ -39,31 +40,31 @@ class Volume(JSONAble):

def __init__(
self,
number: Optional[int] = None,
url: Optional[str] = None,
title: Optional[str] = None,
fullTitle: Optional[str] = None,
acronym: Optional[str] = None,
lang: Optional[str] = None,
location: Optional[str] = None,
country: Optional[str] = None,
countryWikidataId: Optional[str] = None,
region: Optional[str] = None,
city: Optional[str] = None,
cityWikidataId: Optional[str] = None,
ordinal: Optional[int] = None,
date: Optional[datetime.datetime] = None,
dateFrom: Optional[datetime.datetime] = None,
dateTo: Optional[datetime.datetime] = None,
pubYear: Optional[str] = None,
pubDate: Optional[datetime.datetime] = None,
submitDate: Optional[datetime.datetime] = None,
number: int | None = None,
url: str | None = None,
title: str | None = None,
fullTitle: str | None = None,
acronym: str | None = None,
lang: str | None = None,
location: str | None = None,
country: str | None = None,
countryWikidataId: str | None = None,
region: str | None = None,
city: str | None = None,
cityWikidataId: str | None = None,
ordinal: int | None = None,
date: datetime.datetime | None = None,
dateFrom: datetime.datetime | None = None,
dateTo: datetime.datetime | None = None,
pubYear: str | None = None,
pubDate: datetime.datetime | None = None,
submitDate: datetime.datetime | None = None,
valid: bool = True,
conference: Optional["Conference"] = None,
editors: Optional[list["Editor"]] = None,
sessions: Optional[list["Session"]] = None,
editors: list["Editor"] | None = None,
sessions: list["Session"] | None = None,
virtualEvent: bool = False,
submittedBy: Optional[str] = None,
submittedBy: str | None = None,
):
"""
constructor
Expand Down Expand Up @@ -130,7 +131,7 @@ def getVolumeNumber(self):
number = getattr(self, "number", "Volume has no number")
return number

def getVolumeUrl(self) -> Union[str, None]:
def getVolumeUrl(self) -> str | None:
"""
get the url of the volume page
"""
Expand All @@ -142,8 +143,8 @@ def getVolumeUrl(self) -> Union[str, None]:

@staticmethod
def getVolumeUrlOf(
number: Union[str, int],
) -> Union[str, None]:
number: str | int,
) -> str | None:
"""
get the volume url of the given volume number
Args:
Expand All @@ -167,7 +168,7 @@ def normalize(self):
"""
pass

def get_loctime(self) -> Optional[str]:
def get_loctime(self) -> str | None:
"""
get the loctime
"""
Expand Down Expand Up @@ -244,7 +245,7 @@ def extractAndSetLocation(self, locationStr: str):

def extractDates(
self, dateStr: str, durationThreshold: int = 11
) -> tuple[Optional[datetime.date], Optional[datetime.date]]:
) -> tuple[datetime.date | None, datetime.date | None]:
""" "
Extracts the start and end time from the given string
optimized for the format of the loctime property
Expand Down Expand Up @@ -374,7 +375,7 @@ def papers(self):
"""
return

def extractValuesFromVolumePage(self, timeout: float = 3) -> Union[tuple[Optional[dict], Optional[BeautifulSoup]]]:
def extractValuesFromVolumePage(self, timeout: float = 3) -> tuple[dict | None, BeautifulSoup | None]:
"""
extract values from the given volume page
"""
Expand Down Expand Up @@ -510,7 +511,7 @@ def update_or_recreate(self, parser_config: ParserConfig):
print(f"storing {len(paper_list)} papers")
pm.store(replace=True)

def loadFromIndexHtml(self, parser_config: Optional[ParserConfig] = None, vol_limit: Optional[int] = None):
def loadFromIndexHtml(self, parser_config: ParserConfig | None = None, vol_limit: int | None = None):
"""
load my content from the index.html file
Expand Down Expand Up @@ -553,13 +554,13 @@ class Paper(JSONAble):

def __init__(
self,
id: Optional[str] = None,
title: Optional[str] = None,
type: Optional[str] = None,
position: Optional[int] = None,
pagesFrom: Optional[int] = None,
pagesTo: Optional[int] = None,
authors: Optional[dict] = None,
id: str | None = None,
title: str | None = None,
type: str | None = None,
position: int | None = None,
pagesFrom: int | None = None,
pagesTo: int | None = None,
authors: dict | None = None,
):
super().__init__()
self.id = id
Expand Down Expand Up @@ -658,7 +659,7 @@ class Session(JSONAble):
"""

def __init__(
self, id: Optional[str], title: Optional[str], position: Optional[int], papers: Optional[dict[str, "Paper"]]
self, id: str | None, title: str | None, position: int | None, papers: dict[str, "Paper"] | None
):
"""
constructor
Expand Down
3 changes: 1 addition & 2 deletions ceurws/ceur_ws_web_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import sys
from argparse import ArgumentParser
from dataclasses import asdict
from typing import Optional

from ngwidgets.cmd import WebserverCmd
from tabulate import tabulate
Expand Down Expand Up @@ -148,7 +147,7 @@ def handle_args(self) -> bool:
return handled


def main(argv: Optional[list] = None):
def main(argv: list | None = None):
"""
main call
"""
Expand Down
19 changes: 9 additions & 10 deletions ceurws/dblp.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import time
from dataclasses import dataclass
from itertools import groupby
from typing import Optional, Union
from urllib.error import HTTPError

from lodstorage.cache import CacheManager
Expand Down Expand Up @@ -60,7 +59,7 @@ class DblpAuthors(DblpManager):

def __init__(self, endpoint: "DblpEndpoint"):
super().__init__(endpoint, "dblp/authors", "CEUR-WS Paper Authors")
self.authors: Optional[list[DblpScholar]] = None
self.authors: list[DblpScholar] | None = None

def load(self, force_query: bool = False):
"""
Expand All @@ -82,7 +81,7 @@ class DblpEditors(DblpManager):

def __init__(self, endpoint: "DblpEndpoint"):
super().__init__(endpoint, "dblp/editors", "CEUR-WS all Editors")
self.editors: Optional[list[DblpScholar]] = None
self.editors: list[DblpScholar] | None = None

def load(self, force_query: bool = False):
"""
Expand All @@ -104,7 +103,7 @@ class DblpPapers(DblpManager):

def __init__(self, endpoint: "DblpEndpoint"):
super().__init__(endpoint, "dblp/papers", "CEUR-WS all Papers")
self.papers: Optional[list[DblpPaper]] = None
self.papers: list[DblpPaper] | None = None
self.papers_by_volume: dict[str, dict] = {}
self.papersById: dict[str, DblpPaper] = {}
self.papersByProceeding: dict[str, list[DblpPaper]] = {}
Expand Down Expand Up @@ -324,7 +323,7 @@ def getDblpIdByVolumeNumber(self, number) -> list[str]:
qIds = [record.get("proceeding")[len(self.DBLP_REC_PREFIX) :] for record in qres]
return qIds

def getDblpUrlByDblpId(self, entityId: Optional[str] = None) -> Union[str, None]:
def getDblpUrlByDblpId(self, entityId: str | None = None) -> str | None:
"""
Get the dblp url for given entity id
Args:
Expand All @@ -346,7 +345,7 @@ def getDblpUrlByDblpId(self, entityId: Optional[str] = None) -> Union[str, None]
qId = qIds[0] if qIds is not None and len(qIds) > 0 else None
return qId

def convertEntityIdToUrlId(self, entityId: Optional[str]) -> Union[str, None]:
def convertEntityIdToUrlId(self, entityId: str | None) -> str | None:
"""
Convert the given entityId to the id used in the url
Note: use with care this conversion does not always work
Expand All @@ -361,7 +360,7 @@ def convertEntityIdToUrlId(self, entityId: Optional[str]) -> Union[str, None]:
"""
return self.getDblpUrlByDblpId(entityId)

def toDblpUrl(self, entityId: str, withPostfix: bool = False) -> Union[str, None]:
def toDblpUrl(self, entityId: str, withPostfix: bool = False) -> str | None:
"""
Convert the given id to the corresponding dblp url
Args:
Expand All @@ -380,7 +379,7 @@ def toDblpUrl(self, entityId: str, withPostfix: bool = False) -> Union[str, None
url += postfix
return url

def getEditorsOfVolume(self, number: Union[int, str, None]) -> list[dict]:
def getEditorsOfVolume(self, number: int | str | None) -> list[dict]:
"""
Get the editors for the given volume number
Args:
Expand Down Expand Up @@ -443,7 +442,7 @@ class DblpAuthorIdentifier:

name: str # the name should be usable as SPARQL variable
dblp_property: str
wikidata_property: Optional[str]
wikidata_property: str | None

@classmethod
def all(cls) -> list["DblpAuthorIdentifier"]:
Expand Down Expand Up @@ -500,7 +499,7 @@ def getWikidataIdQueryPart(cls, id_name: str, value: str, var: str):
# unknown identifier
return ""
wd_prop = dblp_author_ids.wikidata_property
values: Union[str, list[str]]
values: str | list[str]
if id_name == "wikidata":
values = value
if isinstance(value, str):
Expand Down
11 changes: 5 additions & 6 deletions ceurws/indexparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import datetime
import html
import re
from typing import Optional

from tqdm import tqdm

Expand All @@ -21,7 +20,7 @@ class ParserConfig:

def __init__(
self,
progress_bar: Optional[tqdm] = None,
progress_bar: tqdm | None = None,
down_to_volume: int = 1,
force_download: bool = False,
verbose: bool = False,
Expand Down Expand Up @@ -52,7 +51,7 @@ class IndexHtmlParser(Textparser):
CEUR-WS Index.html parser
"""

def __init__(self, htmlText: str, config: Optional[ParserConfig] = None):
def __init__(self, htmlText: str, config: ParserConfig | None = None):
"""
Constructor
Expand Down Expand Up @@ -83,7 +82,7 @@ def __init__(self, htmlText: str, config: Optional[ParserConfig] = None):
self.editedByPattern = re.compile("Edited by:")
self.tdBgColorPattern = re.compile("<td bgcolor", re.I)

def find(self, startLine: int, compiledPattern, step: int = 1) -> Optional[int]:
def find(self, startLine: int, compiledPattern, step: int = 1) -> int | None:
"""
find the next line with the given compiled regular expression pattern
Expand All @@ -109,7 +108,7 @@ def findVolume(
startLine: int,
expectedTr: int = 3,
progress: int = 10,
) -> tuple[Optional[int], Optional[int]]:
) -> tuple[int | None, int | None]:
"""
find Volume lines from the given startLine
Expand Down Expand Up @@ -304,7 +303,7 @@ def parseVolume(self, volCount: int, fromLine: int, toLine: int, verbose: bool):
self.log(f"{volumeNumber:4}-{volCount:4}:{fromLine}+{lineCount} {acronym}")
return volume

def parse(self, vol_limit: Optional[int] = None):
def parse(self, vol_limit: int | None = None):
"""
parse my html code for Volume info
"""
Expand Down
3 changes: 1 addition & 2 deletions ceurws/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"""

import sys
from typing import Optional

from geograpy.locator import LocationContext
from geograpy.nominatim import NominatimWrapper
Expand All @@ -16,7 +15,7 @@ class LocationLookup:
Class for location lookup.
"""

predefinedLocations: dict[str, Optional[str]] = {}
predefinedLocations: dict[str, str | None] = {}

@classmethod
def initPredefinedLocations(cls):
Expand Down
3 changes: 1 addition & 2 deletions ceurws/loctime.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import re
from collections import Counter
from pathlib import Path
from typing import Optional

import yaml
from tabulate import tabulate
Expand All @@ -29,7 +28,7 @@ class LoctimeParser:
total_loctimes (int): The total count of processed loctimes.
"""

def __init__(self, filepath: Optional[str] = None):
def __init__(self, filepath: str | None = None):
"""
Initializes the LoctimeParser object, setting up paths, loading lookups,
and initializing counters and patterns.
Expand Down
Loading

0 comments on commit d0b0752

Please sign in to comment.