-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscraper.py
executable file
·56 lines (45 loc) · 1.8 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#! /usr/bin/env python3
from optparse import OptionParser
import sys
parser = OptionParser(usage="Usage: %prog -s\'search term\' -p\'platform\'")
parser.add_option("-s", "--search", action="append", dest="search",
help="The keyword you want to search for")
parser.add_option("-p", "--platform", action="append", dest="platform",
help="The platform that will be searched. must be the name of"
" a plugin module (example: for kijiji.py write kijiji)")
parser.add_option("-l", "--location", action="append", dest="location",
help="The geographical location for the item "
"//not yet implemented//")
parser.add_option("-r", "--refresh-rate", action="store", dest="refresh",
help="Time interval between page fetches", default=60)
(option, args) = parser.parse_args()
if option.search == None:
sys.stderr.write('You need to specify at least a search term\n')
exit(code=1)
if option.platform == None:
sys.stderr.write('You need to specify at least a search term\n')
exit(code=1)
### Plugin Loading System ###
import importlib
for module in option.platform:
module = 'pl.' + module
try:
modules = {module:importlib.import_module(module.lower())}
except ImportError:
sys.stderr.write('Could not import module {0}\n'.format(module))
exit(code=1)
searchers = []
for search in option.search:
for platform in option.platform:
searchers.append(getattr(modules['pl.'+platform.lower()],
'Page' + platform.capitalize())(search))
### Main loop ###
from pl.page import Container
from time import sleep
cont = Container(option.search[0])
i = 0
while True:
for search in searchers:
i += cont.add(search.get())
print(i)
sleep(float(option.refresh))