Last active
April 15, 2017 02:27
-
-
Save jonathan-ostrander/cff4de65e02f9bca43ea to your computer and use it in GitHub Desktop.
Tweets random YouPorn Comments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import requests | |
from bs4 import BeautifulSoup as bsoup | |
import tweepy | |
def findTweet(): | |
tweet = "" | |
while True: | |
r = requests.get("http://www.youporn.com/random/video/") | |
pornsoup = bsoup(r.text) | |
comments = [a.string for a in pornsoup.find_all('p', attrs={'class':'message'})] | |
while comments: | |
comment = comments.pop(random.choice(range(len(comments)))) | |
if len(comment) <= 140: | |
tweet = comment | |
break | |
if tweet: | |
return tweet | |
def postTweet(tweet): | |
consumer_key, consumer_secret, access_token, access_token_secret = "consumer_key", "consumer_secret", "access_token", "access_token_secret" | |
auth = tweepy.OAuthHandler(consumer_key, consumer_secret) | |
auth.set_access_token(access_token, access_token_secret) | |
api = tweepy.API(auth) | |
api.update_status(tweet) | |
return False | |
if __name__ == "__main__": | |
postTweet(findTweet()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment