Skip to content

Commit 21b958c

Browse files
committedSep 24, 2021
Handle null character in tweet text and user bio
1 parent f664d1d commit 21b958c

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed
 

‎twitter/helper.py

100644100755
+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import os
22
import sys
33
import json
4-
import psycopg2
54
from pprint import pprint
65
from dateutil import parser
76
from datetime import datetime
@@ -279,7 +278,6 @@ def get_ref_relations(tweets, ref_id2author_id, author_id2n_followers,
279278
tweet_id2ref_type2n_followers = dict()
280279
for tweet in tweets:
281280
tweet_id = tweet['id']
282-
ref_id2ref_type = dict()
283281
tweet_id2ref_type2author[tweet_id] = dict()
284282
tweet_id2ref_type2n_followers[tweet_id] = dict()
285283

@@ -401,7 +399,7 @@ def get_tweet_insert(tweet, event, query_type, direct):
401399
'directly_from_quote_search': False,
402400
'from_timeline_search': False,
403401
'directly_from_timeline_search': False,
404-
'text': tweet['text'],
402+
'text': tweet['text'].replace('\x00', ''),
405403
'lang': tweet['lang'],
406404
'author_id': tweet['author_id'],
407405
'created_at': parser.parse(tweet['created_at']),
@@ -498,7 +496,7 @@ def get_user_insert(user, event):
498496

499497
for f in ['description', 'location', 'pinned_tweet_id']:
500498
try:
501-
user_insert[f] = user[f]
499+
user_insert[f] = user[f].replace('\x00', '')
502500
except KeyError:
503501
user_insert[f] = None
504502

0 commit comments

Comments
 (0)
Please sign in to comment.