Skip to content

Instantly share code, notes, and snippets.

@WillisN
Created September 29, 2020 02:03
Show Gist options
  • Save WillisN/5a9259efd99cedb6e18b5187823d686b to your computer and use it in GitHub Desktop.
Save WillisN/5a9259efd99cedb6e18b5187823d686b to your computer and use it in GitHub Desktop.
send_tweets_to_spark
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