PK!wtweakstream/__init__.py__version__ = "0.3.2" PK!֭tweakstream/cli.pyfrom datetime import datetime import click import crayons import tweakers from tabulate import tabulate from . import __version__, config, utils def format_date(dt): if dt.date() == datetime.today().date(): return dt.strftime("%H:%M") elif dt.year == datetime.today().year: return dt.strftime("%d-%m") else: return dt.strftime("%d-%m-%Y") def confirm_overwrite_existing_login(): if utils.cookies_exist(): confirmed = click.confirm( "You are already logged in. Would you like to login to a different account?" ) if confirmed: config.stored_cookies_path.unlink() click.echo("Existing login deleted.") else: raise SystemExit def print_comment(comment): """Pretty print a comment""" print( crayons.yellow((comment.date.strftime("%H:%M"))), crayons.green(comment.user.name), crayons.blue(comment.url), ) print(comment.text, "\n") def choose_topic(topics): """Return chosen topic from a printed list of topics Args: topics (list): List of Topic objects Returns: topic (Topic): Chosen topic """ table = [] for i, t in enumerate(topics): row = [i + 1, t.title, format_date(t.last_reply)] table.append(row) print("\n", tabulate(table, headers=["#", "Titel", "Laatste reactie"])) choice = click.prompt(f"\nChoose a topic to stream (1-{len(topics)})", type=int) return topics[choice - 1] @click.group() @click.version_option(version=__version__) @click.option("--last", default=3, help="Number of previous comments to show.") @click.pass_context def cli(ctx, last): ctx.ensure_object(dict) ctx.obj["last"] = last try: utils.load_persistent_cookies() except FileNotFoundError: pass @cli.command(name="stream", help="Stream from a specific url.") @click.argument("url") @click.pass_context def stream(ctx, url): topic = tweakers.gathering.Topic(url=url) for comment in topic.comment_stream(last=ctx.obj["last"]): print_comment(comment) @cli.command(name="list", help="Choose from a list of active topics.") @click.option("-n", default=20, help="Number of topics to show.") @click.pass_context def list_active(ctx, n): topics = tweakers.gathering.active_topics()[:n] topic = choose_topic(topics) for comment in topic.comment_stream(last=ctx.obj["last"]): print_comment(comment) @cli.command(name="search", help="Search for a specific topic.") @click.argument("query", nargs=-1) @click.option("-n", default=10, help="Number of results to show.") @click.pass_context def search(ctx, query, n): query = " ".join(query) topics = tweakers.gathering.search(query) if len(topics) == 0: click.echo("No topics found!") raise SystemExit topic = choose_topic(topics) for comment in topic.comment_stream(last=ctx.obj["last"]): print_comment(comment) @cli.command(name="login", help="Login to tweakers.net.") def login(): confirm_overwrite_existing_login() username = click.prompt("Username") password = click.prompt("Password", hide_input=True) tweakers.utils.login(username=username, password=password) utils.store_persistent_cookies() click.echo("Login successful!") @cli.command(name="bookmarks", help="Choose from a list of bookmarks.") @click.pass_context def bookmarks(ctx): topics = tweakers.gathering.bookmarks() if len(topics) == 0: click.echo("No topics found!") raise SystemExit topic = choose_topic(topics) for comment in topic.comment_stream(last=ctx.obj["last"]): print_comment(comment) if __name__ == "__main__": cli(obj={}) PK!0<tweakstream/config.pyfrom pathlib import Path from appdirs import user_data_dir save_dir = user_data_dir(appname="tweakstream") filename = "cookies.pkl" stored_cookies_path = Path(save_dir) / filename PK!n^-iitweakstream/utils.pyimport pickle from tweakers.utils import session from . import config def ensure_user_data_dir_exists(func): def wrapper(): config.stored_cookies_path.parent.mkdir(exist_ok=True) func() return wrapper @ensure_user_data_dir_exists def store_persistent_cookies(): with open(config.stored_cookies_path, "wb") as f: pickle.dump(session.cookies, f) def load_persistent_cookies(): with open(config.stored_cookies_path, "rb") as f: cookies = pickle.load(f) session.cookies.update(cookies) def cookies_exist(): return config.stored_cookies_path.exists() PK!Y'%%#tweakstream-0.3.2.dist-info/LICENSEMIT License Copyright (c) 2018 Timo Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!H_zTT!tweakstream-0.3.2.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]n0H*J>mlcAPK!H$tweakstream-0.3.2.dist-info/METADATAWkOH_qEV['@BDz-PTX)}Lb{3P{vJZ$}Ϝ;*Q3pE}{~˻ȓD]ɪLFZ%4vZc0E?ewgᅵy'2Go/{Q&R_)ܾ|wX#G!W)SG/i/˴sanʹVc-щH9qjѹ@#eԆ_-q_&e8sJBkV~67U汰\ v]%XulP}ZNmu _mȘE* y+_7Htr o5:Nq)h._[4 >߻2b{'ddHXƒsI!۲<"m9N݂Yd^Z@xÉm|44] XT0Rev9%Tq& ґБ1׋Q"FZP\¨*UXa \F2 \8h :kQ"VWDAX0יUa55Jl*նO C]]NJ+Qs^=. f_81]IJirtkCV uڡRidN۲Nan\3ԥ¼Q:kahaV`:QA)k~v>d {M,1ѷze2uh*4)mѫuTL!:,3\w 1R:Onq`Awv*;eQҲz]_RD2\Xw4K#d8Hǚjm{h۪Ŭ]FtPK!Hy؂h"tweakstream-0.3.2.dist-info/RECORD}ˎ0@| : b -UPC Hį٘8m88˷e8p"tF-a?i}AWCw"͇[Ն_(;k,E{ ;%CqpZcg z=0N';UIh}*9FT8ӻi\J91>1g$Txnm~f/VhkCvtrסvTUMe:*1u'?peR}t?ib]5/~ljD/G\U"x |ƫ|^2̎vDF*L ]c[A<%IM'IMݻ<=qH5