-
Notifications
You must be signed in to change notification settings - Fork 12
/
jobcatcher.py
executable file
·350 lines (267 loc) · 9.19 KB
/
jobcatcher.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__authors__ = [
'Yoann Sculo <[email protected]>',
'Bruno Adelé <[email protected]>',
'Yankel Scialom <[email protected]>'
]
__copyright__ = 'Copyright (C) 2013 Yoann Sculo'
__license__ = 'GPLv2'
__version__ = '1.0'
# System
import sys
# Third party
from optparse import OptionParser
# Jobcatcher
import utilities
from jc.page import Pages
from jc.config import Config
from jc.p2p import P2PDownloader
from jc.report import ReportGenerator
reload(sys)
sys.setdefaultencoding("utf-8")
def executeall(conf, selecteduser):
utilities.showMessage('Init blacklist', 'info', '###')
initblacklist(conf)
utilities.showMessage('Download feeds', 'info', '###')
downloadfeeds(conf, selecteduser)
utilities.showMessage('Download pages', 'info', '###')
downloadpages(conf)
utilities.showMessage('Insert pages to jobboard', 'info', '###')
insertpages(conf, selecteduser)
utilities.showMessage('Move datas to offers', 'info', '###')
movepages(conf, selecteduser)
utilities.showMessage('Generate reports', 'info', '###')
generatereport(conf, selecteduser)
def generatereport(conf, selecteduser):
r = ReportGenerator(conf)
r.generate(selecteduser)
def initblacklist(conf):
utilities.db_checkandcreate(conf)
utilities.blacklist_flush(conf)
utilities.blocklist_load(conf)
def downloadfeeds(conf, selecteduser):
"""Download all jobboard feeds"""
# Get all users feeds
feedsinfo = conf.getFeedsInfo(selecteduser)
for jobboardname, jobboardfeeds in feedsinfo.iteritems():
for feedid, feedinfo in jobboardfeeds.iteritems():
plugin = utilities.loadJobBoard(jobboardname, conf)
plugin.downloadFeed(feedinfo)
def downloadpages(conf):
pages = Pages(conf)
pages.downloadPagesFromJobboards()
# """Download all jobboard pages"""
# jobboardlist = conf.getJobboardList()
# for jobboardname in jobboardlist:
# downloadpage(conf, jobboardname)
def redownload(conf):
pages = Pages(conf)
pages.redownloadFromOffers()
def insertpage(conf, jobboardname):
# Search page for jobboard
pages = Pages(conf)
pages.searchPagesForJobboard(jobboardname)
plugin = utilities.loadJobBoard(jobboardname, conf)
for page in pages.pages:
# Load page content if needed
if not page.downloaded:
page.load()
# Analyse page
if page.downloaded:
error = plugin.analyzePage(page)
if error:
mess = "Analyse error page %s(%s)" % (page.url, error)
utilities.showMessage(mess, "warn", "JobCatcher")
else:
mess = "%s analyzed" % page.url
if conf.globals['debug']:
utilities.showMessage(mess, "info", "JobCatcher")
def insertpages(conf, selecteduser):
"""Insert all pages from all jobboard"""
utilities.db_checkandcreate(conf)
jobboardlist = conf.getJobboardList()
for jobboardname in jobboardlist:
insertpage(conf, jobboardname)
def movepage(conf, jobboardname):
"""Move jobboard pages to offers"""
utilities.db_checkandcreate(conf)
plugin = utilities.loadJobBoard(jobboardname, conf)
plugin.moveToOffers()
def movepages(conf, selecteduser):
"""Move all pages from all jobboard"""
jobboardlist = conf.getJobboardList()
for jobboardname in jobboardlist:
movepage(conf, jobboardname)
def clean(conf, jobboardname):
utilities.db_checkandcreate(conf)
utilities.db_delete_jobboard_datas(conf, jobboardname)
# def importjobboard(conf, jobboardname):
# utilities.db_checkandcreate(conf)
# pagesinsert(conf)
# pagesmove(conf)
# def imports(conf):
# jobboardlist = getjobboardlist(conf)
# for jobboardname in jobboardlist:
# importjobboard(conf, jobboardname)
# def reimports(conf, jobboardname):
# clean(conf, jobboardname)
# imports(conf)
if __name__ == '__main__':
# Load configs
from config import configs as globalconfig
configs = Config()
configs.addGlobalconfig(globalconfig)
configs.loadUsersConfig()
parser = OptionParser(usage='syntax: %prog [options] <from> [to]')
args = sys.argv[1:]
selecteduser = None
parser.set_defaults(version=False)
parser.add_option('--user',
action='store',
metavar='USERNAME',
dest='user',
help='download feed only for the USERNAME'
)
parser.add_option('--all',
action='store_true',
dest='all',
help='sync the blacklist, fetch the offers and generates reports.'
)
parser.add_option('--feeds',
action='store_true',
dest='feeds',
help='download the all feeds in the config'
)
# parser.add_option('--feed',
# action='store',
# metavar='JOBBOARD',
# dest='feed',
# help='download only the feed from JOBBOARD in the config',
# )
parser.add_option('--pages',
action='store_true',
dest='pages',
help='download the all pages in the config'
)
parser.add_option('--redownload',
action='store_true',
dest='redownload',
help='Redownload all web pages from url field offers table'
)
parser.add_option('--inserts',
action='store_true',
dest='inserts',
help='inserts all pages to offers'
)
parser.add_option('--insert',
action='store',
metavar='JOBBOARD',
dest='insert',
help='insert JOBBOARD pages to offers'
)
parser.add_option('--moves',
action='store_true',
dest='moves',
help='move datas to offer'
)
parser.add_option('--move',
action='store',
metavar='JOBBOARD',
dest='move',
help='move JOBBOARD datas to offer'
)
parser.add_option('--clean',
action='store',
metavar='JOBBOARD',
dest='clean',
help='clean offers from JOBBOARD source'
)
parser.add_option('--report',
action='store_true',
dest='report',
help='generate a full report'
)
parser.add_option('--blocklist',
action='store_true',
dest='blocklist',
help='update blocklist'
)
parser.add_option('--flush',
action='store_true',
dest='flush',
help = 'flush the blacklist and update it.'
)
parser.add_option('--p2psync',
action='store_true',
dest='p2psync',
help = 'sync by P2P'
)
parser.add_option('--version',
action='store_true',
dest='version',
help='output version information and exit'
)
# parser.add_option('-u', '--url',
# action = 'store_true', dest = 'url',
# help = 'analyse an url')
# parser.add_option('-f', '--flush',
# action = 'store_true', dest = 'flush',
# help = 'flush the blacklist and update it.')
(options, args) = parser.parse_args(args)
# Clean
if options.clean:
clean(configs, options.clean)
if options.version:
print 'jobcatcher version %s - %s (%s)' % (
__version__,
__copyright__,
__license__
)
sys.exit(0)
if options.user:
selecteduser = [options.user]
if options.all:
executeall(configs, selecteduser)
sys.exit(0)
#Feeds
if options.feeds:
downloadfeeds(configs, selecteduser)
sys.exit(0)
# if options.feed:
# downloadfeed(configs, options.feed)
# sys.exit(0)
# Pages
if options.pages:
downloadpages(configs)
sys.exit(0)
if options.redownload:
redownload(configs)
sys.exit(0)
# Inserts
if options.inserts:
insertpages(configs, selecteduser)
if options.insert:
insertpage(configs, options.insert)
# Moves
if options.moves:
movepages(configs, selecteduser)
if options.move:
movepage(configs, options.move)
if options.blocklist:
utilities.blocklist_load(configs)
sys.exit(0)
if options.flush:
initblacklist(configs)
sys.exit(0)
if options.p2psync:
# Donwload feeds
downloadfeeds(configs, selecteduser)
# Sync p2p
p = P2PDownloader(configs)
p.initLocalCache()
p.sync()
if options.report:
print "Report generation..."
generatereport(configs, selecteduser)
print "Done."