Skip to content

Commit

Permalink
Merge pull request #8 from j6k4m8/no-frof-no
Browse files Browse the repository at this point in the history
HONK! A new, python-only flow
  • Loading branch information
j6k4m8 committed Nov 2, 2020
2 parents 82a1343 + c7981fb commit fd8b62f
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 155 deletions.
64 changes: 32 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,73 +8,73 @@

goosepaper is a utility that delivers a daily newspaper to your remarkable tablet. that's cute!

you can include RSS feeds, Twitter feeds, news articles, wikipedia articles-of-the-day, weather, and more. I read it when I wake up so that I can feel anxious without having to get my phone out.
you can include RSS feeds, Twitter feeds, news articles, wikipedia articles-of-the-day, weather, and more. I read it when I wake up so that I can feel anxious without having to get my phone.

Check out [this example PDF](https://github.com/j6k4m8/goosepaper/blob/71ee16e91840560fe40234493a02a283cb84083f/docs/Example-Nov-1-2020.pdf), generated on Nov 1 2020 using `main.py`.
## installation

### dependencies:

## existing story providers (want to write your own?)

* [Wikipedia Top News / Current Events](https://github.com/j6k4m8/goosepaper/blob/71ee16e91840560fe40234493a02a283cb84083f/goosepaper/__init__.py#L112)
* [Tweets](https://github.com/j6k4m8/goosepaper/blob/71ee16e91840560fe40234493a02a283cb84083f/goosepaper/__init__.py#L154) (Note: Currently borked, see [Issue #5](https://github.com/j6k4m8/goosepaper/issues/5))
* [Weather](https://github.com/j6k4m8/goosepaper/blob/71ee16e91840560fe40234493a02a283cb84083f/goosepaper/__init__.py#L258). These stories appear in the "ear" of the front page, just like a regular ol' newspaper
* [RSS Feeds](https://github.com/j6k4m8/goosepaper/blob/71ee16e91840560fe40234493a02a283cb84083f/goosepaper/__init__.py#L283)
* [Reddit Subreddits](https://github.com/j6k4m8/goosepaper/blob/71ee16e91840560fe40234493a02a283cb84083f/goosepaper/__init__.py#L307)
this tool uses `weasyprint` to generate PDFs. You can install everything you need with `pip3 install -r ./requirements.txt` from this repo, but you may need these prerequisites before starting.

## usage
more details [here](https://weasyprint.readthedocs.io/en/latest/install.html).

execute easily using [frof](https://github.com/j6k4m8/frof):
#### mac:

```shell
frof remarkable.frof
brew install cairo pango gdk-pixbuf libffi
```

You can add this to a crontab to run daily in the morning.

### slightly more annoying, without frof:
#### ubuntu-flavored:

```shell
mkdir -p temp
python3 main.py > temp/test.html
wkhtmltopdf temp/test.html temp/test.pdf
open temp/test.pdf
sudo apt-get install build-essential python3-dev python3-pip python3-setuptools python3-wheel python3-cffi libcairo2 libpango-1.0-0 libpangocairo-1.0-0 libgdk-pixbuf2.0-0 libffi-dev shared-mime-info
```

### p2r
#### windows:

[Follow these instructions carefully](https://weasyprint.readthedocs.io/en/latest/install.html#windows).

You'll need a [`p2r` of some variety](https://github.com/GjjvdBurg/paper2remarkable) installed; this tool syncs documents to your tablet. (You can also use this without p2r, and sync the PDF yourself.) I'd recommend cloning the p2r repo and building with docker:
## and then:

```shell
git clone https://github.com/GjjvdBurg/paper2remarkable
cd paper2remarkable
docker build -t p2r .
pip3 install -r ./requirements.txt
```

## yes but pardon me — i haven't a remarkable tablet
## get started

Do you have another kind of tablet? You may generate a print-ready PDF which you can use on another kind of robot as well!
You can customize your goosepaper by editing `main.py`. (Better customization tools coming soon!)

```shell
frof frofs/pdf-only.frof
python3 ./main.py
```

## thank you, but i prefer not to install `frof`!
Check out [this example PDF](https://github.com/j6k4m8/goosepaper/blob/71ee16e91840560fe40234493a02a283cb84083f/docs/Example-Nov-1-2020.pdf), generated on Nov 1 2020.

that is ok! you can still use this like a Python library, and move the resulting HTML or PDF onto your device of choice.
## existing story providers (want to write your own?)

- [Wikipedia Top News / Current Events](https://github.com/j6k4m8/goosepaper/blob/71ee16e91840560fe40234493a02a283cb84083f/goosepaper/__init__.py#L112)
- [Tweets](https://github.com/j6k4m8/goosepaper/blob/71ee16e91840560fe40234493a02a283cb84083f/goosepaper/__init__.py#L154) (Note: Currently borked, see [Issue #5](https://github.com/j6k4m8/goosepaper/issues/5))
- [Weather](https://github.com/j6k4m8/goosepaper/blob/71ee16e91840560fe40234493a02a283cb84083f/goosepaper/__init__.py#L258). These stories appear in the "ear" of the front page, just like a regular ol' newspaper
- [RSS Feeds](https://github.com/j6k4m8/goosepaper/blob/71ee16e91840560fe40234493a02a283cb84083f/goosepaper/__init__.py#L283)
- [Reddit Subreddits](https://github.com/j6k4m8/goosepaper/blob/71ee16e91840560fe40234493a02a283cb84083f/goosepaper/__init__.py#L307)

# More Questions, Infrequently Asked

## very nice! may i have it in comic sans?
### yes but pardon me — i haven't a remarkable tablet

Do you have another kind of tablet? You may generate a print-ready PDF which you can use on another kind of robot as well! Just remove the last line of `main.py`.

### very nice! may i have it in comic sans?

yes! you may do anything that you find to be fun and welcoming :)

Check out the `styles.Styles` enum in the goosepaper library. You will find there what you seek.

## do all dogs' names start with the letter "B"?
### do all dogs' names start with the letter "B"?

I do not think so, but it is a good question!

## may i use this to browse twitter?
### may i use this to browse twitter?

yes you may! you can add a list of usernames to the feed generator and it will make a print-ready version of twitter. this is helpful for when you are on twitter on your laptop but wish you had Other Twitter as well, in print form.

Expand Down
3 changes: 0 additions & 3 deletions frofs/convert.sh

This file was deleted.

7 changes: 0 additions & 7 deletions frofs/pdfonly.frof

This file was deleted.

11 changes: 0 additions & 11 deletions frofs/remarkable.frof

This file was deleted.

79 changes: 56 additions & 23 deletions goosepaper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import feedparser
import requests

from .styles import Styles
from .styles import Style, AutumnStyle


def htmlize(text: str) -> str:
Expand All @@ -29,13 +29,13 @@ def htmlize(text: str) -> str:

def clean_html(html: str) -> str:
html = html.replace("â€TM", "'")
html = re.sub("http[s]?:\/\/[^\s\"']+", "", html)
html = re.sub(r"http[s]?:\/\/[^\s\"']+", "", html)
return html


def clean_text(text: str) -> str:
text = text.replace("â€TM", "'")
text = re.sub("http[s]?:\/\/[^\s\"']+", "", text)
text = re.sub(r"http[s]?:\/\/[^\s\"']+", "", text)
return text


Expand Down Expand Up @@ -123,7 +123,7 @@ def get_stories(self, limit: int = 10) -> List[Story]:
"""
feed = feedparser.parse("https://www.to-rss.xyz/wikipedia/current_events/")
# title = feed.entries[0].title
title = "Today's Current Events (Wiki)"
title = "Today's Current Events"
content = bs4.BeautifulSoup(feed.entries[0].summary)
for a in content.find_all("a"):
while a.find("li"):
Expand Down Expand Up @@ -320,7 +320,7 @@ def get_stories(self, limit: int = 20) -> List[Story]:
Story(
headline=None,
body_text=entry.title,
byline=entry.author,
byline=f"{entry.author} in r/{self.subreddit}",
date=entry.updated_parsed,
placement_preference=PlacementPreference.SIDEBAR,
)
Expand All @@ -334,7 +334,6 @@ def __init__(
story_providers: List[StoryProvider],
title: str = None,
subtitle: str = None,
style: str = Styles.Autumn,
):
self.story_providers = story_providers
self.title = title if title else "Daily Goosepaper"
Expand All @@ -343,8 +342,6 @@ def __init__(
)

def to_html(self) -> str:
style = Styles.Autumn

stories = []
for prov in self.story_providers:
stories.extend(prov.get_stories())
Expand All @@ -371,18 +368,54 @@ def to_html(self) -> str:
if s.placement_preference == PlacementPreference.SIDEBAR
]

return (
"<html><head><style>"
+ style
+ "</style><meta http-equiv='Content-type' content='text/html; charset=utf-8' /><meta charset='UTF-8' /></head><body>"
+ "<div class='header'>"
+ f"<div class='left-ear ear'>{left_ear}</div><div><h1>{self.title}</h1><h4>{self.subtitle}</h4></div><div class='right-ear ear'>{right_ear}</div>"
+ "</div><table class='stories'><tbody>"
+ "<tr><td class='main-stories'>"
+ " <hr />".join(main_stories)
+ "</td>"
+ "<td class='sidebar-stories'>"
+ " <hr />".join(sidebar_stories)
+ "</td>"
+ "</tr></tbody></table></body></html>"
)
return f"""
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta charset="UTF-8" />
</head>
<body>
<div class="header">
<div class="left-ear ear">{left_ear}</div>
<div><h1>{self.title}</h1><h4>{self.subtitle}</h4></div>
<div class="right-ear ear">{right_ear}</div>
</div>
<div class="stories row">
<div class="main-stories column">
{"<hr />".join(main_stories)}
</div>
<div class="sidebar column">
{"<br />".join(sidebar_stories)}
</div>
</div>
</body>
</html>
"""

def to_pdf(self, filename: str, style: Style = AutumnStyle) -> str:
"""
Renders the current Goosepaper to a PDF file on disk.
TODO: If an IO type is provided, write bytes instead.
"""
from weasyprint import HTML, CSS

style = style()

html = self.to_html()
h = HTML(string=html)
c = CSS(string=style.get_css())
h.write_pdf(filename, stylesheets=[c, *style.get_stylesheets()])
return filename


def transfer_file_to_remarkable(fname: str, config_dict: dict = None):
from rmapy.document import ZipDocument
from rmapy.api import Client

rm = Client(config_dict=config_dict)
rm.renew_token()
doc = ZipDocument(doc=fname)
rm.upload(doc)
return True

0 comments on commit fd8b62f

Please sign in to comment.