From: Mart Lubbers Date: Wed, 8 Oct 2014 18:45:44 +0000 (+0200) Subject: update X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=566f393a32c471adc316d9d2d4eda66c2c0e48b3;p=bsc-thesis1415.git update --- diff --git a/program/everything/contextmenu_o.js b/program/everything/contextmenu_o.js deleted file mode 100644 index b7b6d1f..0000000 --- a/program/everything/contextmenu_o.js +++ /dev/null @@ -1,120 +0,0 @@ -var selection; -var mouse_x = 0; -var mouse_y = 0; -var mouse_left = false; -var mouse_right = false; -if (document.addEventListener != undefined) document.addEventListener('mousemove', mouseMove, true); -else if (document.layers) document.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP); -//document.onmousemove = mouseMove; -//document.oncontextmenu = RightMouseDown; -document.onmousedown = mouseDown; -document.onmouseup = mouseUp; - -function mouseMove(a) { -// mouse_x = document.all ? event.clientX + document.body.scrollLeft : document.layers ? a.x + window.pageXOffset : a.clientX + window.pageXOffset; -// mouse_y = document.all ? event.clientY + document.body.scrollTop : document.layers ? a.y + window.pageYOffset : a.clientY + window.pageYOffset -} - -//function RightMouseDown() { -// mouse_right = true; -// return false -//} - -function mouseUp(e) { - var curselection = window.getSelection().getRangeAt(0); - if (curselection.endOffset - curselection.startOffset > 0) - selection = curselection; - if (e.which == 3) mouse_right = false -} - -function mouseDown(e) { - if (e.which == 3) { - mouse_right = true; -// document.getElementById("contextmenu").style.left = mouse_x + "px"; -// document.getElementById("contextmenu").style.top = mouse_y + "px"; -// document.getElementById("contextmenu").style.visibility = "visible" - } -} - - -function stylizeHighlightedString(range, col) -{ - var selectionContents = range.extractContents(); - var span = document.createElement("span"); - span.appendChild(selectionContents); - span.setAttribute("class","uiWebviewHighlight"); - span.style.backgroundColor = col; - span.style.color = "white"; - range.insertNode(span); -} - -function f_wann_tijd() { - stylizeHighlightedString(selection, "red") -} - -function f_wann_dat() { - stylizeHighlightedString(selection, "darkred") -} - -function f_wat() { - stylizeHighlightedString(selection, "green") -} - -function f_waar() { - stylizeHighlightedString(selection, "blue") -} - -function f_clear() { - parnt = selection.commonAncestorContainer.parentNode; - stopp = selection.endContainer.parentNode; - starp = selection.startContainer.parentNode; - console.log(selection); - if(parnt.tagName == "SPAN"){ - superparent = parnt.parentNode; - var text = document.createTextNode(parnt.innerHTML); - superparent.insertBefore(text, parnt); - superparent.removeChild(parnt); - console.log("You selected a colored piece perfectly"); - } - else { - if(starp.tagName == "SPAN"){ - superparent = starp.parentNode; - var text = document.createTextNode(starp.innerHTML); - superparent.insertBefore(text, starp); - superparent.removeChild(starp); - console.log("You selected a overlap with span start"); - } - } -} - -function post_all(num) { - var xmlhttp = new XMLHttpRequest(); - if(num == 1){ - xmlhttp.onreadystatechange=function() - { - 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); - params += "&name="+encodeURIComponent(document.getElementById("rssname").innerHTML); - var indatarray = document.getElementsByClassName('indat') - for (var i = 0; ivrijdag 4 juli 2014 20:30 - The Crimson Projekct - Locatie: Tolhuistuin (zaal)' +p13 +aS'Muziek rond King Crimson' +p14 +aa(lp15 +S'dinsdag 10 juni 2014 20:30 - Het Ultieme Natuurkunde Feestje \xe2\x80\x93 keynote Amanda Gefter' p16 +ag11 aa(lp17 -S'vrijdag 4 juli 2014 20:30 - The Crimson Projekct - Locatie: Tolhuistuin (zaal)' +S'dinsdag 12 augustus 2014 21:00 - Kevin Drew - Locatie: Bitterzoet' p18 -aS'Muziek rond King Crimson' +aS'mede-oprichter Broken Social Scene solo' p19 aa(lp20 -S'dinsdag 10 juni 2014 20:30 - Het Ultieme Natuurkunde Feestje \xe2\x80\x93 keynote Amanda Gefter' +S'vrijdag 4 juli 2014 22:00 - Palenke Soultribe' p21 -ag16 -aa(lp22 -S'dinsdag 12 augustus 2014 21:00 - Kevin Drew - Locatie: Bitterzoet' -p23 -aS'mede-oprichter Broken Social Scene solo' +aS'Electronische muziek en Afro-Colombiaanse ritmes' +p22 +aa(lp23 +S'maandag 3 november 2014 20:15 - Eefje de Visser: Waterwereldsteden - Locatie: Het Concertgebouw' p24 +ag11 aa(lp25 -S'vrijdag 4 juli 2014 22:00 - Palenke Soultribe' +S'zaterdag 27 september 2014 20:30 - A Great Big World - Locatie: Tolhuistuin (zaal)' p26 -aS'Electronische muziek en Afro-Colombiaanse ritmes' +aS'Hitschrijvers uit New York' p27 aa(lp28 -S'maandag 3 november 2014 20:15 - Eefje de Visser: Waterwereldsteden - Locatie: Het Concertgebouw' -p29 -ag16 -aa(lp30 -S'zaterdag 27 september 2014 20:30 - A Great Big World - Locatie: Tolhuistuin (zaal)' -p31 -aS'Hitschrijvers uit New York' -p32 -aa(lp33 S'zaterdag 7 juni 2014 23:00 - Benefietavond Marokkaanse Boot' -p34 +p29 aS'Van Amsterdam naar Tanger' -p35 -aa(lp36 +p30 +aa(lp31 S'donderdag 13 november 2014 19:30 - Wouter Hamel' -p37 +p32 aS'Sprankelende jazzy pop' -p38 -aa(lp39 +p33 +aa(lp34 S'vrijdag 13 juni 2014 00:00 - Legends' -p40 -ag16 +p35 +ag11 aasS'headers' -p41 -(lp42 -S'Title' -p43 -aS'Summary' -p44 -asS'summarydawg' -p45 -(lp46 +p36 +(lp37 +sS'summarydawg' +p38 +(lp39 sS'titledawg' -p47 -(lp48 +p40 +(lp41 S'\x01 \x02 - \x03 - Locatie: \x04' -p49 -asS'freq' -p50 -S'1w' -p51 -sS'adress' -p52 -g4 -ss. \ No newline at end of file +p42 +aS'\x01 \x02 - \x03' +p43 +ass. \ No newline at end of file diff --git a/program/everything/crawler.py b/program/everything/crawler.py index 39f2e9b..ae12bef 100644 --- a/program/everything/crawler.py +++ b/program/everything/crawler.py @@ -148,8 +148,6 @@ class Crawler(): matchs = filter(lambda x: x is not None, matchs) # Title urls - for u in URL_REG.findall(title): - results['url'] += list(filter(None, u)) results['url'] = URL_REG.findall(title) # Title best match @@ -159,14 +157,19 @@ class Crawler(): results['title'] = list(reversed(matches))[0].groupdict() # Summary urls - for u in URL_REG.findall(summary): - results['url'] += list(filter(None, u)) + results['url'] += URL_REG.findall(summary) + # Summary best match results['summary'] = {} if matchs: matches = sorted(matchs, key=lambda x: len(x.groups())) results['summary'] = list(reversed(matches))[0].groupdict() outputdct = dict(results['summary'].items() + results['title'].items()) + outputdct['urls'] = [x[0] for x in results['url'] if filter(None, x)] + if not outputdct['urls']: + del(outputdct['urls']) + else: + outputdct['urls'] = ', '.join(outputdct['urls']) return {re.sub('\d', '', k): v for k, v in outputdct.iteritems()} def has_to_run(self, interval, last_run, now): diff --git a/program/everything/index.py b/program/everything/index.py index 146fa67..287730c 100644 --- a/program/everything/index.py +++ b/program/everything/index.py @@ -45,7 +45,7 @@ def crawler_edit(req, args, apok): cr = crawler.Crawler() with open('/var/www/py/new.html.t', 'r') as f: data = f.read() - html_feed = '' + html_feed = '
' html_feed += '' for i in cr.entries[args['name']]['content']: html_feed += ('
TitleSummary
{}{}') - else: - data = cr.full_run(args['name']) - for entry, dc in data: - req.write(u'
entry: {title}, {summary}
'. - format(**entry).encode('utf-8')) - for k, v in dc.iteritems(): - req.write(u'{}: {}
'.format(k, v).encode('utf-8')) - req.write('

