Changeset 13 in feed2telegram


Ignore:
Timestamp:
10/09/18 19:44:51 (6 years ago)
Author:
cheese
Message:

#1 apply cloudflare-scrape

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/feed2telegram.py

    r12 r13  
    8181        return time.mktime(timetuple)
    8282
     83class Cloudflare:
     84    @staticmethod
     85    def check(response):
     86        return response.status_code == 503 and 'DDoS protection by Cloudflare' in response.content
     87
     88    @staticmethod
     89    def get(*args, **kwargs):
     90        import cfscrape
     91        return cfscrape.create_scraper().get(*args, **kwargs)
     92
    8393class Feed:
    8494    def __init__(self, url):
     
    122132        try:
    123133            resp = requests.get(self.url, timeout=10.0)
     134            if Cloudflare.check(resp):
     135                resp = Cloudflare.get(self.url, timeout=10.0)
    124136        except requests.ReadTimeout as e:
    125137            raise
Note: See TracChangeset for help on using the changeset viewer.