Guest User

Untitled

a guest
Sep 8th, 2024
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. import feedparser
  2. import pprint
  3. import sys
  4. import traceback
  5. import requests
  6.  
  7. sys.path.append("/home/$USER/rssfeed/venv/lib/python3.9/site-packages/pushbullet/")
  8. from pushbullet import Pushbullet
  9.  
  10. def send_pb_msg(title, msg):
  11. ACCESS_TOKEN = ('*****HIDDEN_TOKEN_PUSHBULLET*******')
  12. try:
  13. pb = Pushbullet(ACCESS_TOKEN)
  14. pb.push_note(title, msg)
  15. except Exception as e:
  16. print(f"Error sending Pushbullet message: {e}")
  17. traceback.print_exc()
  18.  
  19. key_words = ['e', 'a']
  20.  
  21. try:
  22. f = open('output.txt', 'r', encoding='utf-8')
  23. urls = f.readlines()
  24. urls = [url.rstrip() for url in urls]
  25. f.close()
  26. except Exception as e:
  27. print(f"Error reading output.txt: {e}")
  28. traceback.print_exc()
  29.  
  30. def contains_wanted(in_str):
  31. for wrd in key_words:
  32. if wrd.lower() in in_str:
  33. return True
  34. return False
  35.  
  36. def url_is_new(urlstr):
  37. if urlstr in urls:
  38. return False
  39. else:
  40. return True
  41.  
  42. rss = 'https://www.lowendtalk.com/categories/offers.rss'
  43. headers = {
  44. 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
  45. }
  46.  
  47. try:
  48. response = requests.get(rss, headers=headers)
  49. response.raise_for_status()
  50. feed_content = response.text
  51.  
  52. feed = feedparser.parse(feed_content)
  53. if 'bozo' in feed and feed.bozo:
  54. print(f"Error parsing feed: {feed.bozo_exception}")
  55. else:
  56. print(f"Feed parsed successfully: {len(feed['entries'])} entries found.")
  57. except Exception as e:
  58. print(f"Error fetching or parsing RSS feed: {e}")
  59. traceback.print_exc()
  60.  
  61. output = open('output.txt', 'a', encoding='utf-8')
  62. for key in feed["entries"]:
  63. try:
  64. title = key['title']
  65. url = key['links'][0]['href']
  66.  
  67. if contains_wanted(title.lower()) and url_is_new(url):
  68. print(f'{title} - {url}'.encode("utf-8"))
  69.  
  70. msgtitle = title
  71. msg = '{}\n{}'.format(title, url)
  72.  
  73. send_pb_msg(msgtitle, msg)
  74. with open('output.txt', 'a') as f:
  75. f.write('{}\n'.format(url))
  76. except Exception as e:
  77. print(f"Error processing entry: {e}")
  78. traceback.print_exc()
  79.  
Advertisement
Add Comment
Please, Sign In to add comment