-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmozalien.py
executable file
·42 lines (32 loc) · 1.01 KB
/
mozalien.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python
# -*- coding: utf-8-*-
import praw
import json
import feedparser
def configure():
with open('settings.json') as f:
json_data = f.read()
settings = json.loads(json_data)
return settings
return None
def login(reddit, settings):
reddit.login(settings['username'], settings['password'])
def submit(subreddit, feed):
submission = subreddit.submit(title=feed['title'], url=feed['url'])
print submission.short_link
def get_feeds(url):
feed = feedparser.parse(url)
return [{'url': x.link, 'title': x.title} for x in feed.entries]
def main():
settings = configure()
r = praw.Reddit(user_agent='mozalien by /u/%s' % settings['username'])
sub = r.get_subreddit(settings['subreddit'])
login(r, settings)
feeds = get_feeds(settings['feed_url'])
feeds.reverse()
for feed in feeds:
if not len([x for x in r.info(feed['url'])]):
print feed['title']
submit(sub, feed)
if __name__ == '__main__':
main()