Skip to content

Instantly share code, notes, and snippets.

@jul
Forked from anonymous/lemonde.py
Last active August 3, 2017 16:06
Show Gist options
  • Save jul/6652373 to your computer and use it in GitHub Desktop.
Save jul/6652373 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Small utility only useful for people able to understand the web front and back
that are bored of actually bloated web pages and only want to see what they
think is useful.
It is not intended as an adblock except if as I, you hate advertisement and
think ads are noise so I tend to not fetch them.
Not intended as an antivirus, but I also tend to not load virus because
there is nothing interesting in them.
"""
from pyquery import PyQuery as P
import requests as req
from functools import wraps
from flask import Flask
from flask.ext.cache import Cache
from random import shuffle, randint
from urlparse import urljoin
from lxml import etree
import re
import json
import sys
tostr = etree.tostring
flask_setting = {}
app = Flask(__name__)
cache = Cache(config={'CACHE_TYPE': 'simple'})
header = u"""
<!doctype html>
<html lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8">
<link href="data:image/x-icon;base64,AAABAAEAEBAAAAAAAABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAA////AAAAAJ4YGAClFxcApRcXAKUWFgCkFRUApBQUAKQTEwCjEhIAoxESAKMREgCjAAAAnv///wAAAAAAAAAAAAAAAJ6zHQn/sx0J/7MdCf+zHQn/sx0J/7MdCf+zHQn/sx0J/7MdCf+zHQn/sx0J/7MdCf8BAQCfAAAAAAAAAAAREQCjsx0Ju7MdCbuzHQn/sx0J/7MdCf+zHQn/sx0J/7MdCf+zHQn/sx0J/7MdCf+zHQm7CwsAoQAAAAAAAAAAAAAARLMdCbuzHQm7sx0J/7MdCf+zHQn/sx0J/7MdCf+zHQn/sx0J/7MdCf+zHQm7sx0J/wAAAD4AAAAAAAAAAP///wAkJACosx0JlbMdCbuzHQn/sx0J/7MdCf+zHQn/sx0J/7MdCf+zHQn/sx0J/wAAAJ7///8AAAAAAAAAAAD///8AnZ2dCbMdCZWzHQm7sx0Ju7MdCf+zHQn/sx0J/7MdCf+zHQn/sx0JuzAvAqz///8A////AAAAAAAAAAAA////AP///wAAAABWsx0JlbMdCbuzHQm7sx0J/7MdCf+zHQn/sx0Ju7MdCf8AAAA/////AP///wAAAAAAAAAAAP///wD///8A////ACAgAKf8/6Bv/P+TXvz/AC/8/wAs/P8AKvz/llACAgCf////AP///wD///8AAAAAAAAAAAD///8A////AP///wCoqKgJaWsAiP3/oWj8/wAw/P8ALfz/i008PQCn/v7+AP///wD///8A////AAAAAAAAAAAA////AP///wD///8A////AAAAAFbW2ABB+/9rTfz/AC6PkQBRAAAAQP///wD///8A////AP///wAAAAAAAAAAAP///wD///8A////AP///wDt7e0EgYMAZ/v/ak9OTwCWP0AAr////wD///8A////AP///wD///8AAAAAAAAAAAD///8A////AP///wD///8AjY2NBoKEAGf9/2BP/P8AL2xtAGn///8A////AP///wD///8A////AAAAAAAAAAAA////AP///wD///8A////AI2NjQqEhQBn/P9JTfz/ADBpaQBz////AP///wD///8A////AP///wAAAAAAAAAAAP///wD///8A////AP///wCNjY0LhogAZ/z/REv8/wAxYGEAfv///wD///8A////AP///wD///8AAAAAAAAAAAD///8A////AP///wD///8AAAAAPMHEAE37/wA1/P8AMXd4AGLj4+MB////AP///wD///8A////AAAAAAAAAAAA////AP///wD///8A////AB8fAKcdHgCmHBwAphsbAKYaGgClBAUAoP///wD///8A////AP///wAAAAAAwAMAAIABAACAAQAAwAMAAMADAADgBwAA8A8AAPfvAAD73wAA//8AAP8/AAD//wAA//8AAP//AAD//wAA+B8AAA==" rel="icon" type="image/x-icon" />
<style>
@import url(http://fonts.googleapis.com/css?family=Crimson+Text);
body {
font-family:'Crimson Text', 'Georgia', serif !important;
font-size: 20px;
color: #000; }
a {
margin-left:.3em; color:#003;
text-decoration:none;
border-bottom: 1px dashed black;
border-radius:0
}
a:visited { color:#123;}
tr:hover, li:hover, .entete:hover {
z-index:4; max-width:100%;transition: all .3s ease-in;
border-radius:.6em;
text-shadow: rgba(0,0,0,.6) .1em .1em 2px;
}
h3 { font-size:100%; font-weight:normal }
.numero { visibility:hidden }
li { list-style: none;padding-top:.1em; padding-bottom:.1em; }
tr:nth-child(odd) > td, li:nth-child(odd) {
background: #DDD; border-radius:.6em;
}
li:nth-child(even), tr:nth-child(even)> td {
background: white; border-radius:.6em;
}
.entete:first-child {
margin-top:1.59em;
}
.entete {
text-shadow: rgba(0,0,0,.6) .08em .08em 1px;
margin-left:.5em; display:block; margin-top:.1em;
margin-bottom:3px; border-radius: 15px;background:#46A;color:white;
padding:.1em;font-size: 1.3em;text-align:center ; border-bottom:0px; border-bottom:0px;
}
.footer { z-index:4;margin: auto;margin-left:-.5em;
background:#46A;color:white;padding:.2em;font-size: .8em;
text-align:center; position:fixed; top:0px;width:100%; }
</style>
<title>127.0.0.1 suss Heim</title>
<script src='http://code.jquery.com/jquery-latest.min.js' type='text/javascript' ></script>
<script>
$( document ).ready( function() {
$(".entete").next().hide();
$($(".entete")[0]).css("background-color","#aad")
$($(".entete")[1]).css("background-color","#bad")
$($(".entete")[2]).css("background-color","#cad")
$($(".entete")[3]).css("background-color","#dad")
$($(".entete")[4]).css("background-color","#ead")
$(function() {
$(".entete").click( function() {
$(this).next().toggle();
} ) }
);
$('[name=webcam]').next().show()
} )
</script>
</head>
<body>
<div class=footer>What The Fuck Public Licence v3.14159 Julien Tayon //<a
href=http://gist.github.com/jul/6652373>source</a> //<a
name=top onclick='$(window).scrollTop(0)'>haut
</a>
</div>
<div style="width:90%;margin-top:-.4em;margin-left:auto; margin-right:auto">
"""
footer = u"""</div></body></html>"""
magnet_img = u"""<img alt="" src="data:image/gif;base64,R0lGODlhDAAMALMPAOXl5ewvErW1tebm5oocDkVFRePj47a2ts0WAOTk5MwVAIkcDesuEs0VAEZGRv///yH5BAEAAA8ALAAAAAAMAAwAAARB8MnnqpuzroZYzQvSNMroUeFIjornbK1mVkRzUgQSyPfbFi/dBRdzCAyJoTFhcBQOiYHyAABUDsiCxAFNWj6UbwQAOw==" /> """
def fullpage(*msg):
return "\n".join([ header ] + list(msg) + [ footer ])
@wraps
def get_or_fail(funct):
def wraped(*a, **kw):
try:
return funct(*a,**kw)
except Exception as e:
return str(e)
return wraped
#@cache.cached(timeout=1000, key_prefix='lemonde')
@get_or_fail
def lemonde_fragment():
toprint = P(
'http://www.lemonde.fr')('.plus_partages'
).make_links_absolute(
).attr('target', '_blank').html()
toprint = P(toprint).remove(".sociaux_suivre").html()
return toprint
@get_or_fail
def anime():
title = u"""<a class="entete" name=anime>animation</a>"""
that = 'navyvaxm.gi'.decode("rot13")
site=('http://%s/' % that)
base_url = urljoin(site, '/fetch.php')
html = req.post(base_url, headers = {
'Cache-Control' : 'no-cache',
'Pragma': 'no-cache',
'Host': that,
'Accept': '*/*',
'Accept-Encoding': 'gzip, deflate',
'Connection': 'keep-alive',
'User-Agent' : 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:26.0) Gecko/20100101 Firefox/26.0',
'X-Requested-With' : 'XMLHttpRequest','Referer' : 'http://%s/?p=1' % that,
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
data=dict(action='ongoing',page=1,type=0)
)
doc = P(html.content)
for a in doc.find("a"):
a=P(a)
rel = a.attr("href")
a.attr("href", urljoin(site,rel)).attr('target', '_blank')
return title + "<div><ul>" + doc.html() + "</ul></div>"
@get_or_fail
def toride(plus="tv"):
title = u"""<a class="entete" name=anime>A la tele ce soir (%s)</a>""" % plus
base_url = urljoin('uggcf://xng.pe/'.decode('rot13'), plus)
script= """<script>
$("[href^=magnet]").html('%s');
$('.torrentname > a, .font11px').hide();
</script>""" % magnet_img
return title + "<div><ul>" + tostr(P(base_url, verify=False
).make_links_absolute(
).attr('target', '_blank'
)("table.data")[0]
) + "</ul></div>" + script
@get_or_fail
def npr_fragment(channel=1):
li_list = []
base_url ="http://www.npr.org/rss/rss.php?id=%d"
title = "NPR"
doc = str(P(base_url % channel))
### WTF I cannot use lxml to parse fucking RSS O_o
print doc
title += P(doc("channel"))("title").html()
print title
for item in doc.find('item'):
el = P(item)
li_list += [ "<a href=%s >%s</a>" % (P("link").html(),
P("description").html()) ]
return title + "<div><ul><li>" + "</li><li>".join(li_list) + "</li></ul></div>"
@get_or_fail
def webcam_fragment():
MAX_PAGE=100
MAX_LINE_OFF=2
title = u"""<a class="entete" name=webcam>Random webcam</a>"""
base_url = 'uggc://jjj.bcragbcvn.pbz/uvqqrapnz.cuc?fubjzbqr=fgnaqneq&pbhagel=*&frrjung=enaqbz&c=%q'.decode("rot13") % randint(1,MAX_PAGE)
li_list = P(P(P(base_url).make_links_absolute()('.camgrid3')[randint(0,MAX_LINE_OFF)])("li"))
wrapper_o = "<div style='width:100%;text-align:center;margin:auto'>"
item_o = "<div style='height:100%;width:33%;float:left;margin:auto;display:inline'>"
cement = "</div>" + item_o
return title + wrapper_o + item_o + cement.join(
[ P(el).css("display", "inline").html() for el in li_list.css("display", "inline").items() ]
) + "</div></div></div>"
@cache.cached(timeout=50, key_prefix='cam')
@app.route("/")
def proxy():
return fullpage(lemonde_fragment(), anime(), toride("tv"), toride("movies"), webcam_fragment())
if __name__ == "__main__":
app.run(**flask_setting)
@jul
Copy link
Author

jul commented Sep 21, 2013

miss cleaning all the js shit added on on_click that makes weired behaviour

@jul
Copy link
Author

jul commented Nov 6, 2015

snapshot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment