Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create csv/json/others file that record the articles #12

Open
EmilyVam opened this issue Oct 20, 2015 · 10 comments
Open

Create csv/json/others file that record the articles #12

EmilyVam opened this issue Oct 20, 2015 · 10 comments
Assignees

Comments

@EmilyVam
Copy link
Collaborator

Create a downloadable file (csv/json/other formats) at the bottom of the searching result page that store articles' info with given searching query.
More discussion at #11

@EmilyVam
Copy link
Collaborator Author

I made some changes to the code (mainly brainspell.php) -> print out all the article titles at the beginning of the search result page (it is very messy, sorry!) with any query. Then I was trying to save the article titles into a CSV file, but it gives me a warning message (below), I pushed all the changes to Emily branch for reference.

Warning: fopen(list_of_articles.csv): failed to open stream: Permission denied in /home/oski/brainspell/site/php/brainspell.php on line 607

Warning: fwrite() expects parameter 1 to be resource, boolean given in /home/oski/brainspell/site/php/brainspell.php on line 608

Warning: fclose() expects parameter 1 to be resource, boolean given in /home/oski/brainspell/site/php/brainspell.php on line 609

Why would the it got denied? How am I suppose to fix it? @davclark @jbpoline @r03ert0

@jbpoline
Copy link
Collaborator

Have you check the permissions ? if you are writting as root, do you have
permission to write where you are trying to save the csv ?

May be Roberto will be able to help tomorrow ?

cheers
JB

On Tue, Oct 27, 2015 at 7:49 PM, Emily Zhang [email protected]
wrote:

I made some changes to the code (mainly brainspell.php) -> print out all
the article titles at the beginning of the search result page (it is very
messy, sorry!) with any query. Then I was trying to save the article titles
into a CSV file, but it gives me a warning message (below), I pushed all
the changes to Emily branch for reference.

Warning: fopen(list_of_articles.csv): failed to open stream: Permission denied in /home/oski/brainspell/site/php/brainspell.php on line 607

Warning: fwrite() expects parameter 1 to be resource, boolean given in /home/oski/brainspell/site/php/brainspell.php on line 608

Warning: fclose() expects parameter 1 to be resource, boolean given in /home/oski/brainspell/site/php/brainspell.php on line 609

Why would the it got denied? How am I suppose to fix it? @davclark
https://github.com/davclark @jbpoline https://github.com/jbpoline
@r03ert0 https://github.com/r03ert0


Reply to this email directly or view it on GitHub
#12 (comment)
.

@EmilyVam
Copy link
Collaborator Author

I modified the brainspell.php file in the php folder, and I saved the csv
file in the same folder. Maybe we can talk about it tomorrow.

Thanks,
Emily

On Tue, Oct 27, 2015 at 7:57 PM, Jean-Baptiste Poline <
[email protected]> wrote:

Have you check the permissions ? if you are writting as root, do you have
permission to write where you are trying to save the csv ?

May be Roberto will be able to help tomorrow ?

cheers
JB

On Tue, Oct 27, 2015 at 7:49 PM, Emily Zhang [email protected]
wrote:

I made some changes to the code (mainly brainspell.php) -> print out all
the article titles at the beginning of the search result page (it is very
messy, sorry!) with any query. Then I was trying to save the article
titles
into a CSV file, but it gives me a warning message (below), I pushed all
the changes to Emily branch for reference.

Warning: fopen(list_of_articles.csv): failed to open stream: Permission
denied in /home/oski/brainspell/site/php/brainspell.php on line 607

Warning: fwrite() expects parameter 1 to be resource, boolean given in
/home/oski/brainspell/site/php/brainspell.php on line 608

Warning: fclose() expects parameter 1 to be resource, boolean given in
/home/oski/brainspell/site/php/brainspell.php on line 609

Why would the it got denied? How am I suppose to fix it? @davclark
https://github.com/davclark @jbpoline https://github.com/jbpoline
@r03ert0 https://github.com/r03ert0


Reply to this email directly or view it on GitHub
<
#12 (comment)

.


Reply to this email directly or view it on GitHub
#12 (comment)
.

Emily Zhang
B.A. of Statistics and Economics
University of California, Berkeley

@r03ert0
Copy link
Collaborator

r03ert0 commented Oct 28, 2015

Ideally, you should do that in the client, not in the server. When you
launch a search there's already an array that is sent with all the titles.
The code is in brainspell-search.js.
You should just add a button to the title of the query result (when
brainspell tells how many papers responded to the query), and add a
function to that button to download the csv file when clicked. Brainspell
uses jQuery, and is very easy to append click functions to anything. If you
have a button defined like
Download CSV
you append a function in the code like
$("#download_csv").click(function() {
/* my download csv function here */
});

For the download function, have a look at this function I use to save SVG
paths in another app:

function savePaths() {
var filename=prompt("File name",filename);
var tmpRegions=JSON.parse(JSON.stringify(Regions));
for(var i=0;i<Regions.length;i++)
tmpRegions[i].path=Regions[i].path.exportJSON();
var json = JSON.stringify(tmpRegions);
var jsonData = 'data:text/json;charset=utf-8,'+encodeURIComponent(json);
var a = document.createElement('a');
a.href = jsonData;
a.download = filename+'.json';
document.body.appendChild(a);
a.click();
}

cheers,
roberto

On Wed, Oct 28, 2015 at 3:50 AM, Emily Zhang [email protected]
wrote:

I made some changes to the code (mainly brainspell.php) -> print out all
the article titles at the beginning of the search result page (it is very
messy, sorry!) with any query. Then I was trying to save the article titles
into a CSV file, but it gives me a warning message (below), I pushed all
the changes to Emily branch for reference.

Warning: fopen(list_of_articles.csv): failed to open stream: Permission denied in /home/oski/brainspell/site/php/brainspell.php on line 607

Warning: fwrite() expects parameter 1 to be resource, boolean given in /home/oski/brainspell/site/php/brainspell.php on line 608

Warning: fclose() expects parameter 1 to be resource, boolean given in /home/oski/brainspell/site/php/brainspell.php on line 609

Why would the it got denied? How am I suppose to fix it? @davclark
https://github.com/davclark @jbpoline https://github.com/jbpoline
@r03ert0 https://github.com/r03ert0


Reply to this email directly or view it on GitHub
#12 (comment)
.

@EmilyVam
Copy link
Collaborator Author

Meeting Updates & Next Steps:

  • Clarified the code regarding to the <!-- Bla Bla Bla --> symbol, more detail explanations in the Documentation.md file.
    • Next step is to modify all the code to follow this convention.
  • Continue to implement the article title snapshot with the button feature indicated in this issue.
    @anokhikastia @SydneyHuang

@davclark
Copy link
Member

davclark commented Nov 6, 2015

@EmilyVam has implemented some sample downloader button (where?) and @anokhikastia has wired something up to the actual app (again, where?)!

@EmilyVam
Copy link
Collaborator Author

EmilyVam commented Nov 6, 2015

I have pushed all my changes on Emily branch. But here is the code I added in the base.html:

$('#give-me-something').click(function () {
    var filename="Test";
    var csvfile=["Articles", "\narticle1", "\narticle2", "\narticle3"]
    var csvData = 'data:text/json;charset=utf-8,'+ encodeURIComponent(csvfile);
    var a = document.createElement('a');
    a.href = csvData;
    a.download = filename+'.csv';
    document.body.appendChild(a);
    a.click();
});

@anokhikastia You can just copy this for the button you created on the brainspell.dev.

@EmilyVam
Copy link
Collaborator Author

Help! @davclark @jbpoline @r03ert0

Can anyone enlighten me how to pass a php variable to js file? It is kind of frustrated after I tried multiple ways (I learned from Google), but none of them worked.

Two of the methods I tried are:

var data = <?php echo $articles; ?>;
var data = <?php echo json_encode($articles); ?>; 

When I printed out the $articles variable in PHP, it listed all the article names I need, but when I print out the data variable in JS using document.print(data), it doesn't print out anything.

@r03ert0
Copy link
Collaborator

r03ert0 commented Nov 12, 2015

Hi Emily,

brainspell.php passes data to the javascript code through the html page it
generates. More in detail: when a user searches a query term, lets say
'vision', this gets transformed into a query for the following web page:

http://brainspell.org/search?query=vision

this web page does not exist before hand -- it is generated by the server
(the php code).
To generate the search result page, brainspell.php uses Lucene to query the
DB that indexes all the papers. The result of this query is an array,
similar to $articles in your example. However, instead of adding all the
article data to the web page, brainspell.php generates a formated html list
of papers, which is the list of papers you can see when you do a search
(the 132 papers that correspond to 'vision'). This is the way in which
brainspell.php is already passing the list of articles to the client. I
don't think it's necessary to do it again.

what you can do now in the client is to recover the article data from the
html page using jquery. All the papers in the list have the class
"paper-stuff'. Inside the 'paper-stuff' div, the href attribute of the link
elements contains the PMID of the papers, that we want to save to the CSV
file. The text of the link contains the paper title, authors, journal, etc,
that we may also want to save to the CSV file. You can get a javascript
array with all the papers by typing:

$(".paper-stuff")

(this works even from the web browser console! give it a try!)

The jquery function each() may come handy for iterate through the results,
you can use find() to find the elements that you need, attr() to get the
value of specific attributes (such as href), and text() to get the text
content of an element.

Hope this helps,

roberto

On Thu, Nov 12, 2015 at 2:38 AM, Emily Zhang [email protected]
wrote:

Help! @davclark https://github.com/davclark @jbpoline
https://github.com/jbpoline @r03ert0 https://github.com/r03ert0

Can anyone enlighten me how to pass a php variable to js file? It is kind
of frustrated after I tried multiple ways (I learned from Google), but none
of them worked.

Two of the methods I tried are:

var data = ;
var data = ;

When I printed out the $articles variable in PHP, it listed all the
article names I need, but when I print out the data variable in JS using
document.print(data), it doesn't print out anything.


Reply to this email directly or view it on GitHub
#12 (comment)
.

@EmilyVam
Copy link
Collaborator Author

Updates:

Last week:

  • @SydneyHuang and I got the download button works last week.

This week:

  • Improved CSV file -- now the CSV file contains both the article titles and corresponding references.
  • Button works for home page as well -- clicking on it could download both the article titles with given word/query as well as the article titles (default articles) display on the home page.
  • Implemented the upload button (a baby step) -- clicking on the upload button can browse the files to upload, I stored all the content in the CSV file into a list.

Next step:

  • Need instruction on how to put all the article titles upload from an existing CSV file into the script so the webpage could reproduce the graphs, etc..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants