-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathsys_scraper.py
executable file
·58 lines (49 loc) · 1.94 KB
/
sys_scraper.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
51
52
53
54
55
56
57
58
#!/usr/bin/env python2
"""Module for SysScraper"""
from scrapers import *
class SysScraper:
"""SysScraper class
System-Engineering_Devops project scraper.
Args:
soup (obj): BeautifulSoup obj containing parsed link
Attributes:
ruby_check (str): if ruby exists, assign to 0. Else scrape empty list
file_names (list): scraped file names from find_files()
"""
def __init__(self, soup):
self.soup = soup
self.file_names = self.find_files()
self.ruby_check = self.ruby_checker()
def ruby_checker(self):
"""Method that checks for ruby files in project
"""
temp = self.soup.find_all(string=re.compile("env ruby"))
if temp != []:
return 0
else:
return temp
def find_files(self):
"""Method that scrapes bash or ruby for file names"""
return self.soup.find_all(string=re.compile("File: "))
def write_files(self):
"""Method that writes/creates bash or ruby files"""
sys.stdout.write(" -> Creating task files... ")
for item in self.file_names:
try:
w_file_name = open(item.next_sibling.text, "w")
if self.ruby_check == 0:
w_file_name.write("#!/usr/bin/env ruby\n")
elif ".py" in item.next_sibling.text:
w_file_name.write("#!/usr/bin/python3\n")
else:
w_file_name.write("#!/usr/bin/env bash\n")
w_file_name.close()
except (AttributeError, IndexError):
sys.stdout.write("[ERROR] Failed to create ")
try:
sys.stdout.write("task file %s\n" % item.next_sibling.text)
except AttributeError:
sys.stdout.write("any task files, tasks do not exist\n")
sys.stdout.write(" ... ")
continue
print("done")