Skip to content

Commit

Permalink
Merge pull request #2 from kurokobo/fix-invalid-json
Browse files Browse the repository at this point in the history
fix: remove initialization per loop for new_data (#1)
  • Loading branch information
kurokobo authored Jun 19, 2021
2 parents 43ef30e + 544d003 commit e6ed824
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 27 deletions.
4 changes: 2 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
from dotenv import load_dotenv

from modules.steam import Steam
from modules.msstore import MSStore
from modules.epicgames import EpicGames
from modules.discord import Discord
from modules.epicgames import EpicGames
from modules.msstore import MSStore

dotenv_path = join(dirname(__file__), ".env")
load_dotenv(dotenv_path)
Expand Down
6 changes: 3 additions & 3 deletions helper/app_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

monkey.patch_all()

import requests # noqa: E402
import ms_cv # noqa: E402
from tabulate import tabulate # noqa: E402
from steam.client import SteamClient # noqa: E402
import requests # noqa: E402
from legendary.cli import LegendaryCLI # noqa: E402
from steam.client import SteamClient # noqa: E402
from tabulate import tabulate # noqa: E402


def gather_steam(id):
Expand Down
1 change: 1 addition & 0 deletions helper/list_cache.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import os

from tabulate import tabulate


Expand Down
14 changes: 7 additions & 7 deletions modules/epicgames.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import copy
import logging
from datetime import datetime

from legendary.cli import LegendaryCLI

from modules.models import Cache, Result, App
from modules import utils
from modules.models import App, Cache, Result


class EpicGames:
def __init__(self, app_ids, notifier, ignore_first):
self.logger = logging.getLogger(__name__)
self.client = LegendaryCLI()
self.old_result = None
self.new_result = None
self.old_result = {}
self.new_result = {}
self.timestamp = None

self.apps = app_ids
Expand Down Expand Up @@ -40,10 +41,9 @@ def gather_app_info(self):
self.logger.info("Cache raw data as {}".format(self.cache.tmp_data))
utils.save_dict_as_json(_product_info, self.cache.tmp_data)

self.old_result = self.new_result
self.new_result = {}
self.old_result = copy.copy(self.new_result)
for _app in self.apps:
self.logger.info("Gather updated data from raw data")
self.logger.info("Gather updated data from raw data for: {}".format(_app))

_last_updated = None
if self.old_result and _app in self.old_result:
Expand All @@ -69,7 +69,7 @@ def is_updated(self):

for _app in self.apps:
if (
self.old_result is None
self.old_result is {}
or _app not in self.old_result
or self.old_result[_app].data != self.new_result[_app].data
):
Expand Down
17 changes: 9 additions & 8 deletions modules/msstore.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import copy
import logging
from datetime import datetime
import requests
import re
from datetime import datetime

import ms_cv
import requests

from modules.models import Cache, Result, App
from modules import utils
from modules.models import App, Cache, Result


class MSStoreFilter:
Expand All @@ -18,8 +19,8 @@ def __init__(self, id, filter="Windows.Desktop"):
class MSStore:
def __init__(self, app_ids, notifier, ignore_first, market):
self.logger = logging.getLogger(__name__)
self.old_result = None
self.new_result = None
self.old_result = {}
self.new_result = {}
self.timestamp = None

self.apps = []
Expand Down Expand Up @@ -63,8 +64,7 @@ def gather_app_info(self):
self.logger.info("Cache raw data as {}".format(self.cache.tmp_data))
utils.save_dict_as_json(_product_info, self.cache.tmp_data)

self.old_result = self.new_result
self.new_result = {}
self.old_result = copy.copy(self.new_result)
for _app in self.apps:
self.logger.info(
"Gather updated data from raw data for {} for: {}".format(
Expand Down Expand Up @@ -121,9 +121,10 @@ def is_updated(self):
_is_updated = False
_updated_apps = []

print(self.old_result)
for _app in self.apps:
if (
self.old_result is None
self.old_result is {}
or _app.id not in self.old_result
or self.old_result[_app.id].data != self.new_result[_app.id].data
):
Expand Down
12 changes: 6 additions & 6 deletions modules/steam.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import copy
import logging
from datetime import datetime

Expand All @@ -7,8 +8,8 @@

monkey.patch_all()

from modules.models import Cache, Result, App # noqa: E402
from modules import utils # noqa: E402
from modules.models import App, Cache, Result # noqa: E402


class SteamAppFilter:
Expand All @@ -21,8 +22,8 @@ class Steam:
def __init__(self, app_ids, notifier, ignore_first):
self.logger = logging.getLogger(__name__)
self.client = SteamClient()
self.old_result = None
self.new_result = None
self.old_result = {}
self.new_result = {}
self.timestamp = None

self.apps = []
Expand Down Expand Up @@ -75,8 +76,7 @@ def gather_app_info(self):
self.logger.info("Cache raw data as {}".format(self.cache.tmp_data))
utils.save_dict_as_json(_product_info, self.cache.tmp_data)

self.old_result = self.new_result
self.new_result = {}
self.old_result = copy.copy(self.new_result)
for _app in self.apps:
self.logger.info(
"Gather updated data from raw data for {} in branch: {}".format(
Expand Down Expand Up @@ -110,7 +110,7 @@ def is_updated(self):

for _app in self.apps:
if (
self.old_result is None
self.old_result is {}
or _app.id not in self.old_result
or self.old_result[_app.id].data != self.new_result[_app.id].data
):
Expand Down
2 changes: 1 addition & 1 deletion modules/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
import json
import os

from modules import models

Expand Down

0 comments on commit e6ed824

Please sign in to comment.