Added build_deep_stats_model, made other small tweaks
This commit is contained in:
@@ -11,6 +11,7 @@ from typing import Any, Callable, Dict, List, Tuple
|
||||
|
||||
import pytumblr
|
||||
|
||||
from build_deep_stats_model import BuildDeepStatsModel
|
||||
from build_draft_stats_model import BuildDraftStatsModel
|
||||
from build_tag_stats_model import BuildTagStatsModel
|
||||
from build_total_stats_model import BuildTotalStatsModel
|
||||
@@ -26,7 +27,8 @@ def get_args() -> Dict[str, Any]:
|
||||
+ '$TUMBLR_CONSUMER_KEY, $TUMBLR_CONSUMER_SECRET, $TUMBLR_OAUTH_TOKEN, and $TUMBLR_OAUTH_SECRET',
|
||||
epilog='— Be gay and do crime')
|
||||
parser.add_argument('operation', type=str, nargs='+', metavar='OPERATION',
|
||||
choices=['build_tag_stats', 'build_queue_stats', 'build_draft_stats'],
|
||||
choices=['build_tag_stats', 'build_queue_stats', 'build_draft_stats',
|
||||
'build_deep_stats'],
|
||||
help="operation used to calculate stats")
|
||||
parser.add_argument('-b', '--blog', type=str, required=True,
|
||||
help='blog name for which to calculate stats')
|
||||
@@ -94,6 +96,7 @@ def build_post_maps(client: pytumblr.TumblrRestClient,
|
||||
|
||||
draft_url = f"/v2/blog/{blog_name}/posts/draft"
|
||||
is_draft_stats: bool = 'build_draft_stats' in args['operation']
|
||||
is_deep_stats: bool = 'build_deep_stats' in args['operation']
|
||||
|
||||
total: int = 0
|
||||
offset: int = 0
|
||||
@@ -112,6 +115,8 @@ def build_post_maps(client: pytumblr.TumblrRestClient,
|
||||
elif is_draft_stats:
|
||||
data = client.send_api_request("get", draft_url)
|
||||
else: # Above is for queued + draft posts, below is for published posts.
|
||||
if is_deep_stats:
|
||||
params.update({'notes_info': 'true'})
|
||||
data = client.posts(f"{blog_name}.tumblr.com",
|
||||
offset=offset,
|
||||
limit=limit,
|
||||
@@ -236,6 +241,14 @@ def main() -> None:
|
||||
stats_model = BuildTotalStatsModel(blog_name=args['blog'],
|
||||
original_post_map=og_post_map,
|
||||
unoriginal_post_map=un_og_post_map)
|
||||
case {'operation': op} if 'build_deep_stats' in operation:
|
||||
if 'after' not in args: # or 'before' not in args:
|
||||
print(f"You must specify a time range for {op}. " +
|
||||
'You\'ll otherwise request TOO MUCH DATA!')
|
||||
sys.exit(1)
|
||||
stats_model = BuildDeepStatsModel(blog_name=args['blog'],
|
||||
original_post_map=og_post_map,
|
||||
unoriginal_post_map=un_og_post_map)
|
||||
case _:
|
||||
print('Unsupported command. How did you even make it this far?!')
|
||||
sys.exit(1)
|
||||
|
||||
Reference in New Issue
Block a user