Last active
July 13, 2017 22:48
-
-
Save 64lines/ec2349d5fe798f4d619925e3338b0040 to your computer and use it in GitHub Desktop.
[PYTHON] - Gif Randomizer
This file contains hidden or 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 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