Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from requests import get
- from bs4 import BeautifulSoup
- import feedparser
- import praw
- client_id = 'XXXX'
- client_secret = 'XXXX'
- reddit_user = 'XXXX'
- reddit_pass = 'XXXX'
- user_agent = 'Fribble on the shizzle thing (by /u/impshum)'
- target_subreddit = 'XXXX'
- reddit = praw.Reddit(client_id=client_id,
- client_secret=client_secret,
- user_agent=user_agent,
- username=reddit_user,
- password=reddit_pass)
- def post_to_sub(title, texts):
- reddit.subreddit(target_subreddit).submit(title, selftext=texts)
- def get_texts(link):
- soup = BeautifulSoup(get(link).content, 'lxml')
- title = soup.find('h3', {'class': 'title'}).text
- content = soup.find('div', {'id': 'content-body-'})
- paras = content.findAll('p')
- p = []
- for x in paras:
- p.append(x.text)
- texts = '\n'.join(p)
- post_to_sub(title, texts)
- def db(title):
- with open('db.txt', 'r') as f:
- data = f.read()
- if title not in data:
- with open('db.txt', 'a') as f:
- lines = f.write(title + '\n')
- return False
- else:
- return True
- posts = feedparser.parse('http://www.rssmix.com/u/8300496/rss.xml').entries
- for post in posts:
- title = post.title
- link = post.link
- print(title)
- if not db(title):
- get_texts(link)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement