Преглед изворни кода

junk: ignore materials in config

raylu пре 5 дана
родитељ
комит
3bfa524e0c
5 измењених фајлова са 23 додато и 4 уклоњено
  1. 7 0
      config.py
  2. 7 1
      junk.py
  3. 2 2
      market.py
  4. 6 0
      pyproject.toml
  5. 1 1
      supply.py

+ 7 - 0
config.py

@@ -10,6 +10,7 @@ class Config:
 	fio_rest_key: str
 	fio_api_key: str
 	punoted_api_key: str
+	junk: JunkConfig
 	market: MarketConfig
 	supply: dict[str, SupplyConfig]
 
@@ -18,6 +19,8 @@ class Config:
 			config = tomllib.load(f)
 		for k, v in config.items():
 			match k:
+				case 'junk':
+					v = JunkConfig(**v)
 				case 'market':
 					v = MarketConfig(**v)
 				case 'supply':
@@ -30,6 +33,10 @@ class Config:
 		else:
 			return SupplyConfig()
 
+@dataclasses.dataclass(eq=False, frozen=True, slots=True)
+class JunkConfig:
+	ignore_materials: typing.Sequence[str] = dataclasses.field(default_factory=list)
+
 @dataclasses.dataclass(eq=False, frozen=True, slots=True)
 class MarketConfig:
 	mm_items: typing.Mapping[str, int]

+ 7 - 1
junk.py

@@ -20,14 +20,20 @@ def main() -> None:
 	
 	supplies: list[tuple[float, str]] = []
 	for mat, amount in supply.warehouse_inventory().items():
+		if mat is None:
+			continue
 		if (consumption := total_consumption.get(mat)) is None:
 			supplies.append((float('inf'), mat))
 		else:
 			supplies.append((amount / consumption, mat))
 
 	supplies.sort(reverse=True)
+	ignored = frozenset(config.junk.ignore_materials)
 	for days, mat in supplies:
-		print(f'{mat}: {days:.2f} d')
+		if mat in ignored:
+			print(f'\033[90m{mat:3}: {days:.2f} d\033[0m')
+		else:
+			print(f'{mat:3}: {days:.2f} d')
 
 if __name__ == '__main__':
 	main()

+ 2 - 2
market.py

@@ -156,10 +156,10 @@ class Storage(typing.TypedDict):
 	StorageItems: typing.Sequence[StorageItem]
 	WeightLoad: float
 	VolumeLoad: float
-	Type: typing.Literal['STORE'] | typing.Literal['WAREHOUSE_STORE'] | typing.Literal['FTL_FUEL_STORE'] | typing.Literal['STL_FUEL_STORE'] |  typing.Literal['SHIP_STORE']
+	Type: typing.Literal['STORE', 'WAREHOUSE_STORE', 'FTL_FUEL_STORE', 'STL_FUEL_STORE', 'SHIP_STORE']
 
 class StorageItem(typing.TypedDict):
-	MaterialTicker: str
+	MaterialTicker: str | None # shipment blocks are None
 	MaterialAmount: int
 	Type: typing.Literal['INVENTORY', 'SHIPMENT']
 

+ 6 - 0
pyproject.toml

@@ -11,3 +11,9 @@ dependencies = [
 
 [dependency-groups]
 dev = ['workers-py', 'workers-runtime-sdk']
+
+[tool.ruff.lint]
+ignore = [
+	'I001', # unsorted-imports
+	'TRY002', # raise-vanilla-class
+]

+ 1 - 1
supply.py

@@ -193,7 +193,7 @@ def shipping_used(materials: typing.Mapping[str, Material], ignore: typing.Colle
 		volume += amount * materials[ticker]['Volume']
 	return weight, volume
 
-def warehouse_inventory() -> dict[str, int]:
+def warehouse_inventory() -> dict[str | None, int]:
 	warehouses: typing.Sequence[market.Warehouse] = cache.get('https://rest.fnar.net/sites/warehouses/' + config.username,
 			headers={'Authorization': config.fio_rest_key})
 	for warehouse in warehouses: