pass sql result to mako template and show in table - html

I just decided to learn Pyramid and choose Mako as template language. I got a list from view which is a raw sql result, as follow:
[{'sample': 'R1_Y200.fq', 'study': 'GaoQiang1'},{'sample': 'R1_Y300.fq', 'study': 'GaoQiang2'},...]
view.py:
#view_config(route_name='example', renderer='example.html')
def templet_test(request):
...
return {'result':search_result}
html:
<html>
...
<table border="1" width="500" align="center" cellpadding="0">
<tr>
<th >study</th>
<th >sample</th>
</tr>
% for item in result:
<tr>
<td valign=top align=center> ${item['study']} </td>
<td valign=top align=center> ${item['sample']} </td>
</tr>
% endfor
</table>
...
</html>
But it didn't work out. I got this message:
"Internal Server Error
The server encountered an unexpected internal server error
(generated by waitress)"
How to fix it?

The real exception is shown in console - it will contain the cause of your problem.
You may also want to enable debug toolbar in pyramid to have a more friendly way of error handling in development.
Also by looking at your template - and i assume you use sqlalchemy for database interaction, your probably want to access result rows like item.study , not like item['study'].
That's as much as I can guess without a proper traceback.

Related

Unexpected end tag (font) HTML

I am running an R code to which several HTML files are connected. As R Returns an error message, I have opened the source file from which the message results:
In the HTML file, there is the following error message:
"End tag (font) violates step 1, paragraph 1 of the Adoption agency algorithm. Unexpected end tag (font). Ignored.
As I am completely new to HTML, I would appreciate if someone told me from which the message results. Here is the code line:
<TH ALIGN="left" COLSPAN="2">Methods in org.apache.poi.hssf.usermodel with parameters of type CellType</FONT></TH>
Thanks in advance.
You have a </FONT> tag ... but you have not a beginner tag <FONT>
<TH ALIGN="left" COLSPAN="2">
Methods in
org.apache.poi.hssf.usermodel
with parameters of type
CellType
</FONT>
</TH>
..so or you add the begin
<TH ALIGN="left" COLSPAN="2">
<FONT
Methods in
org.apache.poi.hssf.usermodel
with parameters of type
CellType
</FONT>
</TH>
or you should remove
<TH ALIGN="left" COLSPAN="2">
Methods in
org.apache.poi.hssf.usermodel
with parameters of type
CellType
</TH>

R-Advanced Web Scraping-bypassing aspNetHidden using xmlTreeParse()

This question takes a bit of time to introduce, bear with me. It will be fun to solve if you can get there. This scrape would be replicated over thousands of pages on this website using a loop.
I'm trying to scrape the website http://www.digikey.com/product-detail/en/207314-1/A25077-ND/ looking to capture the data in the table with Digi-Key Part Number, Quantity Available etc.. including the right hand side with Price Break, Unit Price, Extended Price.
Using the R function readHTMLTable() doesn't work and only returns NULL values. The reason for this (I believe) is because the website has hidden it's content using the tag "aspNetHidden" in the html code.
For this reason I also found difficulty using htmlTreeParse() and xmlTreeParse() with the whole section parented by not appearing in the results.
Using the R function scrape() from the scrapeR package
require(scrapeR)
URL<-scrape("http://www.digikey.com/product-detail/en/207314-1/A25077-ND/")
does return the full html code including the lines of interest:
<th align="right">Digi-Key Part Number</th>
<td id="reportpartnumber">
<meta itemprop="productID" content="sku:A25077-ND">A25077-ND</td>
<th>Price Break</th>
<th>Unit Price</th>
<th>Extended Price
</th>
</tr>
<tr>
<td align="center">1</td>
<td align="right">2.75000</td>
<td align="right">2.75</td>
However, I haven't been able to select the nodes out of this block of code with the error being returned:
no applicable method for 'xpathApply' applied to an object of class "list"
I've received that error using different functions such as:
xpathSApply(URL,'//*[#id="pricing"]/tbody/tr[2]')
getNodeSet(URL,"//html[#class='rd-product-details-page']")
I'm not the most familiar with xpath but have been identifying the xpath using inspect element on the webpage and copy xpath.
Any help you can give on this would be much appreciated!
You've not read the help for scrape have you? It returns a list, you need to get parts of that list (if parse=TRUE) and so on.
Also I think that web page is doing some heavy heavy browser detection. If I try and wget the page from the command line I get an error page, the scrape function gets something usable (but seems different to you) and Chrome gets the full junk with all the encoded stuff. Yuck. Here's what works for me:
> URL<-scrape("http://www.digikey.com/product-detail/en/207314-1/A25077-ND/")
> tables = xpathSApply(URL[[1]],'//table')
> tables[[2]]
<table class="product-details" border="1" cellspacing="1" cellpadding="2">
<tr class="product-details-top"/>
<tr class="product-details-bottom">
<td class="pricing-description" colspan="3" align="right">All prices are in US dollars.</td>
</tr>
<tr>
<th align="right">Digi-Key Part Number</th>
<td id="reportpartnumber"><meta itemprop="productID" content="sku:A25077-ND"/>A25077-ND</td>
<td class="catalog-pricing" rowspan="6" align="center" valign="top">
<table id="pricing" frame="void" rules="all" border="1" cellspacing="0" cellpadding="1">
<tr>
<th>Price Break</th>
<th>Unit Price</th>
<th>Extended Price
</th>
</tr>
<tr>
<td align="center">1</td>
<td align="right">2.75000</td>
<td align="right">2.75</td>
Adjust to your use-case, here I'm getting all the tables and showing the second one, which has the info you want, some of it in the pricing table which you can get directly with:
pricing = xpathSApply(URL[[1]],'//table[#id="pricing"]')[[1]]
> pricing
<table id="pricing" frame="void" rules="all" border="1" cellspacing="0" cellpadding="1">
<tr>
<th>Price Break</th>
<th>Unit Price</th>
<th>Extended Price
</th>
</tr>
<tr>
<td align="center">1</td>
<td align="right">2.75000</td>
<td align="right">2.75</td>
</tr>
and so on.

