Skip to content

Commit

Permalink
Added to replace
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel committed Jul 16, 2023
1 parent ebed86b commit b2c4fa9
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion modrinth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
'''

import requests
from warnings import warn

__version__ = '0.1.3'
__version__ = '0.1.5'


class Users:
Expand Down Expand Up @@ -295,11 +296,32 @@ def __init__(self, project: Projects.ModrinthProject, version: str):
self.changeLog: str = rJSON['changelog']
self.dependencies: list = rJSON['dependencies']
self.changeLogURL: str = rJSON['changelog_url']

def getFiles(self, hash: str = 'sha1', primary: bool = True, optional: bool = True) -> str:
'''
Returns the file hashes of the version.
'''
files = []

if hash not in ['sha1', 'sha512']:
raise ValueError("hash must be either sha1 or sha512")
for file in self.files:
if file['primary'] and primary:
files.append(file['hashes'][hash])
elif not file['primary'] and optional:
files.append(file['hashes'][hash])

return files


def getPrimaryFile(self, hash: str = 'sha1') -> str:
'''
Returns the primary file hash of the version.
Deprecate: Use getFiles instead, getPrimaryFile may be removed in
a future update.
'''
warn("getPrimaryFile is deprecated, use getFiles instead.")
if hash not in ['sha1', 'sha512']:
raise ValueError("hash must be either sha1 or sha512")
for file in self.files:
Expand Down

1 comment on commit b2c4fa9

@betapictoris
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh dang, that commit message got messed up, it was supposed to be "Added getFiles to replace getPrimaryFile."

Please sign in to comment.