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

Merge branch 'dev' into master

parents f499c31b 01c744ae
...@@ -69,6 +69,14 @@ async def getFeed(init): ...@@ -69,6 +69,14 @@ async def getFeed(init):
return feed, init return feed, init
async def getPic(url):
async with aiohttp.ClientSession() as session:
r = await fetch(session, url)
soup = BeautifulSoup(r, "html.parser")
picture = soup.find("div", "AdaptiveMedia-photoContainer js-adaptive-photo ")
if picture is not None:
return picture["data-image-url"].replace(" ", "")
async def getTweets(init): async def getTweets(init):
tweets, init = await getFeed(init) tweets, init = await getFeed(init)
count = 0 count = 0
...@@ -87,6 +95,14 @@ async def getTweets(init): ...@@ -87,6 +95,14 @@ async def getTweets(init):
replies = tweet.find("span", "ProfileTweet-action--reply u-hiddenVisually").find("span")["data-tweet-stat-count"] 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"] 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"] likes = tweet.find("span", "ProfileTweet-action--favorite u-hiddenVisually").find("span")["data-tweet-stat-count"]
if arg.rawpic and "pic.twitter.com" in text:
try:
picture = await getPic("https://twitter.com/{0}/status/{1}/photo/1".format(username, tweetid))
if picture is not None:
pic = re.findall(r"pic.twitter.com/\w+", text)[-1]
text = text.replace(pic, picture)
except:
pass
try: try:
mentions = tweet.find("div", "js-original-tweet")["data-mentions"].split(" ") mentions = tweet.find("div", "js-original-tweet")["data-mentions"].split(" ")
for i in range(len(mentions)): for i in range(len(mentions)):
...@@ -183,6 +199,7 @@ if __name__ == "__main__": ...@@ -183,6 +199,7 @@ if __name__ == "__main__":
ap.add_argument("--limit", help="Number of Tweets to pull (Increments of 20).") ap.add_argument("--limit", help="Number of Tweets to pull (Increments of 20).")
ap.add_argument("--count", help="Display number Tweets scraped at the end of session.", action="store_true") ap.add_argument("--count", help="Display number Tweets scraped at the end of session.", action="store_true")
ap.add_argument("--stats", help="Show number of replies, retweets, and likes", action="store_true") ap.add_argument("--stats", help="Show number of replies, retweets, and likes", action="store_true")
ap.add_argument("--rawpic", help="Display raw picture URL (Slow).", action="store_true")
arg = ap.parse_args() arg = ap.parse_args()
check() check()
......
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