-
Notifications
You must be signed in to change notification settings - Fork 6
/
scraper.py
35 lines (28 loc) · 1.38 KB
/
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
#!/usr/bin/env python
#Moses Nakamura & Nate Brennand
import urllib
#all of the js files that have the information we need
links=["http://www.columbia.edu/acis/facilities/printers/ninja/acis/js/printers.js",
"http://www.columbia.edu/acis/facilities/printers/ninja/barnard/js/printers.js",
"http://www.columbia.edu/acis/facilities/printers/ninja/cait/js/printers.js",
"http://www.columbia.edu/acis/facilities/printers/ninja/lso/js/printers.js",
"http://www.columbia.edu/acis/facilities/printers/ninja/meche/js/printers.js",
"http://www.columbia.edu/acis/facilities/printers/ninja/old_pcd/js/printers.js",
"http://www.columbia.edu/acis/facilities/printers/ninja/soa/js/printers.js",
"http://www.columbia.edu/acis/facilities/printers/ninja/ssw/js/printers.js"]
lst=[]
#scrapes the files, puts the information into lists in lists
for link in links:
filep = urllib.urlopen(link)
for line in filep:
if line.count('[') == 2:
line = line.replace('"', '') # removing double quotations from strings
line = line[line.rfind('[')+1 : line.rfind(']')-1]
lst.append(line.split(","))
#organizes the information nicely
towrite = []
for line in sorted(lst):
towrite.append("{} {} {}\n".format(line[0], line[1], line[3]))
#writes it into the correct format in newprinter.yaml file
filep = open("printers.conf","w")
filep.writelines(towrite)