From f5267d05d7f4275314913877388e3558a0382052 Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Sun, 24 May 2020 13:06:52 +0100 Subject: [PATCH] my.twitter.archive: rename config (preserving bckwd compatibility for now) --- doc/MODULES.org | 19 ++++++++++--------- my/twitter/archive.py | 22 ++++++++++++++++++---- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/doc/MODULES.org b/doc/MODULES.org index 1a05624..e26d439 100644 --- a/doc/MODULES.org +++ b/doc/MODULES.org @@ -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]]. @@ -55,14 +56,14 @@ import importlib # from lint import all_modules # meh # TODO figure out how to discover configs automatically... modules = [ - ('google' , 'my.google.takeout.paths'), - ('hypothesis' , 'my.hypothesis' ), - ('reddit' , 'my.reddit' ), - ('twint' , 'my.twitter.twint' ), - ('twitter' , 'my.twitter.archive' ), - ('lastfm' , 'my.lastfm' ), - ('polar' , 'my.reading.polar' ), - ('instapaper' , 'my.instapaper' ), + ('google' , 'my.google.takeout.paths'), + ('hypothesis' , 'my.hypothesis' ), + ('reddit' , 'my.reddit' ), + ('twint' , 'my.twitter.twint' ), + ('twitter_archive', 'my.twitter.archive' ), + ('lastfm' , 'my.lastfm' ), + ('polar' , 'my.reading.polar' ), + ('instapaper' , 'my.instapaper' ), ] def indent(s, spaces=4): @@ -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]] diff --git a/my/twitter/archive.py b/my/twitter/archive.py index edcf63c..031701f 100755 --- a/my/twitter/archive.py +++ b/my/twitter/archive.py @@ -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