Repository: internetarchive/openlibrary

Issue:
Add February carousel to top of homepage
@seabelis has created a collection for February! Let's add it to the top of the home page as "Books for February". We want:

- [ ] A search query that summarizes the collection so that books appear on the homepage (here's the literal aggregate of all the carousels: https://openlibrary.org/search?mode=everything&q=subject%3A%22february%22+OR++subject%3A%22groundhog+day%22+OR++subject%3A%22valentines+day%22+OR++subject%3A%22heart%22+OR++subject%3A%22black+history%22+OR++key%3A%28%2Fworks%2FOL3912087W+OR+%2Fworks%2FOL19728320W+OR+%2Fworks%2FOL19666828W+OR+%2Fworks%2FOL3459949W+OR+%2Fworks%2FOL66728W+OR+%2Fworks%2FOL17768453W+OR+%2Fworks%2FOL16190571W+OR+%2Fworks%2FOL15160873W+OR+%2Fworks%2FOL8275668W+OR+%2Fworks%2FOL17211582W+OR+%2Fworks%2FOL17628545W+OR+%2Fworks%2FOL20163236W+OR+%2Fworks%2FOL20153225W++OR+%2Fworks%2FOL17371695W%29+OR++subject%3A%22canned+food%22+OR++subject%3A%22friendship%22+OR++subject%3A%22pie%22+OR++subject%3A%22libraries%22+OR++subject%3A%22baking%22+OR++title%3A%22bird+feeding%22+OR++title%3A%22cat+health%22+OR++subject%3A%22cherries%22+OR++subject%3A%22Childrens+Dental+Health%22+OR++title%3A%22Childrens+Dental+Health%22+OR++subject%3A%22Embroidery%22+OR++title%3A%22Grapefruit%22+OR++subject%3A%22hot+breakfast%22+OR++title%3A%22hot+breakfast%22+OR++subject%3A%22snack+food%22+OR++title%3A%22Youth+Leadership%22+OR++title%3A%22Teen+Dating+Violence%22&has_fulltext=true , but the results aren't super great. Maybe @seabelis can come up with one?)
- [ ] The carousel should link to the collection: https://openlibrary.org/collections/february

### Describe the problem that you'd like solved
Showcase the February collection :)

### Proposal & Constraints
- Note: We might have to do some stuff to make sure it caches (I don't believe it caches by default)

### Additional context
- https://github.com/internetarchive/openlibrary/blob/ce81c3986dae8bce9df8e4d81b17578f30454d1b/openlibrary/templates/home/index.html#L21

### Stakeholders
@seabelis @Sabreen-Parveen 





Discussion:
@Sabreen-Parveen would you be interested in giving this one a shot? Might be a _bit_ tricky, though :)

(Pre-emptive: the homepage is cached, so if you make changes to its template, they won't show up automatically in your local environment. You can change this function to call `get_homepage` instead of `get_cached_homepage` to make it skip caching: https://github.com/internetarchive/openlibrary/blob/37445028e7ad2f11410bd0a94d4bae45be37b246/openlibrary/plugins/openlibrary/home.py#L62-L67 )
Sure @cdrini, I would like to work on it and will ask you whenever I get stuck :)
It's a strange thing. Individually searching subjects "groundhog day" or "valentines day" does not include "Laws", "Alice's Adventures in Wonderland", or "Hamlet" in results. In combination they do.
> It's a strange thing. Individually searching subjects "groundhog day" or "valentines day" does not include "Laws", "Alice's Adventures in Wonderland", or "Hamlet" in results. In combination they do.

Nah, that just results in a bad query, but it's silently ignoring it instead of giving you an error message. Try `subject:("groundhog day" OR "valentines day")`

