perrette / papers

Command-line tool to manage bibliography (pdfs + bibtex)
MIT License
146 stars 22 forks source link

Implement nauthor, ntitle and nameformat user settings #18

Closed malfatti closed 1 year ago

malfatti commented 4 years ago

Allows user to define number of authors, title words and file name fields. After this change, the user can run, for example:

$ papers add --rename --info --nameformat Author,year,-,Title --nauthor 1 --ntitle 1 esd-4-11-2013
INFO:papers:found doi:10.5194/esd-4-11-2013
INFO:papers:new entry: perrette2013scaling
INFO:papers:create directory: files/2013
INFO:papers:mv /home/perrette/playground/papers/esd-4-11-2013.pdf files/2013/PerretteEtAl2013-AScalingApproachToProjectRegionalSeaLevelRiseAndItsUncertainties.pdf
INFO:papers:renamed file(s): 1

I also made those arguments installable, so the user can run papers install --nameformat Author,year,-,Title --nauthor 1 --ntitle 1 to make them default.

This, if merged, closes #16.

perrette commented 3 years ago

Thanks for all the work. I am slowly coming back to github and papers. Let me some more time to review the project and your changes, before merging.

malfatti commented 3 years ago

Hey @perrette !

Sorry for the slow feedback, I finally got some time to work on this.

I fixed the variable case and updated a bit the autoname functions to remove some set of characters that were getting my files into trouble.

I completely agree with your first comment, but I didn't get where should I apply such changes. Could you point me to the lines where I should improve string formatting?

By the way, in my local version I implemented a (still simple) tagging mechanism, so that you can:

$ papers add --info --rename --tags Auditory,Humans,Tinnitus,Etiology ~/Downloads/10.3109@14992027.2014.893377.pdf

$ cat PapersBib.bib  # note the 'tags' line
[...]
@article{zagolski2014tinnitus,
 author = {Olaf Zag{\'{o}}lski and Pawe{\l} Strek},
 doi = {10.3109/14992027.2014.893377},
 file = {:/Documents/Papers/ZagOLskiAndStrKEK2014-TinnitusPitchAndMinimumMaskingLevelsInDifferentEtiologies.pdf:pdf},
 journal = {International Journal of Audiology},
 month = {mar},
 number = {7},
 pages = {482--489},
 publisher = {Informa {UK} Limited},
 tags = {Auditory,Humans,Tinnitus,Etiology},
 title = {Tinnitus pitch and minimum masking levels in different etiologies},
 url = {https://doi.org/10.3109%2F14992027.2014.893377},
 volume = {53},
 year = {2014}
}
[...]

for example. Would you be interested in this feature? If so, I'll open a separate pull request.

Cheers!

VolkovIlia commented 2 years ago

Will it be merged? Tags are awesome!

perrette commented 2 years ago

Yes this is definitely a useful feature and we can thank T. Malfatti for making a suggestion. As I looked into it I was unsure about the interface (keywords naming, options) and didn't want to put something in that I'd modify later. Good you remind me though, I'll dive into it again asap, it has only waited for too long already. Il 13 nov 2021, 17:52 +0100, Ilia Volkov @.***>, ha scritto:

Will it be merged? Tags are awesome! —You are receiving this because you were mentioned.Reply to this email directly, view it on GitHub, or unsubscribe.

VolkovIlia commented 2 years ago

Any updates?))

Sorry for annoying asking comments, I am trying to integrate "papers" to my PhD workflow and this feature is very useful for sorting huge amount of articles. As a reason of my PhD is around chemistry and I am terrible coder. I'd love to help to contribute this feature by myself but can't (((

VolkovIlia commented 2 years ago

Any news?))0

malfatti commented 2 years ago

Hey,

Since these changes can help others, instead of keeping them only local, I merged your dev branch with mine and pushed everything to the Dev branch in my fork :)

@VolkovIlia If you want to give it a try you can:

$ git clone https://github.com/malfatti/papers/ -b Dev
$ cd papers
$ pip install --user .
perrette commented 2 years ago

Thanks @malfatti

perrette commented 2 years ago

Hi @malfatti, I was about to merge your pull request (and put aside my secondary concerns for now -- as I have no time to look into that anyway), but the CI fails on add_attachment. Looking at the logs makes me think that's because you changed the default naming convention and papers are not regrouped by year any more, is that correct?

malfatti commented 2 years ago

Hey,

That is weird, because I actually did not change the default (see papers/bib.py line 420):

    def rename_entry_files(self, e, copy=False, nameformat='year,/,ID')

I added the nameformat argument, but the default value is such that the pdf should be at 2013/perrete_2013.pdf ( perrete_2013 being whatever the ID becomes according to the config file). Therefore, dirmains[-2] should be self.year :/

Now that I think of it, this test line will fail for any config that does not use a name format that have pdfs organized in year subfolders (dirmains[-2] would then likely ever be self.year).