-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdailyprogrammer.py
48 lines (27 loc) · 1.04 KB
/
dailyprogrammer.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
import re
import praw
class Scraper:
user_agent = 'daily programmer test scrapper'
thing_limit=10
already_done=[]
def __init__(self):
self.r= praw.Reddit(self.user_agent)
def get_newest(self,difficulty='Easy'):
'''
Gets newest submmisions from /r/ dailyprogrammer
:param difficulty: Easy, Intermediate, Hard
:return:
'''
submission_links=[]
subreddit = self.r.get_subreddit('dailyprogrammer')
for submission in subreddit.get_hot(limit=10):
if submission.id not in self.already_done and self._check(difficulty,submission.title):
submission_links.append(submission.permalink)
self.already_done.append(submission.id)
return submission_links
def _check(self,difficulty,title):
regex_easy = '.*?\[.*?(\[)('+difficulty+').*?..*?..*?..*?..*?(.)'
rg = re.compile(regex_easy,re.IGNORECASE | re.DOTALL)
return rg.search(title)
a= Scraper()
submission_links= a.get_newest('Easy')