Commit 53183006 authored by Cody Zacharias's avatar Cody Zacharias Committed by GitHub

Fix break from copyright Tweets

parent da5b7f70
...@@ -69,63 +69,60 @@ async def getFeed(init): ...@@ -69,63 +69,60 @@ async def getFeed(init):
return feed, init return feed, init
async def getPic(url): async def outTweet(tweet):
async with aiohttp.ClientSession() as session: tweetid = tweet["data-item-id"]
r = await fetch(session, url) datestamp = tweet.find("a", "tweet-timestamp")["title"].rpartition(" - ")[-1]
soup = BeautifulSoup(r, "html.parser") d = datetime.datetime.strptime(datestamp, "%d %b %Y")
picture = soup.find("div", "AdaptiveMedia-photoContainer js-adaptive-photo ") date = d.strftime("%Y-%m-%d")
if picture is not None: timestamp = str(datetime.timedelta(seconds=int(tweet.find("span", "_timestamp")["data-time"]))).rpartition(", ")[-1]
return picture["data-image-url"].replace(" ", "") t = datetime.datetime.strptime(timestamp, "%H:%M:%S")
time = t.strftime("%H:%M:%S")
username = tweet.find("span", "username").text.replace("@", "")
timezone = strftime("%Z", gmtime())
text = tweet.find("p", "tweet-text").text.replace("\n", "").replace("http", " http").replace("pic.twitter", " pic.twitter")
hashtags = ",".join(re.findall(r'(?i)\#\w+', text, flags=re.UNICODE))
replies = tweet.find("span", "ProfileTweet-action--reply u-hiddenVisually").find("span")["data-tweet-stat-count"]
retweets = tweet.find("span", "ProfileTweet-action--retweet u-hiddenVisually").find("span")["data-tweet-stat-count"]
likes = tweet.find("span", "ProfileTweet-action--favorite u-hiddenVisually").find("span")["data-tweet-stat-count"]
try:
mentions = tweet.find("div", "js-original-tweet")["data-mentions"].split(" ")
for i in range(len(mentions)):
mention = "@{}".format(mentions[i])
if mention not in text:
text = "{} {}".format(mention, text)
except:
pass
if arg.users:
output = username
elif arg.tweets:
output = tweets
else:
output = "{} {} {} {} <{}> {}".format(tweetid, date, time, timezone, username, text)
if arg.hashtags:
output+= " {}".format(hashtags)
if arg.stats:
output+= " | {} replies {} retweets {} likes".format(replies, retweets, likes)
if arg.o != None:
if arg.csv:
dat = [tweetid, date, time, timezone, username, text, replies, retweets, likes, hashtags]
with open(arg.o, "a", newline='') as csv_file:
writer = csv.writer(csv_file, delimiter="|")
writer.writerow(dat)
else:
print(output, file=open(arg.o, "a"))
return output
async def getTweets(init): async def getTweets(init):
tweets, init = await getFeed(init) tweets, init = await getFeed(init)
count = 0 count = 0
for tweet in tweets: for tweet in tweets:
tweetid = tweet["data-item-id"] copyright = tweet.find("div","StreamItemContent--withheld")
datestamp = tweet.find("a", "tweet-timestamp")["title"].rpartition(" - ")[-1] if copyright is None:
d = datetime.datetime.strptime(datestamp, "%d %b %Y") count +=1
date = d.strftime("%Y-%m-%d") print(await outTweet(tweet))
timestamp = str(datetime.timedelta(seconds=int(tweet.find("span", "_timestamp")["data-time"]))).rpartition(", ")[-1]
t = datetime.datetime.strptime(timestamp, "%H:%M:%S")
time = t.strftime("%H:%M:%S")
username = tweet.find("span", "username").text.replace("@", "")
timezone = strftime("%Z", gmtime())
text = tweet.find("p", "tweet-text").text.replace("\n", " ").replace("http"," http").replace("pic.twitter"," pic.twitter")
hashtags = ",".join(re.findall(r'(?i)\#\w+', text, flags=re.UNICODE))
replies = tweet.find("span", "ProfileTweet-action--reply u-hiddenVisually").find("span")["data-tweet-stat-count"]
retweets = tweet.find("span", "ProfileTweet-action--retweet u-hiddenVisually").find("span")["data-tweet-stat-count"]
likes = tweet.find("span", "ProfileTweet-action--favorite u-hiddenVisually").find("span")["data-tweet-stat-count"]
try:
mentions = tweet.find("div", "js-original-tweet")["data-mentions"].split(" ")
for i in range(len(mentions)):
mention = "@{}".format(mentions[i])
if mention not in text:
text = "{} {}".format(mention, text)
except:
pass
if arg.users:
output = username
elif arg.tweets:
output = tweets
else:
output = "{} {} {} {} <{}> {}".format(tweetid, date, time, timezone, username, text)
if arg.hashtags:
output+= " {}".format(hashtags)
if arg.stats:
output+= " | {} replies {} retweets {} likes".format(replies, retweets, likes)
if arg.o != None:
if arg.csv:
dat = [tweetid, date, time, timezone, username, text, hashtags, replies, retweets, likes]
with open(arg.o, "a", newline='') as csv_file:
writer = csv.writer(csv_file, delimiter="|")
writer.writerow(dat)
else:
print(output, file=open(arg.o, "a"))
count += 1
print(output)
return tweets, init, count return tweets, init, count
......
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