You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
2.6 KiB
68 lines
2.6 KiB
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):
|
|
response = httpx.get(self.URL+"/reader/api/0/stream/contents?n=100"+"&s="+category, headers=self.headers)
|
|
return response.json()["items"]
|
|
|
|
def getFavorites(self):
|
|
response = httpx.get(self.URL+"/reader/api/0/stream/contents?s=user/-/state/com.google/starred&n=100", headers=self.headers)
|
|
json = response.json()
|
|
return (json["updated"], Utils.timestampToDate(json["updated"]*1000000), json["items"])
|
|
|
|
def markStreamAsRead(self, streamId, ts):
|
|
try:
|
|
response = httpx.post(self.URL+"/reader/api/0/mark-all-as-read", data={"s": streamId, "ts": ts}, headers=self.headers)
|
|
if response.status_code == 200:
|
|
return True
|
|
else:
|
|
return False
|
|
except BaseException:
|
|
return False
|
|
|
|
def toggleArticleStatus(self, articleId, is_read):
|
|
return self.toggleArticleTag(articleId, is_read, "user/-/state/com.google/read")
|
|
|
|
def toggleArticleStarred(self, articleId, is_favorite):
|
|
return self.toggleArticleTag(articleId, is_favorite, "user/-/state/com.google/starred")
|
|
|
|
def toggleArticleTag(self, articleId, is_set, tag):
|
|
if is_set == 0:
|
|
tag_op = 'r'
|
|
else:
|
|
tag_op = 'a'
|
|
try:
|
|
response = httpx.post(self.URL+"/reader/api/0/edit-tag", data={"i": articleId, tag_op: tag},
|
|
headers=self.headers)
|
|
if response.status_code == 200:
|
|
return True
|
|
else:
|
|
return False
|
|
except BaseException:
|
|
return False
|