-
Notifications
You must be signed in to change notification settings - Fork 0
/
PastaBean.py
53 lines (40 loc) · 1.63 KB
/
PastaBean.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
43
44
45
46
47
48
49
50
#!/usr/bin/python3
import json, re, time, requests, logging, traceback, codecs
#config
pastebin = 'https://pastebin.com/raw/'
post_limit = '100'
urlposts = 'https://scrape.pastebin.com/api_scraping.php?limit='
wait = 60
#loading regex
with open('regex.json', 'r') as f:
j = json.load(f)
j_reg = j['regex_pasta']
#log settings
logging.basicConfig(filename='pasta.log',level=logging.INFO,format='%(asctime)s %(levelname)-8s %(message)s',datefmt='%Y-%m-%d %H:%M:%S%p')
restart=True
def pasta():
logging.info('Loop Started!')
p_posts = requests.get(f'{urlposts}{post_limit}')
p_json = json.loads(p_posts.content)
for x in j_reg:
xnam = (x['name'])
xreg = (x['regex'])
for k in p_json:
p_sc = (k['scrape_url'])
p_k = (k['key'])
p_get = requests.get(p_sc)
xcheck = re.match(f'{xreg}', p_get.text)
if xcheck is not None :
logging.info(f'Regex Rule:{xnam} Matched! - {pastebin}{p_k}')
with open(f'{xnam}-{p_k}.txt', 'w') as pasta:
p_out = pasta.write(f'{p_get.text}')
elif xcheck is None :
continue
logging.info('Loop Completed!')
time.sleep(wait)
while restart:
try:
pasta()
except Exception as e:
logging.error(traceback.format_exc())
restart=True