}
}
-function post_all() {
+function post_all(num) {
var xmlhttp = new XMLHttpRequest();
- xmlhttp.onreadystatechange=function()
- {
- if (xmlhttp.readyState==4)
+ if(num == 1){
+ xmlhttp.onreadystatechange=function()
{
- document.write(xmlhttp.responseText);
+ if (xmlhttp.readyState==4)
+ {
+ document.write(xmlhttp.responseText);
+ }
+ }
+ } else {
+ xmlhttp.onreadystatechange=function()
+ {
+ if (xmlhttp.readyState==4)
+ {
+ field = document.getElementById("preview_field");
+ field.innerHTML = xmlhttp.responseText;
+ }
}
}
var params = "content="+encodeURIComponent(document.getElementById("content-table").innerHTML);
for (var i = 0; i<indatarray.length; i++) {
params += "&" + indatarray[i].name + "=" + indatarray[i].value;
}
- xmlhttp.open("POST", "hyper.py", true);
+ xmlhttp.open("POST", num == 1 ? "hyper.py" : "preview.py", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", params.length);
xmlhttp.send(params);
return self.entries.keys()
def add_entry(self, d):
- if d['name'] in self.entries:
+ if d['name'] in self.entries and False:
raise Exception('That name is already present')
else:
self.entries[d['name']] = d
f.write(pickle.dumps(entries2))
status += 'Crawler written succesfully<br />'
except Exception, e:
- # print 'something went wrong writing: {}'.format(e)
- # print 'restoring backup'
status += 'Something went wrong: {}<br />'.format(e)
os.rename('{}.bak'.format(path), path)
status += 'Writing failed, restored backup<br />'
raise Exception('interval is either 0 or unparsable')
return now - last_run >= time_wait
+ def full_run(self, name):
+ if name not in self.entries:
+ return []
+ results = []
+ entry = self.entries[name]
+ feed = feedparser.parse('http://' + entry['url'])
+ for i in feed.entries:
+ results.append(
+ (i, self.test_entry(name, i['title'], i['summary'])))
+ return results
+
def run_entry(self, name):
edict = self.entries[name]
if 'db' not in edict:
if 'name' not in args or str(args['name']) not in cr.entries:
req.write('Name not in the crawler...<br/>')
else:
- args['summary'] = args.get('summary', '')
- args['title'] = args.get('title', '')
- respons = cr.test_entry(str(args['name']), str(args['title']),
- str(args['summary']))
- req.write('<b>Title:</b> {}<br/><b>Summary: </b>{}<br/>'.format(
- str(args['title']), str(args['summary'])))
- req.write('<br/><b>Results:</b><br/>')
- req.write('<br/>'.join('{}: {}'.format(k, v)
- for k, v in sorted(respons.iteritems())))
+ data = cr.full_run(args['name'])
+ for entry, dc in data:
+ req.write(u'<br/><b>entry</b>: {title}, {summary}<br/>'.
+ format(**entry).encode('utf-8'))
+ for k, v in dc.iteritems():
+ req.write(u'<b>{}</b>: {}<br/>'.format(k, v).encode('utf-8'))
req.write('<br/><br/><a href="index.py">Go back</a>')
return apok
'cel--></tr><!--line-->').format(
i['title'].encode('ascii', 'xmlcharrefreplace'),
i['summary'].encode('ascii', 'xmlcharrefreplace'))
- return result
+ return result + '</table>'
def input_data(dictio):
'feed_html': feed2html(args['url'], args['name'])}
req.write(data.format(**params))
return apok
+
+def crawler_preview(req, args, apok):
+ req.log_error('handler')
+ req.content_type = 'text/html'
+ req.send_http_header()
req.content_type = 'text/html'
req.send_http_header()
args = util.FieldStorage(req)
- listing = data_main(args)
+ listing, crawl = data_main(args)
req.write(
'<html>\n<head>\n'
'\t<title>VER: 0.01 - HyperFrontend RSS feed POSTREQUEST</title>'
del(d['matchdata'])
crawl = crawler.Crawler()
crawl.add_entry(d)
- status = crawl.write()
- return crawl.list_names()
+ crawl.write()
+ return crawl.list_names(), crawl
def feed2html(req, url, name):
return index.crawler_new(req, util.FieldStorage(req), apache.OK)
else:
if req.method == "POST":
- req_pre_pos(req)
+ if req.uri.split('/')[-1] == 'hyper.py':
+ req_pre_pos(req)
+ elif req.uri.split('/')[-1] == 'preview.py':
+ args = util.FieldStorage(req)
+ listing, crawl = data_main(args)
+ return index.crawler_test(req, {'name': args['name']},
+ apache.OK)
else:
req.write('Unknown case')
return apache.OK
{active_crawlers_dropdown}
</select>
</td></tr>
- <tr><td>Title:</td><td><input type="text" name="title"></td></tr>
- <tr><td>Summary:</td><td><input type="text" name="summary"></td></tr>
<tr><td><input type="submit" value="Submit"></td></tr>
</table>
</form>
<button onclick="javascript:f_clear()">Clear selection</button>
<br/>Loading "{url}" as <b><p id="rssname">{rssname}</p></b><br/>
{feed_html}
- <button onclick="javascript:post_all()" method="post" target="_blank">Submit</button>
+ <button onclick="javascript:post_all(1)" method="post" target="_blank">Submit</button>
+ <button onclick="javascript:post_all(0)" method="post" target="_blank">Preview</button>
+ <br />
+ <p>Preview:<p>
+ <p id="preview_field"><p>
</body>
</html>