Go back') + try: + cr = crawler.Crawler(init=True) + if 'name' not in args or str(args['name']) not in cr.entries: + req.write('Name not in the crawler...
') + else: + data = cr.full_run(args['name']) + req.write('Results: {}/{} got results
\n'.format( + len(filter(None, [x[1] for x in data])), len(data))) + for entry, dc in data: + req.write(u"""

+Entry: +
+ {title} +
+
+{summary} +

+""".format(**entry).encode('ascii', 'xmlcharrefreplace')) + req.write('') + if dc: + for k, v in dc.iteritems(): + req.write( + (u'').format( + k, v).encode('ascii', 'xmlcharrefreplace')) + else: + req.write('') + req.write('
{}{}
NO RESULTS FOUND
\n') + req.write('

Go back') + except Exception, e: + req.write(repr(e)) return apok @@ -88,7 +108,7 @@ def feed2html(url, name): url = urllib.unquote(url) url = url if re.match('https?://', url) else 'http://{}'.format(url) feed = feedparser.parse(url) - result += '' + result += '
' result += '' for i in feed.entries[:10]: result += ('' diff --git a/program/everything/new.html.t b/program/everything/new.html.t index 7ba7602..4f95a77 100644 --- a/program/everything/new.html.t +++ b/program/everything/new.html.t @@ -1,7 +1,7 @@ HyperFrontend RSS feed input new - +
TitleSummary
{}{}{}
diff --git a/program/everything/scripts.js b/program/everything/scripts.js new file mode 100644 index 0000000..98c00df --- /dev/null +++ b/program/everything/scripts.js @@ -0,0 +1,129 @@ +var selection; +document.captureEvents(Event.MOUSEUP); +document.onmouseup = function mouseUp(e) { + var curselection = window.getSelection().getRangeAt(0); + if (curselection.endOffset - curselection.startOffset > 0) { + selection = curselection; + } +} + +function stylizeHighlightedString(range, col) +{ + par = range.commonAncestorContainer; + correct = 0 + while(1) { + if(par.tagName == 'BODY' || par.tagName == 'TH'){ + break; + } + if(par.tagName == 'TR' || par.tagName == 'TD'){ + correct = 1; + } + if(correct == 1 && par.tagName == 'TABLE' && par.id == 'content-table'){ + correct = 2; + break + } + par = par.parentNode; + } + if(correct == 2 && range_has_span(range) == null){ + var selectionContents = range.extractContents(); + var span = document.createElement("span"); + span.appendChild(selectionContents); + span.setAttribute("class","uiWebviewHighlight"); + span.style.backgroundColor = col; + span.style.color = "white"; + range.insertNode(span); + } +} + +function range_has_span(range){ + par = range.commonAncestorContainer; + while(1) { + if(par == null){ + break; + } + if(par.tagName == "SPAN"){ + return par; + } + par = par.parentNode; + } + parentchilds = range.commonAncestorContainer.childNodes; + returnarray = [] + for(var i = 0; i