Skip to content

Instantly share code, notes, and snippets.

@64lines
Last active July 13, 2017 22:48
Show Gist options
  • Select an option

  • Save 64lines/ec2349d5fe798f4d619925e3338b0040 to your computer and use it in GitHub Desktop.

Select an option

Save 64lines/ec2349d5fe798f4d619925e3338b0040 to your computer and use it in GitHub Desktop.
[PYTHON] - Gif Randomizer
import feedparser
import os
import random
import time
from bs4 import BeautifulSoup
def download_file(url):
os.system('curl -o index.html %s' % url)
def get_entries(url):
return feedparser.parse(url).entries
def get_content(entry):
content = entry["content"][0]["value"]
soup = BeautifulSoup(content, 'html.parser')
links = soup.findAll('a')
return ",".join([link["href"] for link in links if ".gifv" in link["href"]] if links else [])
def get_content_list(url):
return ",".join([get_content(entry) for entry in get_entries(url) if get_content(entry)])
while True:
download_file(random.choice(get_content_list("https://www.reddit.com/r/woahdude/.rss").split(",")))
time.sleep(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment