|  |  |  | @ -142,6 +142,14 @@ def parse_entities(entity): | 
			
		
	
		
			
				
					|  |  |  |  |     if "display_url" in entity: data["text"] = entity["display_url"] | 
			
		
	
		
			
				
					|  |  |  |  |     return data | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | def parse_card(card): | 
			
		
	
		
			
				
					|  |  |  |  |     data = {} | 
			
		
	
		
			
				
					|  |  |  |  |     for v in card["legacy"]["binding_values"]: | 
			
		
	
		
			
				
					|  |  |  |  |         if "choice" in v["key"] or v["key"] in ["end_datetime_utc"]: | 
			
		
	
		
			
				
					|  |  |  |  |             value_name = f"{v['value']['type'].lower()}_value" | 
			
		
	
		
			
				
					|  |  |  |  |             data[v["key"]] = v['value'].get(value_name, "") | 
			
		
	
		
			
				
					|  |  |  |  |     return data | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | def parse_tweet(tweet): | 
			
		
	
		
			
				
					|  |  |  |  |     # with open("tweet.json", "w") as f: json.dump(tweet, f) | 
			
		
	
		
			
				
					|  |  |  |  |     while not "rest_id" in tweet: tweet = tweet["tweet"] | 
			
		
	
	
		
			
				
					|  |  |  | @ -157,7 +165,8 @@ def parse_tweet(tweet): | 
			
		
	
		
			
				
					|  |  |  |  |         "media": [], | 
			
		
	
		
			
				
					|  |  |  |  |         "entities": [], | 
			
		
	
		
			
				
					|  |  |  |  |         "quoted": {}, | 
			
		
	
		
			
				
					|  |  |  |  |         "retweeted": {} | 
			
		
	
		
			
				
					|  |  |  |  |         "retweeted": {}, | 
			
		
	
		
			
				
					|  |  |  |  |         "card": {} | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  |      | 
			
		
	
		
			
				
					|  |  |  |  |     for m in tweet["legacy"]["entities"].get("media", []): | 
			
		
	
	
		
			
				
					|  |  |  | @ -168,6 +177,9 @@ def parse_tweet(tweet): | 
			
		
	
		
			
				
					|  |  |  |  |             data["entities"].append(parse_entities(m)) | 
			
		
	
		
			
				
					|  |  |  |  |     data["entities"].sort(key=lambda x: x["indices"][0]) | 
			
		
	
		
			
				
					|  |  |  |  |      | 
			
		
	
		
			
				
					|  |  |  |  |     if "card" in tweet: | 
			
		
	
		
			
				
					|  |  |  |  |         data["card"] = parse_card(tweet["card"]) | 
			
		
	
		
			
				
					|  |  |  |  |      | 
			
		
	
		
			
				
					|  |  |  |  |     return data | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  |  | 
 |