mirror of
https://github.com/lutris/lutris
synced 2024-09-04 23:13:35 +00:00
Create utility function to convert API dates to datetime objects
This commit is contained in:
parent
59151f0cbe
commit
85bf1dba8d
|
@ -1,5 +1,6 @@
|
|||
"""Functions to interact with the Lutris REST API"""
|
||||
import functools
|
||||
import time
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
|
@ -21,6 +22,11 @@ API_KEY_FILE_PATH = os.path.join(settings.CACHE_DIR, "auth-token")
|
|||
USER_INFO_FILE_PATH = os.path.join(settings.CACHE_DIR, "user.json")
|
||||
|
||||
|
||||
def get_time_from_api_date(date_string):
|
||||
"""Convert a date string originating from the API and convert it to a datetime object"""
|
||||
return time.strptime(date_string[:date_string.find(".")], "%Y-%m-%dT%H:%M:%S")
|
||||
|
||||
|
||||
def load_runtime_versions() -> dict:
|
||||
"""Load runtime versions from json file"""
|
||||
if not system.path_exists(settings.RUNTIME_VERSIONS_PATH):
|
||||
|
|
|
@ -6,7 +6,7 @@ import time
|
|||
from gi.repository import GLib
|
||||
|
||||
from lutris import settings
|
||||
from lutris.api import download_runtime_versions, load_runtime_versions
|
||||
from lutris.api import download_runtime_versions, load_runtime_versions, get_time_from_api_date
|
||||
from lutris.util import http, jobs, system, update_cache
|
||||
from lutris.util.downloader import Downloader
|
||||
from lutris.util.extract import extract_archive
|
||||
|
@ -103,8 +103,7 @@ class Runtime:
|
|||
|
||||
def download(self, remote_runtime_info: dict):
|
||||
"""Downloads a runtime locally"""
|
||||
remote_updated_at = remote_runtime_info["created_at"]
|
||||
remote_updated_at = time.strptime(remote_updated_at[:remote_updated_at.find(".")], "%Y-%m-%dT%H:%M:%S")
|
||||
remote_updated_at = get_time_from_api_date(remote_runtime_info["created_at"])
|
||||
if not self.should_update(remote_updated_at):
|
||||
return None
|
||||
downloader = self.get_downloader(remote_runtime_info)
|
||||
|
@ -139,9 +138,7 @@ class Runtime:
|
|||
components = self.get_runtime_components()
|
||||
downloads = []
|
||||
for component in components:
|
||||
modified_at = time.strptime(
|
||||
component["modified_at"][:component["modified_at"].find(".")], "%Y-%m-%dT%H:%M:%S"
|
||||
)
|
||||
modified_at = get_time_from_api_date(component["modified_at"])
|
||||
if not self.should_update_component(component["filename"], modified_at):
|
||||
continue
|
||||
downloads.append(component)
|
||||
|
|
Loading…
Reference in a new issue