Created
September 29, 2020 02:03
-
-
Save WillisN/5a9259efd99cedb6e18b5187823d686b to your computer and use it in GitHub Desktop.
send_tweets_to_spark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def send_tweets_to_spark(http_resp, tcp_connection): | |
for line in http_resp.iter_lines(): | |
try: | |
full_tweet = json.loads(line) | |
datetime = full_tweet['created_at'][:20] | |
tweet = full_tweet['text'] | |
print (f"---------------{datetime}--------------------------") | |
print(tweet) | |
tcp_connection.send(bytes(tweet, "utf-8")) | |
except: | |
e = sys.exc_info()[0] | |
print("Error : %s" % e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment