Compare commits

..

10 Commits

Author SHA1 Message Date
8ab616e5fd 🚀 It's a new version!
All checks were successful
Release / check_for_changed_version (push) Successful in 26s
Release / build (push) Successful in 3m53s
2023-05-19 09:52:57 -04:00
1749a8659a Merge pull request 'reddit-support' (#1) from reddit-support into master
All checks were successful
Release / check_for_changed_version (push) Successful in 31s
Release / build (push) Successful in 4m10s
Reviewed-on: #1
2023-05-18 21:51:39 -04:00
5592c0e7cd finish reddit support 2023-05-18 21:49:23 -04:00
b8a482f86c 👷 doin' the thing 2023-05-18 18:45:40 -04:00
d3595cf6b0 👷 turns out I need to wait until 1.20.0
All checks were successful
Release / check_for_changed_version (push) Successful in 24s
Release / build (push) Successful in 3m54s
2023-04-26 10:31:15 -04:00
05d2f5829d 👷 shenanigans with versions
Some checks failed
Release / check_for_changed_version (push) Successful in 22s
Release / checkvar (push) Successful in 19s
Release / build (push) Failing after 3s
2023-04-26 10:26:27 -04:00
4fd6848372 💚 update version number to check deploy
All checks were successful
Release / check_for_changed_version (push) Successful in 23s
Release / build (push) Has been skipped
2023-04-26 10:20:25 -04:00
ff3319a2fc Merge remote-tracking branch 'origin/master'
All checks were successful
Release / check_for_changed_version (push) Successful in 22s
Release / build (push) Has been skipped
2023-04-26 10:16:52 -04:00
4568dd0e4c 💚 test 'needs' jobs on gitea 1.19.1 without changing the version number 2023-04-26 10:16:26 -04:00
fc2e10f9ad add local scope to shell
All checks were successful
build
check_for_changed_version
2023-04-23 16:04:23 -04:00
6 changed files with 1548 additions and 840 deletions

View File

@ -28,9 +28,10 @@ jobs:
echo "::notice title=GOTIME::$GOTIME" echo "::notice title=GOTIME::$GOTIME"
# Set the output named "version_changed" # Set the output named "version_changed"
echo "version_changed=$GOTIME" >> $GITHUB_OUTPUT echo "version_changed=$GOTIME" >> $GITHUB_OUTPUT
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
# this should start working with https://github.com/go-gitea/gitea/pull/24230
# needs: [ check_for_changed_version ] # needs: [ check_for_changed_version ]
# if: needs.check_for_changed_version.outputs.version_changed == 'True' # if: needs.check_for_changed_version.outputs.version_changed == 'True'
permissions: permissions:

3
.gitignore vendored
View File

@ -128,4 +128,5 @@ dmypy.json
# Pyre type checker # Pyre type checker
.pyre/ .pyre/
setup.py setup.py
utils utils
praw.ini

2270
poetry.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "src" name = "src"
version = "0.2.0" version = "0.3.0"
description = "" description = ""
authors = ["Joe Kaufeld <opensource@joekaufeld.com>"] authors = ["Joe Kaufeld <opensource@joekaufeld.com>"]
@ -11,6 +11,7 @@ httpx = "^0.23.0"
click = "^8.1.3" click = "^8.1.3"
rich = "^12.5.1" rich = "^12.5.1"
markdownify = "^0.11.6" markdownify = "^0.11.6"
praw = "^7.7.0"
[tool.poetry.dev-dependencies] [tool.poetry.dev-dependencies]
poetry = "^1.1.14" poetry = "^1.1.14"
@ -21,4 +22,4 @@ requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api" build-backend = "poetry.core.masonry.api"
[tool.poetry.plugins."console_scripts"] [tool.poetry.plugins."console_scripts"]
"utils" = "src.cli:main" "utils" = "src.cli:main"

View File

@ -6,14 +6,15 @@ import uuid
import click import click
import httpx import httpx
from praw import Reddit
from rich import pretty from rich import pretty
from rich.status import Status from rich.status import Status
from rich.traceback import install from rich.traceback import install
from shiv.bootstrap import current_zipfile from shiv.bootstrap import current_zipfile
import src import src
from src.helpers import flip_char from src.helpers import flip_char, load_config, write_config
from src.joplin import process_joplin_posts from src.joplin import process_joplin_posts, get_folders, BASE_URL
from src.art import BANNERS from src.art import BANNERS
@ -39,7 +40,7 @@ def main(ctx, update):
pretty.install() # type: ignore pretty.install() # type: ignore
install() # traceback handler install() # traceback handler
code.interact(banner, None) code.interact(local=globals(), banner=banner)
sys.exit() sys.exit()
@ -115,6 +116,98 @@ def beautify(words: list[str]):
click.echo("".join(new_beautiful_string)) click.echo("".join(new_beautiful_string))
@main.command()
def get_saved_from_reddit() -> None:
"""Get saved posts from reddit."""
def _process(item):
fullname = item.fullname
if fullname.startswith("t3"):
# we got a post
title = f"{item.subreddit.display_name} - {item.title}"
body = item.selftext if item.selftext else item.url
elif fullname.startswith("t1"):
# comment time
try:
author_name = item.author.name
except AttributeError:
author_name = "[deleted]"
title = (
f"{item.submission.subreddit.display_name} - {item.submission.title}"
)
body = f"Comment from {author_name}:\n\n{item.body}"
else:
click.echo(f"Not sure how to process https://reddit.com{item.permalink}")
return
if item.over_18:
title = "🔴 " + title
body = "https://reddit.com" + item.permalink + "\n\n" + body
joplin = BASE_URL + cfg["JOPLIN_PORT"]
notes_url = joplin + f"/notes/?token={cfg.get('JOPLIN_TOKEN')}"
click.echo(f"Processing {title}...")
httpx.post(
notes_url,
json={
"title": title,
"body": body,
"parent_id": cfg.get("joplin_saved_posts_folder_id"),
},
)
item.unsave()
cfg = load_config()
# because 2fa is enabled, we have to get the code first
twofa_code = click.prompt("What's the current 2fa code?", type=str)
if not cfg.get("REDDIT_CLIENT_ID"):
cfg["REDDIT_CLIENT_ID"] = ""
if not cfg.get("REDDIT_CLIENT_SECRET"):
cfg["REDDIT_CLIENT_SECRET"] = ""
if not cfg.get("REDDIT_PASSWORD"):
cfg["REDDIT_PASSWORD"] = ""
if not cfg.get("REDDIT_USERNAME"):
cfg["REDDIT_USERNAME"] = ""
if not cfg.get("joplin_saved_posts_folder_id"):
cfg["joplin_saved_posts_folder_id"] = ""
write_config(cfg)
username = cfg.get("REDDIT_USERNAME", "")
r = Reddit(
client_id=cfg.get("REDDIT_CLIENT_ID", ""),
client_secret=cfg.get("REDDIT_CLIENT_SECRET", ""),
username=username,
password=f"{cfg.get('REDDIT_PASSWORD', '')}:{twofa_code}",
user_agent=f"getter of saved posts, u/{username}",
)
try:
r.user.me()
except Exception as e:
click.echo(f"Cannot connect to reddit: {e}")
return
if not cfg.get("joplin_saved_posts_folder_id"):
folders = get_folders()
click.echo("Pick the folder that I should write your saved posts to:")
for count, option in enumerate(folders["items"]):
click.echo(f"{count} - {option['title']}")
folder_position = click.prompt("Number of folder?", type=int)
folder_name = folders["items"][folder_position]["title"]
folder_id = folders["items"][folder_position]["id"]
click.echo(f"Got it, will write to {folder_name}, ID {folder_id}.")
cfg["joplin_saved_posts_folder_id"] = folder_id
write_config(cfg)
for _ in range(10):
click.echo("Getting new posts...")
for item in r.user.me().saved(limit=None):
_process(item)
def update_from_gitea(): def update_from_gitea():
"""Get the newest release from Gitea and install it.""" """Get the newest release from Gitea and install it."""
status = Status("Checking for new release...") status = Status("Checking for new release...")

View File

@ -105,18 +105,20 @@ def process_joplin_posts():
httpx.get( httpx.get(
joplin joplin
+ f"/notes/{blob['id']}?fields=body&token={c.get('JOPLIN_TOKEN')}" + f"/notes/{blob['id']}?fields=body&token={c.get('JOPLIN_TOKEN')}"
).json()['body'].strip() )
.json()["body"]
.strip()
) )
click.echo(f"Processing {url}...") click.echo(f"Processing {url}...")
site = httpx.get(url, follow_redirects=True) site = httpx.get(url, follow_redirects=True)
soup = bs4.BeautifulSoup(site.content, features="html5lib") soup = bs4.BeautifulSoup(site.content, features="html5lib")
# clean up that schizz # clean up that schizz
title = soup.title.text title = soup.title.text
[t.extract() for t in soup(['script', 'head', 'style'])] [t.extract() for t in soup(["script", "head", "style"])]
body = md(str(soup)) body = md(str(soup))
httpx.put( httpx.put(
joplin + f"/notes/{blob['id']}?token={c.get('JOPLIN_TOKEN')}", joplin + f"/notes/{blob['id']}?token={c.get('JOPLIN_TOKEN')}",
json={'title': title, 'body': body} json={"title": title, "body": body},
) )
click.echo(resp) click.echo(resp)