my.twitter.archive: rename config (preserving bckwd compatibility for now)

This commit is contained in:
Dima Gerasimov 2020-05-24 13:06:52 +01:00
parent b99b2f3cfa
commit f5267d05d7
2 changed files with 28 additions and 13 deletions

View file

@ -36,6 +36,7 @@ Some explanations:
- =/a/path/to/directory/=, so the module will consume all files from this directory
- a list of files/directories (it will be flattened)
- a [[https://docs.python.org/3/library/glob.html?highlight=glob#glob.glob][glob]] string, so you can be flexible about the format of your data on disk (e.g. if you want to keep it compressed)
- empty sequence (e.g. ~export_path = ()~), this is useful for modules that merge multiple data sources (for example, =my.twitter=)
Typically, such variable will be passed to =get_files= to actually extract the list of real files to use. You can see usage examples [[https://github.com/karlicoss/HPI/blob/master/tests/get_files.py][here]].
@ -59,7 +60,7 @@ modules = [
('hypothesis' , 'my.hypothesis' ),
('reddit' , 'my.reddit' ),
('twint' , 'my.twitter.twint' ),
('twitter' , 'my.twitter.archive' ),
('twitter_archive', 'my.twitter.archive' ),
('lastfm' , 'my.lastfm' ),
('polar' , 'my.reading.polar' ),
('instapaper' , 'my.instapaper' ),
@ -157,7 +158,7 @@ for cls, p in modules:
Twitter data (uses [[https://help.twitter.com/en/managing-your-account/how-to-download-your-twitter-archive][official twitter archive export]])
#+begin_src python
class twitter:
class twitter_archive:
export_path: Paths # path[s]/glob to the twitter archive takeout
#+end_src
** [[file:../my/lastfm][my.lastfm]]

View file

@ -1,21 +1,35 @@
"""
Twitter data (uses [[https://help.twitter.com/en/managing-your-account/how-to-download-your-twitter-archive][official twitter archive export]])
"""
# before this config was named 'twitter', doesn't make too much sense for archive
# try to import it defensively..
try:
from my.config import twitter_archive as user_config
except ImportError as e:
try:
from my.config import twitter as user_config
except ImportError:
raise e # raise the original exception.. must be somethingelse
else:
import warnings
warnings.warn('my.config.twitter is deprecated! Please rename it to my.config.twitter_archive in your config')
from dataclasses import dataclass
from ..core.common import Paths
from my.config import twitter as user_config
# TODO perhaps rename to twitter_archive? dunno
@dataclass
class twitter(user_config):
class twitter_archive(user_config):
export_path: Paths # path[s]/glob to the twitter archive takeout
###
from ..core.cfg import make_config
config = make_config(twitter)
config = make_config(twitter_archive)
from datetime import datetime