4 ms·
Cool project. I do something similar for the daily free ebook from Packt. Also for when new episodes of Silicon Valley are posted. Tiny detail - you can do t
by tedmiston 10y ago
Cool project. I do something similar for the daily free ebook from Packt. Also for when new episodes of Silicon Valley are posted.
Tiny detail - you can do the regex match case insensitive and avoid the call to lower() for every string.
re.match(..., re.I)
- jamesbvaughan 10y agoOh cool, thanks for that!
- column 10y agoSeems to me you don't need regex, nor the call to list() at all for that free_food = [s for s in soup.stripped_strings if "free" in s.lower()] works
- js2 10y agoYou can also avoid building the list and terminate at the first true value with `any`: free_food = any(s for s in soup.stripped_strings if ...)
- tedmiston 10y agoWell on that note, if you just want the boolean, I think it'd be enough to say: free_food = 'free' in soup.get_text().lower()
- jamesbvaughan 10y agoOh even better. I'm kind of new to Python, so I hadn't seen that before!
- dmn001 10y agoRight, if you're just matching a substring in a list of strings then you don't need regex for that. Also, lxml is over 20x faster than BeautifulSoup, although it doesn't really matter with such a low frequency of requests, it's something to note if you had another project that required parsing e.g. 1,000's of html pages.
- ge96 10y agoIs the 4th season airing already?
- joshschreuder 10y agoNope, it's back April 24th
- ge96 10y agoAhh nice something to look forward to in life haha
- douche 10y agoDo you have that Packt script handy? There's a lot of junk that gets put up there, but also some gems. Unfortunately it seems like the gems are always on the days I don't check it...
- tedmiston 10y agoFor Packt, I'm just using ChangeDetection.com with an email alert. I noticed in the stats for that URL that others are doing the same. It's super easy to setup.
- tedmiston 10y agoSo today I noticed that they announced additional free ebooks on twitter besides the daily one. I'm thinking of writing custom code now that subscribes to their tweets and filters for mention of free. May be doable with IFTTT.