Can't connect to remote server from FireFox but works in IE & Chrome

I have some html to connect to server's(Remote server path's) like this
<TABLE BORDER="5" WIDTH="90%" CELLPADDING="4" CELLSPACING="3">
<TR>
<TH COLSPAN="2"><BR><H4><Font color=GREEN><b>CIT</b></FONT></H4></TH>
</TR>
<TR>
<TH COLSPAN="2">123</TH>
<TH></TH>
</TR>
<TR ALIGN="CENTER">
<TD COLSPAN="2"><a href=http://123.abc.com/apps>Eformer</a></TD>
</TR>
<TR ALIGN="CENTER">
<TD><a href=http://123.abc.com/apps/way>Gateway - PULSE</a></TD>
<TD><a href=http://123.abc.com/apps/gate>Gateway - HONDA</a></TD>
</TR>
<TR ALIGN="CENTER">
<TD><a href=http://123.abc.com/apps/mm>Fax - PULSE</a></TD>
<TD><a href=http://123.abc.com/apps/mn>Fax - HONDA</a></TD>
</TR>
<TR ALIGN="CENTER">
<TD><a href=http://123.abc.com/apps/pulse>TYPE - PULSE</a></TD>
</TR>
<TR ALIGN="CENTER">
<TD><a href=http://123.abc.com/apps/xy>POST - PULSE</a></TD>
<TD><a href=http://123.abc.com/apps/yz>POST - HONDA</a></TD>
</TR>
<TR ALIGN="CENTER">
<TD><a href=http://123.abc.com/apps/ss>Agent - PULSE</a></TD>
</TR>
</TABLE>
This works in IE & Chrome but doesn't work in Firefox. Can someone extend their kind help to work out?
Finally,i've found it. There is variation in format to work in firefox.We need to include 5 forward slashes to work in firefox.Here is the example
Eformer
For our example it should be formatted as -
<TD>POST - PULSE</TD>
<TD>POST - HONDA</TD>
where 123 is server name and no need to specify domain(abc.com) in our above example.
This works in all IE,Chrome & Firefox browswers.
Links in href must be enclosed in "" as
Read more about using links here. Also link url must not be broken on server end.
All mentioned browsers are capable of handling invalid HTML and opening your links in an appropriate manner. link is one of the oldest HTML tags and core functionality of HTML and works even if you are using very old versions of browsers.
As a good analyist, there must be something different going wrong; I can imagine 3 cases:
You are using a missconfigured proxy (from school or business) which has a problem with your paths.
Your browser(s) openes the url correct, but your server redirects to a different (wrong/unexpected) path due to missconfiguration
You have installed a firewall / antivirus / proxy / plugin which changes the URI in the HTTP request to something unexpected
Good luck on your mission Mr. Hunt. This message will self destruct in 5, ..4, ...3, ...

Advice on how to approach a live feed, containg data from a mysql databse

Hi all as you can probably tell by my two questions yesterday I'm new to wed development. I really need some help on how to approach the next part of my page. So and advice would be great. I'm not really looking for complete/complex code that I can't understand.. I really just want a point in the right direction so I can then work it out / learn myself. CHEERS :D
Okay so basically I have set up a database user accounts and I want to have a rolling feed of new members... . I want to get the feed to go in the main square, how do I code the feed... For the website so far I have used html and php for coding languages. The server is a mysql server. And tips / pointers would be really helpfull :)
my current code:
<?php
//Account validation
session_start();
if(!(isset($_SESSION['login']))){
header("location:welcome.php");
}
?>
<html>
<body>
<table width ="100%" border="1">
<tr>
<td width="25%">
<h1>TOOB</h1>
</td>
<td>
<!all links and stuff>
</td>
</tr>
<tr>
<td>
<h2>Start exploring the TOOB</h2>
</td>
<td width="75%">
</td>
<td>
<form>
<input type="button" value="Logout" onclick="window.location.href='logout.php'">
</form>
</td>
</tr>
</table>
<br>
<table border="1" align="center" width = "60%" height = "500">
<tr>
<td>
<!--FEED GOES HERE-->
</td>
</tr>
</table>
</body>
</html>
You will need to connect to your mysql database and retrieve your user information. Learn more about PDO, there are plenty of tutorials out there, just google 'php pdo'. When you are done with the connection and the retrieval of your data you will have an array you can loop through and display the rows in your page. For the rolling part, you can use javascript and make an ajax get request every few minutes to refresh the information.
Also please consider using css for creating a layout for your page instead of a table.
Let me know if you need more.
If anyone ever comes across this in future months I have found the solution to what I wanted to do on: http://www.phpsimplicity.com/tips.php?id=1
it teahces you how to limit the results of a mysql function to a certain number of rows. it then moves on to how you can for example output the first ten, then the second group of ten and then the third etc..... I just now have to work out how to put that into a form/display typy thing

How do I grab info from source code from other site?

Is there a way to grab things out of the source code of another site directly into your site?
For example, let's say than in a site the following source code exists:
<table ...>
<tr>
<td class=...>...</div></td>
</tr>
<tr>
<td class=....><div align="... class=...>"Interesting string that keeps changing"</div></td>
</tr>
</table>
And we want that Interesting string that keeps changing to appear in our website as well.
you could use php
you use
$html = file_get_contents('url to website');
or use a hidden if you want a javascript function, and then just grab the innerhtml