def traeRegion(link): pagina=html() intentos=0 while True: try: pagina.html_connect(link) intentos=intentos+1 if pagina.status==200: pagina.html_read() soup = BeautifulSoup(pagina.html_showHTML()) return soup.find(id="regionNavigationBar").find_all('a') else: print colored('Error: Servidor No devuelve datos intento %i' % intentos,'red') except Exception, e: print( colored(" Error de descargando pagina intento %i" % intentos,'red')) if intentos==10: intentos=0 while True: si=raw_input('Hay Problemas conectando, intento de nuevo (S/N)') si=si.lower() if si in ["s","n"]: break if si=='n': print (colored('error cargando datos desde la pagina','red')) raise
def __exit__(self, exc_type, exc_val, exc_tb): if not self.debug: print "<META HTTP-EQUIV=refresh CONTENT=\"0;URL=%s\">\n" % (self.url) else: with html('action page') as h: with h.append(table([['input'],['name', 'value']])) as t: for i in self.inputs: try: val = self.form[i].value except KeyError: val = 'off' t.body.append([i, val]) h.append(p('URL: ' + str(self.url) )) h.append(a('return', attr={'href':self.url}))
def degenerated(self): """Sequence check. Only A, C, T, G are valid letters.""" alphabet=['a','c','t','g','A','C','T','G'] setSequence=set(list(self.sequence)) errorChar= (setSequence-set(alphabet)) if len(errorChar)!=0: foo = html() foo.cssUp() print""" <div class="articles"> At least one of your sequences (amplicon or primer ones) has nucleotides which are diferent from 'A', 'C', 'T' and 'G'. Unfortunately, this tool doesn't handle 'N' or other degenerated nucleotides. The offending characteres were %s. <br><br> Please go back to the <a href="../web.html">form</a>. </div> """ %errorChar foo.cssBottom() sys.exit()
import unittest print "hello, world" print "hello, world".wrap("span") print "hello, world".wrap("div", "greeting") def foo(): print "hello, foo" foo() foo() foo() foo() record = { "person": { "name": "Nigel", "age": 35, "lovely": True, "details": {"height": "4m", "fav_colours": ["green", "brown"]}, } } x = html(record, "record") for i in range(2): for j in range(3): document.body.appendChild(x.cloneNode(True)) document.body.appendChild(html([1, 2, 3, 4, 5]))
from html import * from bs4 import BeautifulSoup #from informacion.models import Region import os.path pagina=html() #http://www.cne.gob.ve/resultado_presidencial_2012/lvg/43/reg_220103007011.html dir_ele="http://www.cne.gob.ve/resultado_presidencial_2012/" pagina.html_connect(dir_ele+"lvg/43/reg_220103007011.html") if pagina.status==200: pagina.html_read() soup = BeautifulSoup(pagina.html_showHTML()) contadorOtros=0 if soup.find(id="tablaResultados"): for r in soup.find(id="tablaResultados").find_all(class_='tbsubtotalrow'): t=r.findAll(class_="lightRowContent") nombre=str(t[1].text.replace("Adjudicado","").strip()) votos=int(t[2].text) if nombre=='HUGO CHAVEZ': print ("Oficialismo - (%i)" % votos ) elif nombre == 'HENRIQUE CAPRILES RADONSKI': print ("Oposicion - (%i)" % votos ) else: contadorOtros=contadorOtros+votos print ('Otros - (%i)' % contadorOtros) c=0 for f in soup.find(id="fichaTecnica").find_all(class_='tblightrow'): c=c+1 l=f.findAll("td") if c==1:
def get_caption(self, doi, table, format): if format == 'html': if '10.1016' in doi: up = table.parent table_root = up.parent caption = table_root.find('div', 'caption') caption = caption.find('p') caption, ref = self._search_for_reference(caption, format) caption = unidecode.unidecode(html.unescape( caption.text)).strip() return caption, ref elif '10.1039' in doi: check = table.parent check = check.parent if check.get('class') == ['rtable__wrapper']: up = table.parent up = up.parent caption = up.previous_sibling if caption is None: return '', [] else: caption = caption.previous_sibling if caption is None: return '', [] else: caption = caption.find('span') caption, ref = self._search_for_reference( caption, format) caption = unidecode.unidecode( html.unescape(caption.text)).strip() return caption, ref else: return '', [] elif '10.1002' in doi: up = table.parent caption = up.previous_sibling caption = caption.previous_sibling if caption is not None: caption.span.decompose() caption, ref = self._search_for_reference(caption, format) caption = unidecode.unidecode(html.unescape( caption.text)).strip() return caption, ref else: print('No caption') return '', [] elif '10.1021' in doi: up = table.parent if up.get('class') == ['NLM_table-wrap']: caption = up.find('div', 'NLM_caption') else: caption = up.previous_sibling if caption == ' ': caption = caption.previous_sibling if caption is not None: caption, ref = self._search_for_reference(caption, format) caption = unidecode.unidecode(html.unescape( caption.text)).strip() return caption, ref else: return '', None elif '10.1007' in doi: up = table.parent caption = up.previous_sibling caption = caption.find('p') caption, ref = self._search_for_reference(caption, format) caption = unidecode.unidecode(html(caption.text)).strip() return caption, ref else: return '', [] elif format == 'xml': if '10.1016' in doi: try: caption = table.find('caption') caption, ref = self._search_for_reference(caption, format) caption = unidecode.unidecode(html.unescape( caption.text)).strip() except Exception as e: caption = "" ref = "" print(e) return caption, ref elif '10.1021' in doi: caption = table.find('title') if caption is None: up = table.parent caption = table.find('title') if caption is None: caption = up.find('caption') caption, ref = self._search_for_reference(caption, format) caption = unidecode.unidecode(html.unescape( caption.text)).strip() return caption, ref return '', []
#!/usr/bin/python from html import * import cgitb cgitb.enable() import os # Header import header with html("index page") as h: # Calendar cal_div = div() # Dev dev_div = div() dropFR = form( db_action='drop') # Cal Div with cal_div as cd: cd.append(MonthTable(month=12, db_tbl_col={'gym':'gym'})) def f(inp): return int(inp)+1 cd.append(ul(db_tbl='day', db_col='year', db_func=f)) h.append(header.header_div, cal_div, dev_div) for key, val in os.environ.items():
#!/usr/bin/python from html import * import cgitb import db cgitb.enable() # ___ __ _ _ _ _ # | \ ___ / _| (_) _ _ (_) | |_ (_) ___ _ _ ___ # | |) | / -_) | _| | | | ' \ | | | _| | | / _ \ | ' \ (_-< # |___/ \___| |_| |_| |_||_| |_| \__| |_| \___/ |_||_| /__/ # ---------------------------------------------------------------- page = html("All Tables") body_div = div() list_of_tables = ul() # ___ _ _ # / __| | |_ _ _ _ _ __ | |_ _ _ _ _ ___ # \__ \ | _| | '_| | || | / _| | _| | || | | '_| / -_) # |___/ \__| |_| \_,_| \__| \__| \_,_| |_| \___| # -------------------------------------------------------- # Header import header # Body with body_div as bdiv: bdiv.append(list_of_tables) # Table Of Tables