Commit 38be8710 authored by Cody Zacharias's avatar Cody Zacharias Committed by GitHub

Update tweep.py

parent 1af01c97
......@@ -66,6 +66,14 @@ async def getFeed(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):
tweets, init = await getFeed(init)
count = 0
......@@ -84,6 +92,14 @@ async def getTweets(init):
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"]
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:
mentions = tweet.find("div", "js-original-tweet")["data-mentions"].split(" ")
for i in range(len(mentions)):
......@@ -179,6 +195,7 @@ if __name__ == "__main__":
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("--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()
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