@@ -53,6 +53,7 @@ def __init__(self, app_id, app_key, access_token, refresh_token,
5353 'Authorization' : 'Bearer {}' .format (self .access_token )
5454 })
5555 self .config_manager = config_manager
56+ self .proxies = self .config_manager .proxies if config_manager else None
5657
5758 def check_token (self ):
5859 now = datetime .now ().timestamp ()
@@ -76,7 +77,7 @@ def refresh_access_token(self):
7677 'grant_type' : 'refresh_token' ,
7778 'refresh_token' : self .refresh_token ,
7879 }
79- response = self .parse_response (requests .post (url , json = payload ))
80+ response = self .parse_response (requests .post (url , json = payload , proxies = self . proxies ))
8081 self .access_token = response ['access_token' ]
8182 self .refresh_token = response ['refresh_token' ]
8283 self .expires_at = datetime .now ().timestamp () + response ['expires_in' ]
@@ -92,14 +93,14 @@ def userinfo(self):
9293 self .check_token ()
9394
9495 url = urljoin (BASE_URL , self .USER_INFO_PATH )
95- return self .parse_response (self .session .post (url ))
96+ return self .parse_response (self .session .post (url , proxies = self . proxies ))
9697
9798 def get_folders (self ):
9899 self .check_token ()
99100
100101 url = urljoin (BASE_URL , self .TAG_LIST_PATH )
101102 params = {'types' : 1 , 'counts' : 1 }
102- response = self .parse_response (self .session .post (url , params = params ))
103+ response = self .parse_response (self .session .post (url , params = params , proxies = self . proxies ))
103104
104105 folders = []
105106 for item in response ['tags' ]:
@@ -117,7 +118,7 @@ def get_tags(self):
117118
118119 url = urljoin (BASE_URL , self .TAG_LIST_PATH )
119120 params = {'types' : 1 , 'counts' : 1 }
120- response = self .parse_response (self .session .post (url , params = params ))
121+ response = self .parse_response (self .session .post (url , params = params , proxies = self . proxies ))
121122
122123 tags = []
123124 for item in response ['tags' ]:
@@ -134,7 +135,7 @@ def get_subscription_list(self):
134135 self .check_token ()
135136
136137 url = urljoin (BASE_URL , self .SUBSCRIPTION_LIST_PATH )
137- response = self .parse_response (self .session .get (url ))
138+ response = self .parse_response (self .session .get (url , proxies = self . proxies ))
138139 for item in response ['subscriptions' ]:
139140 yield Subscription .from_json (item )
140141
@@ -156,7 +157,7 @@ def __get_stream_contents(self, stream_id, continuation=''):
156157 'c' : continuation ,
157158 'output' : 'json'
158159 }
159- response = self .parse_response (self .session .post (url , params = params ))
160+ response = self .parse_response (self .session .post (url , params = params , proxies = self . proxies ))
160161 if 'continuation' in response ():
161162 return response ['items' ], response ['continuation' ]
162163 else :
@@ -173,7 +174,7 @@ def fetch_unread(self, folder=None, tags=None):
173174 )
174175 params = {'xt' : self .READ_TAG , 'c' : str (uuid4 ())}
175176
176- response = self .parse_response (self .session .post (url , params = params ))
177+ response = self .parse_response (self .session .post (url , params = params , proxies = self . proxies ))
177178 for data in response ['items' ]:
178179 categories = set ([
179180 category .split ('/' )[- 1 ] for category in data .get ('categories' , [])
@@ -186,7 +187,9 @@ def fetch_unread(self, folder=None, tags=None):
186187 continuation = response .get ('continuation' )
187188 while continuation :
188189 params ['c' ] = continuation
189- response = self .parse_response (self .session .post (url , params = params ))
190+ response = self .parse_response (
191+ self .session .post (url , params = params , proxies = self .proxies )
192+ )
190193 for data in response ['items' ]:
191194 categories = set ([
192195 category .split ('/' )[- 1 ] for category in data .get ('categories' , [])
@@ -207,7 +210,10 @@ def add_general_label(self, articles, label):
207210 'a' : label ,
208211 'i' : [articles [idx ].id for idx in range (start , end )]
209212 }
210- self .parse_response (self .session .post (url , params = params ), json_data = False )
213+ self .parse_response (
214+ self .session .post (url , params = params , proxies = self .proxies ),
215+ json_data = False
216+ )
211217
212218 def add_tag (self , articles , tag ):
213219 self .add_general_label (articles , self .GENERAL_TAG_TEMPLATE .format (tag ))
0 commit comments