Advertisement
Guest User

Untitled

a guest
Oct 16th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.37 KB | None | 0 0
  1. from requests import get
  2. from bs4 import BeautifulSoup
  3. import feedparser
  4. import praw
  5.  
  6. client_id = 'XXXX'
  7. client_secret = 'XXXX'
  8. reddit_user = 'XXXX'
  9. reddit_pass = 'XXXX'
  10. user_agent = 'Fribble on the shizzle thing (by /u/impshum)'
  11. target_subreddit = 'XXXX'
  12.  
  13. reddit = praw.Reddit(client_id=client_id,
  14.                      client_secret=client_secret,
  15.                      user_agent=user_agent,
  16.                      username=reddit_user,
  17.                      password=reddit_pass)
  18.  
  19.  
  20. def post_to_sub(title, texts):
  21.     reddit.subreddit(target_subreddit).submit(title, selftext=texts)
  22.  
  23.  
  24. def get_texts(link):
  25.     soup = BeautifulSoup(get(link).content, 'lxml')
  26.     title = soup.find('h3', {'class': 'title'}).text
  27.     content = soup.find('div', {'id': 'content-body-'})
  28.     paras = content.findAll('p')
  29.     p = []
  30.     for x in paras:
  31.         p.append(x.text)
  32.     texts = '\n'.join(p)
  33.     post_to_sub(title, texts)
  34.  
  35.  
  36. def db(title):
  37.     with open('db.txt', 'r') as f:
  38.         data = f.read()
  39.  
  40.     if title not in data:
  41.         with open('db.txt', 'a') as f:
  42.             lines = f.write(title + '\n')
  43.         return False
  44.     else:
  45.         return True
  46.  
  47.  
  48. posts = feedparser.parse('http://www.rssmix.com/u/8300496/rss.xml').entries
  49.  
  50. for post in posts:
  51.     title = post.title
  52.     link = post.link
  53.     print(title)
  54.     if not db(title):
  55.         get_texts(link)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement