Skip to content

Instantly share code, notes, and snippets.

@jonathan-ostrander
Last active April 15, 2017 02:27
Show Gist options
  • Save jonathan-ostrander/cff4de65e02f9bca43ea to your computer and use it in GitHub Desktop.
Save jonathan-ostrander/cff4de65e02f9bca43ea to your computer and use it in GitHub Desktop.
Tweets random YouPorn Comments
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