Update lastfm order/tests/docs
This commit is contained in:
parent
522bfff679
commit
eba2d26b31
3 changed files with 42 additions and 6 deletions
|
@ -32,6 +32,7 @@ modules = [
|
|||
('reddit' , 'my.reddit' ),
|
||||
('twint' , 'my.twitter.twint' ),
|
||||
('twitter', 'my.twitter.archive' ),
|
||||
('lastfm' , 'my.lastfm' ),
|
||||
]
|
||||
|
||||
def indent(s, spaces=4):
|
||||
|
@ -105,4 +106,15 @@ for cls, p in modules:
|
|||
class twitter:
|
||||
export_path: Paths # path[s]/glob to the twitter archive takeout
|
||||
#+end_src
|
||||
- [[file:../my/lastfm][my.lastfm]]
|
||||
|
||||
Last.fm scrobbles
|
||||
|
||||
#+begin_src python
|
||||
class lastfm:
|
||||
"""
|
||||
Uses [[https://github.com/karlicoss/lastfm-backup][lastfm-backup]] outputs
|
||||
"""
|
||||
export_path: Paths
|
||||
#+end_src
|
||||
:end:
|
||||
|
|
|
@ -2,8 +2,21 @@
|
|||
Last.fm scrobbles
|
||||
'''
|
||||
|
||||
from ..core.common import Paths
|
||||
from dataclasses import dataclass
|
||||
from my.config import lastfm as user_config
|
||||
|
||||
@dataclass
|
||||
class lastfm(user_config):
|
||||
"""
|
||||
Uses [[https://github.com/karlicoss/lastfm-backup][lastfm-backup]] outputs
|
||||
"""
|
||||
export_path: Paths
|
||||
|
||||
|
||||
from ..core.cfg import make_config
|
||||
config = make_config(lastfm)
|
||||
|
||||
from ..common import get_files, mcachew, Json
|
||||
|
||||
from datetime import datetime
|
||||
import json
|
||||
|
@ -12,16 +25,17 @@ from typing import NamedTuple, Any, Sequence, Iterable
|
|||
|
||||
import pytz
|
||||
|
||||
from my.config import lastfm as config
|
||||
from ..core.common import mcachew, Json, get_files
|
||||
|
||||
def inputs() -> Sequence[Path]:
|
||||
return get_files(config.export_path)
|
||||
|
||||
|
||||
# TODO memoised properties?
|
||||
# TODO lazy mode and eager mode?
|
||||
# lazy is a bit nicer in terms of more flexibility and less processing?
|
||||
# eager is a bit more explicit for error handling
|
||||
|
||||
def inputs() -> Sequence[Path]:
|
||||
return get_files(config.export_path)
|
||||
|
||||
|
||||
class Scrobble(NamedTuple):
|
||||
raw: Json
|
||||
|
@ -54,5 +68,5 @@ def scrobbles() -> Iterable[Scrobble]:
|
|||
last = max(inputs())
|
||||
j = json.loads(last.read_text())
|
||||
|
||||
for raw in j:
|
||||
for raw in reversed(j):
|
||||
yield Scrobble(raw=raw)
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
from my.core.cachew import disable_cachew
|
||||
# TODO need something nicer and integrated inside cachew..
|
||||
disable_cachew() # meh
|
||||
|
||||
from more_itertools import ilen
|
||||
|
||||
from my.lastfm import scrobbles
|
||||
|
@ -5,3 +9,9 @@ from my.lastfm import scrobbles
|
|||
|
||||
def test():
|
||||
assert ilen(scrobbles()) > 1000
|
||||
|
||||
|
||||
def test_datetime_ascending():
|
||||
from more_itertools import pairwise
|
||||
for a, b in pairwise(scrobbles()):
|
||||
assert a.dt <= b.dt
|
||||
|
|
Loading…
Add table
Reference in a new issue