Having said that, Groundhog Day seems pretty culture-specific. Is this going to be geo-restricted to patrons from the U.S.?
@tfmorris Yes, that query works better. No, this will not be geo-restricted, but those two subjects were an example, not the entire query.
So I believe some of the strange results are due to "open library staff picks" as a subject. This pulls them in for the "library" subject search even though that's not a subject of the materials. 
[subject:("february" OR  "groundhog day" OR  "valentines day" OR  "heart" OR  "black history" OR "lgbt history" OR "canned food" OR "friendship" OR "pie" OR "baking" OR "bird feeding" OR "cat health" OR "cherries" OR "children's dental health" OR "embroidery" OR "grapefruit" OR "hot breakfast" OR "snack food" OR "youth leadership" OR "teen dating violence")](https://openlibrary.org/search?q=subject%3A%28%22february%22+OR++%22groundhog+day%22+OR++%22valentines+day%22+OR++%22heart%22+OR++%22black+history%22+OR+%22lgbt+history%22+OR+%22canned+food%22+OR+%22friendship%22+OR+%22pie%22+OR+%22baking%22+OR+%22bird+feeding%22+OR+%22cat+health%22+OR+%22cherries%22+OR+%22children%27s+dental+health%22+OR+%22embroidery%22+OR+%22grapefruit%22+OR+%22hot+breakfast%22+OR+%22snack+food%22+OR+%22youth+leadership%22+OR+%22teen+dating+violence%22%29&mode=everything)

works better. It's a shame to leave "library" out, but unless "Open Library Staff Picks" is eliminated as a subject, it is a useless query.

Yeah, still a bit of noise with those classic books sneaking in. I think your idea to use work keys directly might be better. I created a little JS snippet that pulls them off of the collection page. This chooses a random 100 books on the page and generates a query.

```js
await import('https://unpkg.com/lodash@4.17.0');
var books = _.shuffle($$('.book-cover a').map(el => el.href.split('/')[4]).map(olid => `/works/${olid}`)).slice(0,100);
var query = `key:(${books.join(' OR ')})`
console.log(`https://openlibrary.org/search?q=${encodeURIComponent(query)}&mode=everything`);
```

I ran it a few times (each time generates a new query, since it randomly selects), and this one seemed good: https://openlibrary.org/search?q=key%3A(%2Fworks%2FOL5099301W%20OR%20%2Fworks%2FOL20900813W%20OR%20%2Fworks%2FOL19974130W%20OR%20%2Fworks%2FOL21376789W%20OR%20%2Fworks%2FOL21179764W%20OR%20%2Fworks%2FOL491675W%20OR%20%2Fworks%2FOL20848742W%20OR%20%2Fworks%2FOL5730175W%20OR%20%2Fworks%2FOL3496457W%20OR%20%2Fworks%2FOL18023357W%20OR%20%2Fworks%2FOL16910779W%20OR%20%2Fworks%2FOL16662711W%20OR%20%2Fworks%2FOL20857543W%20OR%20%2Fworks%2FOL20632743W%20OR%20%2Fworks%2FOL19729253W%20OR%20%2Fworks%2FOL17314666W%20OR%20%2Fworks%2FOL20858133W%20OR%20%2Fworks%2FOL21672239W%20OR%20%2Fworks%2FOL19757671W%20OR%20%2Fworks%2FOL1928280W%20OR%20%2Fworks%2FOL17874444W%20OR%20%2Fworks%2FOL20783908W%20OR%20%2Fworks%2FOL18335154W%20OR%20%2Fworks%2FOL4114499W%20OR%20%2Fworks%2FOL20872535W%20OR%20%2Fworks%2FOL20153225W%20OR%20%2Fworks%2FOL2639036W%20OR%20%2Fworks%2FOL20207960W%20OR%20%2Fworks%2FOL20544657W%20OR%20%2Fworks%2FOL20854371W%20OR%20%2Fworks%2FOL17869588W%20OR%20%2Fworks%2FOL440489W%20OR%20%2Fworks%2FOL3191599W%20OR%20%2Fworks%2FOL8275668W%20OR%20%2Fworks%2FOL17102898W%20OR%20%2Fworks%2FOL17721078W%20OR%20%2Fworks%2FOL20007451W%20OR%20%2Fworks%2FOL21180618W%20OR%20%2Fworks%2FOL20848626W%20OR%20%2Fworks%2FOL19972590W%20OR%20%2Fworks%2FOL1486478W%20OR%20%2Fworks%2FOL11952386W%20OR%20%2Fworks%2FOL19994722W%20OR%20%2Fworks%2FOL7870775W%20OR%20%2Fworks%2FOL20646859W%20OR%20%2Fworks%2FOL4648142W%20OR%20%2Fworks%2FOL11999803W%20OR%20%2Fworks%2FOL16515210W%20OR%20%2Fworks%2FOL15279153W%20OR%20%2Fworks%2FOL20849927W%20OR%20%2Fworks%2FOL21179974W%20OR%20%2Fworks%2FOL3521634W%20OR%20%2Fworks%2FOL16097454W%20OR%20%2Fworks%2FOL9371452W%20OR%20%2Fworks%2FOL4802599W%20OR%20%2Fworks%2FOL20030448W%20OR%20%2Fworks%2FOL3296483W%20OR%20%2Fworks%2FOL17371695W%20OR%20%2Fworks%2FOL22062636W%20OR%20%2Fworks%2FOL8990067W%20OR%20%2Fworks%2FOL7213898W%20OR%20%2Fworks%2FOL19708155W%20OR%20%2Fworks%2FOL17358927W%20OR%20%2Fworks%2FOL20853865W%20OR%20%2Fworks%2FOL20548582W%20OR%20%2Fworks%2FOL16876826W%20OR%20%2Fworks%2FOL13655581W%20OR%20%2Fworks%2FOL4370955W%20OR%20%2Fworks%2FOL2977588W%20OR%20%2Fworks%2FOL21078916W%20OR%20%2Fworks%2FOL20133929W%20OR%20%2Fworks%2FOL16617686W%20OR%20%2Fworks%2FOL5706069W%20OR%20%2Fworks%2FOL15691480W%20OR%20%2Fworks%2FOL17755326W%20OR%20%2Fworks%2FOL15933199W%20OR%20%2Fworks%2FOL17893385W%20OR%20%2Fworks%2FOL17411311W%20OR%20%2Fworks%2FOL17933439W%20OR%20%2Fworks%2FOL4622460W%20OR%20%2Fworks%2FOL16025481W%20OR%20%2Fworks%2FOL17640891W%20OR%20%2Fworks%2FOL20053695W%20OR%20%2Fworks%2FOL19996443W%20OR%20%2Fworks%2FOL19854767W%20OR%20%2Fworks%2FOL4582875W%20OR%20%2Fworks%2FOL15285884W%20OR%20%2Fworks%2FOL17340085W%20OR%20%2Fworks%2FOL20022939W%20OR%20%2Fworks%2FOL9242636W%20OR%20%2Fworks%2FOL519219W%20OR%20%2Fworks%2FOL17566265W%20OR%20%2Fworks%2FOL22074932W%20OR%20%2Fworks%2FOL20907796W%20OR%20%2Fworks%2FOL20879942W%20OR%20%2Fworks%2FOL22059158W%20OR%20%2Fworks%2FOL17430949W%20OR%20%2Fworks%2FOL20935567W%20OR%20%2Fworks%2FOL18646141W%20OR%20%2Fworks%2FOL19646242W)&mode=everything
Many of those classics are valid. "Friendship" is pretty broad and does include Twain, Carroll, etc. But I think I like your approach better.

Resolving patch:
diff --git a/openlibrary/plugins/upstream/utils.py b/openlibrary/plugins/upstream/utils.py
--- a/openlibrary/plugins/upstream/utils.py
+++ b/openlibrary/plugins/upstream/utils.py
@@ -818,6 +818,11 @@ def render_once(key):
         return True
 
 
+@public
+def today():
+    return datetime.datetime.today()
+
+
 def setup():
     """Do required initialization"""
     # monkey-patch get_markdown to use OL Flavored Markdown


Test patch: