Skip to content

Commit

Permalink
Convert item path from string to Path object
Browse files Browse the repository at this point in the history
  • Loading branch information
campb303 committed Jun 16, 2021
1 parent a32b46e commit 107828a
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/webqueue2api/parser/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from dateutil.parser import parse
from dateutil import tz
from typing import Union
from pathlib import Path
from .config import config


Expand Down Expand Up @@ -39,13 +40,13 @@ class Item:

def __init__(self, queue: str, number: int) -> None:
self.queue = queue

try:
self.number = int(number)
except ValueError:
raise ValueError(" Could not convert \"" +
number + "\" to an integer")
raise ValueError(f"Could not convert {number} to an integer")

self.__path = "/".join([config.queue_directory, self.queue, str(self.number)])
self.__path = Path(config.queue_directory, self.queue, str(self.number))
self.lastUpdated = self.__getLastUpdated()
self.__rawItem = self.__getRawItem()
self.headers = self.__parseHeaders()
Expand All @@ -61,7 +62,7 @@ def __init__(self, queue: str, number: int) -> None:
self.department = self.__getMostRecentHeaderByType("Department")
self.building = self.__getMostRecentHeaderByType("Building")
self.dateReceived = self.__getFormattedDate(
self.__getMostRecentHeaderByType("Date"))
self.__getMostRecentHeaderByType("Date"))

# TODO: Autopopulate jsonData w/ __dir__() command. Exclude `^_` and `jsonData`.
self.jsonData = {
Expand Down Expand Up @@ -995,7 +996,7 @@ def __errorParsing(self, line: str, lineNum: int, expectedSyntax: str) -> dict:
str(datetime.datetime.now()))

# Item filepath
errorDictionary["file_path"] = self.__path
errorDictionary["file_path"] = str(self.__path)

# Expected value
errorDictionary["expected"] = expectedSyntax
Expand Down Expand Up @@ -1060,7 +1061,7 @@ def __isLocked(self) -> Union[str, bool]:
Returns:
Union[str, bool]: String with info about lock if true, bool False if false
"""
lockFile = self.__path + ".lck"
lockFile = str(self.__path) + ".lck"
if os.path.exists(lockFile):
with open(lockFile) as file:
lockInfo = file.readline().split(" ")
Expand Down

0 comments on commit 107828a

Please sign in to comment.