this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Slightly better error handling

+17 -2
+17 -2
twitter_to_sqlite/utils.py
··· 112 112 113 113 def transform_user(user): 114 114 user["created_at"] = parser.parse(user["created_at"]) 115 - if user["description"] and "description" in user["entities"]: 115 + if user["description"] and "description" in user.get("entities", {}): 116 116 user["description"] = expand_entities( 117 117 user["description"], user["entities"]["description"] 118 118 ) 119 - if user["url"] and "url" in user["entities"]: 119 + if user["url"] and "url" in user.get("entities", {}): 120 120 user["url"] = expand_entities(user["url"], user["entities"]["url"]) 121 121 user.pop("entities", None) 122 122 user.pop("status", None) ··· 319 319 while cursor: 320 320 args["cursor"] = cursor 321 321 r = session.get(url, params=args) 322 + raise_if_error(r) 322 323 body = r.json() 323 324 yield body[key] 324 325 cursor = body["next_cursor"] ··· 326 327 break 327 328 if sleep is not None: 328 329 time.sleep(sleep) 330 + 331 + 332 + class TwitterApiError(Exception): 333 + def __init__(self, headers, body): 334 + self.headers = headers 335 + self.body = body 336 + 337 + def __repr__(self): 338 + return "{}: {}".format(self.body, self.headers) 339 + 340 + 341 + def raise_if_error(r): 342 + if "errors" in r.json(): 343 + raise TwitterApiError(r.headers, r.json()["errors"])