Commit 312e4755 authored by Cody Zacharias's avatar Cody Zacharias Committed by GitHub

Add mentions field

parent 387245a6
...@@ -29,7 +29,8 @@ def writeCSV(Tweet, config): ...@@ -29,7 +29,8 @@ def writeCSV(Tweet, config):
"hashtags": Tweet.hashtags, "hashtags": Tweet.hashtags,
"link": Tweet.link, "link": Tweet.link,
"retweet": Tweet.is_retweet, "retweet": Tweet.is_retweet,
"user_rt": Tweet.user_rt "user_rt": Tweet.user_rt,
"mentions": Tweet.mentions,
} }
if config.Custom_csv: if config.Custom_csv:
...@@ -53,7 +54,8 @@ def writeCSV(Tweet, config): ...@@ -53,7 +54,8 @@ def writeCSV(Tweet, config):
"hashtags", "hashtags",
"link", "link",
"retweet", "retweet",
"user_rt" "user_rt",
"mentions",
] ]
row = data row = data
...@@ -82,7 +84,8 @@ def writeJSON(Tweet, file): ...@@ -82,7 +84,8 @@ def writeJSON(Tweet, file):
"hashtags": ",".join(Tweet.hashtags), "hashtags": ",".join(Tweet.hashtags),
"link": Tweet.link, "link": Tweet.link,
"retweet": Tweet.is_retweet, "retweet": Tweet.is_retweet,
"user_rt": Tweet.user_rt "user_rt": Tweet.user_rt,
"mentions": ",".join(Tweet.mentions)
} }
with open(file, "a", newline='', encoding="utf-8") as json_file: with open(file, "a", newline='', encoding="utf-8") as json_file:
...@@ -105,9 +108,14 @@ def getStat(tweet, stat): ...@@ -105,9 +108,14 @@ def getStat(tweet, stat):
st = "ProfileTweet-action--{} u-hiddenVisually".format(stat) st = "ProfileTweet-action--{} u-hiddenVisually".format(stat)
return tweet.find("span", st).find("span")["data-tweet-stat-count"] return tweet.find("span", st).find("span")["data-tweet-stat-count"]
def getMentions(tweet, text): def getMentions(tweet):
try:
return tweet.find("div", "js-original-tweet")["data-mentions"].split(" ")
except:
return ""
def textMentions(tweet, mentions, text):
try: try:
mentions = tweet.find("div", "js-original-tweet")["data-mentions"].split(" ")
for i in range(len(mentions)): for i in range(len(mentions)):
mention = "@{}".format(mentions[i]) mention = "@{}".format(mentions[i])
if mention not in text: if mention not in text:
...@@ -141,7 +149,8 @@ def getTweet(tw, location, config): ...@@ -141,7 +149,8 @@ def getTweet(tw, location, config):
t.timezone = strftime("%Z", localtime()) t.timezone = strftime("%Z", localtime())
for img in tw.findAll("img", "Emoji Emoji--forText"): for img in tw.findAll("img", "Emoji Emoji--forText"):
img.replaceWith("<{}>".format(img['aria-label'])) img.replaceWith("<{}>".format(img['aria-label']))
t.tweet = getMentions(tw, getText(tw)) t.mentions = getMentions(tw)
t.tweet = textMentions(tw, t.mentions, getText(tw))
t.location = location t.location = location
t.hashtags = getHashtags(t.tweet) t.hashtags = getHashtags(t.tweet)
t.replies = getStat(tw, "reply") t.replies = getStat(tw, "reply")
...@@ -181,6 +190,7 @@ def getOutput(Tweet, config, conn): ...@@ -181,6 +190,7 @@ def getOutput(Tweet, config, conn):
output = output.replace("{link}", Tweet.link) output = output.replace("{link}", Tweet.link)
output = output.replace("{is_retweet}", Tweet.is_retweet) output = output.replace("{is_retweet}", Tweet.is_retweet)
output = output.replace("{user_rt}", Tweet.user_rt) output = output.replace("{user_rt}", Tweet.user_rt)
output = output.replace("{mentions}", Tweet.mentions)
else: else:
output = "{} {} {} {} ".format(Tweet.id, Tweet.datestamp, output = "{} {} {} {} ".format(Tweet.id, Tweet.datestamp,
Tweet.timestamp, Tweet.timezone) Tweet.timestamp, Tweet.timezone)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment