import httpx import Utils class Fetcher: def __init__(self, URL, token): self.URL = URL self.token = token self.headers = {"Authorization": "GoogleLogin auth="+token} self.articles = {} def refresh(self): self.getUnreadCounts() self.getSubscriptions() def getUnreadCounts(self): response = httpx.get(self.URL+"/reader/api/0/unread-count?output=json", headers=self.headers) result = dict([(item["id"], (item["count"], item["newestItemTimestampUsec"], Utils.timestampToDate( item["newestItemTimestampUsec"]))) for item in response.json()["unreadcounts"]]) self.unreadCounts = result def getSubscriptions(self): response = httpx.get(self.URL+"/reader/api/0/subscription/list?output=json", headers=self.headers) self.feeds = response.json()["subscriptions"] def checkCategory(self, category): return category in self.articles.keys() def articlesFromCategory(self, category, count=0, timestamp=0, number=0): if number == 0: response = httpx.get(self.URL+"/reader/api/0/stream/contents?n="+count+"&s="+category, headers=self.headers) else: response = httpx.get(self.URL+"/reader/api/0/stream/contents?ot="+timestamp+"&s=" + category, headers=self.headers) return response.json()["items"] def toggleArticleStatus(self, articleId, is_read): if is_read == 0: tag_op = 'r' else: tag_op = 'a' try: response = httpx.post(self.URL+"/reader/api/0/edit-tag", data={"i": articleId, tag_op: "user/-/state/com.google/read"}, headers=self.headers) if response.status_code == 200: return True else: return False except BaseException: return False