Skip to content

Commit

Permalink
Refatora função para usar cache do redis ao invés de em memória
Browse files Browse the repository at this point in the history
Precisei fazer a chamada de _asdict porque o objeto rows.table.Row não é pickable.
Criei uma issue na rows endereçando isso:
turicas/rows#349
  • Loading branch information
berinhard committed May 6, 2020
1 parent bb22710 commit d6fc114
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions covid19/google_data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import io
import rows
from cachetools import cached, TTLCache
from cache_memoize import cache_memoize
from urllib.parse import parse_qs, urlparse

from core.util import http_get
Expand All @@ -26,11 +26,11 @@ def spreadsheet_download_url(url_or_id, file_format):
)


@cached(cache=TTLCache(maxsize=100, ttl=24 * 3600))
@cache_memoize(24 * 3600)
def get_general_spreadsheet(timeout=5):
data = http_get(spreadsheet_download_url(STATE_LINKS_SPREADSHEET_ID, "csv"), timeout)
table = rows.import_from_csv(io.BytesIO(data), encoding="utf-8")
return {row.uf: row for row in table}
return {row.uf: row._asdict() for row in table}


def import_info_by_state(state):
Expand Down

0 comments on commit d6fc114

Please sign in to comment.