1
+ from Site import Site
2
+ from Paste import Paste
3
+ from bs4 import BeautifulSoup
4
+ import helper
5
+ from time import sleep
6
+ from settings import SLEEP_SLEXY
7
+
8
+ class PastiePaste (Paste ):
9
+ def __init__ (self , id ):
10
+ self .id = id
11
+ self .headers = None
12
+ self .url = 'http://pastie.org/pastes' + self .id + '/text'
13
+ super (PastiePaste , self ).__init__ ()
14
+
15
+ class Pastie (Site ):
16
+ def __init__ (self , last_id = None ):
17
+ if not last_id : last_id = None
18
+ self .ref_id = last_id
19
+ self .BASE_URL = 'http://pastie.org'
20
+ super (Pastie , self ).__init__ ()
21
+ def update (self ):
22
+ '''update(self) - Fill Queue with new Slexy IDs'''
23
+ print '[*] Retrieving Slexy ID\' s'
24
+ results = [tag for tag in BeautifulSoup (helper .download (self .BASE_URL + '/pastes' )).find_all ('p' ,'link' ) if tag .a ]
25
+ new_pastes = []
26
+ if not self .ref_id : results = results [:60 ]
27
+ for entry in results :
28
+ paste = PastiePaste (entry .a ['href' ].replace (self .BASE_URL + '/pastes' , '' ))
29
+ # Check to see if we found our last checked URL
30
+ if paste .id == self .ref_id :
31
+ break
32
+ new_pastes .append (paste )
33
+ for entry in new_pastes [::- 1 ]:
34
+ print '[+] Adding URL: ' + entry .url
35
+ self .put (entry )
36
+ def monitor (self , bot , l_lock , t_lock ):
37
+ self .update ()
38
+ while (1 ):
39
+ while not self .empty ():
40
+ paste = self .get ()
41
+ self .ref_id = paste .id
42
+ with l_lock :
43
+ helper .log ('Checking ' + paste .url )
44
+ # goober pastie - Not actually showing *raw* text.. Still need to parse it out
45
+ paste .text = BeautifulSoup (helper .download (paste .url )).pre .text
46
+ with l_lock :
47
+ tweet = helper .build_tweet (paste )
48
+ if tweet :
49
+ print tweet
50
+ with t_lock :
51
+ helper .record (tweet )
52
+ #bot.PostUpdate(paste.url, tweet)
53
+ self .update ()
54
+ # If no new results... sleep for 5 sec
55
+ while self .empty ():
56
+ with l_lock :
57
+ helper .log ('No results... sleeping' )
58
+ sleep (SLEEP_PASTIE )
59
+ self .update ()
0 commit comments